contestId
int64
0
1.01k
index
stringclasses
57 values
name
stringlengths
2
58
type
stringclasses
2 values
rating
int64
0
3.5k
tags
listlengths
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
listlengths
0
7
demo-output
listlengths
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
721
A
One-dimensional Japanese Crossword
PROGRAMMING
800
[ "implementation" ]
null
null
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)). Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword. Help Adaltik find the numbers encrypting the row he drew.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
[ "3\nBBW\n", "5\nBWBWB\n", "4\nWWWW\n", "4\nBBBB\n", "13\nWBBBBWWBWBBBW\n" ]
[ "1\n2 ", "3\n1 1 1 ", "0\n", "1\n4 ", "3\n4 1 3 " ]
The last sample case correspond to the picture in the statement.
500
[ { "input": "3\nBBW", "output": "1\n2 " }, { "input": "5\nBWBWB", "output": "3\n1 1 1 " }, { "input": "4\nWWWW", "output": "0" }, { "input": "4\nBBBB", "output": "1\n4 " }, { "input": "13\nWBBBBWWBWBBBW", "output": "3\n4 1 3 " }, { "input": "1\nB", "output": "1\n1 " }, { "input": "2\nBB", "output": "1\n2 " }, { "input": "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB", "output": "50\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 " }, { "input": "1\nW", "output": "0" }, { "input": "2\nWW", "output": "0" }, { "input": "2\nWB", "output": "1\n1 " }, { "input": "2\nBW", "output": "1\n1 " }, { "input": "3\nBBB", "output": "1\n3 " }, { "input": "3\nBWB", "output": "2\n1 1 " }, { "input": "3\nWBB", "output": "1\n2 " }, { "input": "3\nWWB", "output": "1\n1 " }, { "input": "3\nWBW", "output": "1\n1 " }, { "input": "3\nBWW", "output": "1\n1 " }, { "input": "3\nWWW", "output": "0" }, { "input": "100\nBBBWWWWWWBBWWBBWWWBBWBBBBBBBBBBBWBBBWBBWWWBBWWBBBWBWWBBBWWBBBWBBBBBWWWBWWBBWWWWWWBWBBWWBWWWBWBWWWWWB", "output": "21\n3 2 2 2 11 3 2 2 3 1 3 3 5 1 2 1 2 1 1 1 1 " }, { "input": "5\nBBBWB", "output": "2\n3 1 " }, { "input": "5\nBWWWB", "output": "2\n1 1 " }, { "input": "5\nWWWWB", "output": "1\n1 " }, { "input": "5\nBWWWW", "output": "1\n1 " }, { "input": "5\nBBBWW", "output": "1\n3 " }, { "input": "5\nWWBBB", "output": "1\n3 " }, { "input": "10\nBBBBBWWBBB", "output": "2\n5 3 " }, { "input": "10\nBBBBWBBWBB", "output": "3\n4 2 2 " }, { "input": "20\nBBBBBWWBWBBWBWWBWBBB", "output": "6\n5 1 2 1 1 3 " }, { "input": "20\nBBBWWWWBBWWWBWBWWBBB", "output": "5\n3 2 1 1 3 " }, { "input": "20\nBBBBBBBBWBBBWBWBWBBB", "output": "5\n8 3 1 1 3 " }, { "input": "20\nBBBWBWBWWWBBWWWWBWBB", "output": "6\n3 1 1 2 1 2 " }, { "input": "40\nBBBBBBWWWWBWBWWWBWWWWWWWWWWWBBBBBBBBBBBB", "output": "5\n6 1 1 1 12 " }, { "input": "40\nBBBBBWBWWWBBWWWBWBWWBBBBWWWWBWBWBBBBBBBB", "output": "9\n5 1 2 1 1 4 1 1 8 " }, { "input": "50\nBBBBBBBBBBBWWWWBWBWWWWBBBBBBBBWWWWWWWBWWWWBWBBBBBB", "output": "7\n11 1 1 8 1 1 6 " }, { "input": "50\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW", "output": "0" }, { "input": "50\nBBBBBWWWWWBWWWBWWWWWBWWWBWWWWWWBBWBBWWWWBWWWWWWWBW", "output": "9\n5 1 1 1 1 2 2 1 1 " }, { "input": "50\nWWWWBWWBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWBWWWWWWWBBBBB", "output": "6\n1 1 1 1 1 5 " }, { "input": "50\nBBBBBWBWBWWBWBWWWWWWBWBWBWWWWWWWWWWWWWBWBWWWWBWWWB", "output": "12\n5 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n50 " }, { "input": "100\nBBBBBBBBBBBWBWWWWBWWBBWBBWWWWWWWWWWBWBWWBWWWWWWWWWWWBBBWWBBWWWWWBWBWWWWBWWWWWWWWWWWBWWWWWBBBBBBBBBBB", "output": "15\n11 1 1 2 2 1 1 1 3 2 1 1 1 1 11 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n100 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBWBWBWWWWWBWWWWWWWWWWWWWWBBWWWBWWWWBWWBWWWWWWBWWWWWWWWWWWWWBWBBBBBBBBBBBBBBBBBBBB", "output": "11\n20 1 1 1 2 1 1 1 1 1 20 " }, { "input": "100\nBBBBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWWWWWBWBWWWWWWBBWWWWWWWWWWWWBWWWWBWWWWWWWWWWWWBWWWWWWWBWWWWWWWBBBBBB", "output": "11\n4 1 1 1 1 2 1 1 1 1 6 " }, { "input": "5\nBWBWB", "output": "3\n1 1 1 " }, { "input": "10\nWWBWWWBWBB", "output": "3\n1 1 2 " }, { "input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "1\n50 " }, { "input": "50\nBBBBBBBBBBBBBBBBBWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "2\n17 31 " }, { "input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "2\n24 42 " }, { "input": "90\nWWBWWBWBBWBBWWBWBWBBBWBWBBBWBWBWBWBWBWBWBWBBBBBWBBWWWWBWBBWBWWBBBWBWBWWBWBWBWBWWWWWWBWBBBB", "output": "30\n1 1 2 2 1 1 3 1 3 1 1 1 1 1 1 1 5 2 1 2 1 3 1 1 1 1 1 1 1 4 " }, { "input": "100\nBWWWBWBWBBBBBWBWWBWBWWWBWBWBWWBBWWBBBWBBBWWBWBWWBBBBWBWBBBWBWBBWWWWWWBWWBBBBWBWBWWBWBWWWBWBWWBWBWWWB", "output": "31\n1 1 1 5 1 1 1 1 1 1 2 3 3 1 1 4 1 3 1 2 1 4 1 1 1 1 1 1 1 1 1 " }, { "input": "90\nWBWBBBBBBWWWBBWWBWWWBBWWBWWWBWBBWBWBBWWWWBWBWBBWBBWBWWWBBWBBWWWWBWBBWWWBBBWBBWBWBBBBWWBWWB", "output": "25\n1 6 2 1 2 1 1 2 1 2 1 1 2 2 1 2 2 1 2 3 2 1 4 1 1 " }, { "input": "80\nBBWWBBBWBBWWWWBBWBWBBWWWWWBWBBWWBWBWBWBWBWWBWWBWWWBWBBWBBWBBWBBBWWBBBBBBBWBBBWBB", "output": "23\n2 3 2 2 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 3 7 3 2 " }, { "input": "65\nWWWWBWWWBBBBBWWWWWWBBBWWBBBBWWWWWWWWBBBWWWWBWBWWBBWWWWBWWWBBWBBBB", "output": "11\n1 5 3 4 3 1 1 2 1 2 4 " } ]
1,660,934,469
2,147,483,647
Python 3
OK
TESTS
54
46
0
class OneDimensionalJapaneseCrossword: def __init__(self): self.lastChar = 'W' self.groups = [] def addChar(self, char): if char == 'B': if self.lastChar == 'W': self.groups.append(1) else: self.groups[-1] += 1 self.lastChar = char if __name__ == "__main__": # Ler a entrada n = int(input()) row = input() # Instanciar classe crossword = OneDimensionalJapaneseCrossword() # Processar entrada for c in row: crossword.addChar(c) # Exibir saída k = len(crossword.groups) print(k) print(*crossword.groups)
Title: One-dimensional Japanese Crossword Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)). Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword. Help Adaltik find the numbers encrypting the row he drew. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). Output Specification: The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row. The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. Demo Input: ['3\nBBW\n', '5\nBWBWB\n', '4\nWWWW\n', '4\nBBBB\n', '13\nWBBBBWWBWBBBW\n'] Demo Output: ['1\n2 ', '3\n1 1 1 ', '0\n', '1\n4 ', '3\n4 1 3 '] Note: The last sample case correspond to the picture in the statement.
```python class OneDimensionalJapaneseCrossword: def __init__(self): self.lastChar = 'W' self.groups = [] def addChar(self, char): if char == 'B': if self.lastChar == 'W': self.groups.append(1) else: self.groups[-1] += 1 self.lastChar = char if __name__ == "__main__": # Ler a entrada n = int(input()) row = input() # Instanciar classe crossword = OneDimensionalJapaneseCrossword() # Processar entrada for c in row: crossword.addChar(c) # Exibir saída k = len(crossword.groups) print(k) print(*crossword.groups) ```
3
549
H
Degenerate Matrix
PROGRAMMING
2,100
[ "binary search", "math" ]
null
null
The determinant of a matrix 2<=×<=2 is defined as follows: A matrix is called degenerate if its determinant is equal to zero. The norm ||*A*|| of a matrix *A* is defined as a maximum of absolute values of its elements. You are given a matrix . Consider any degenerate matrix *B* such that norm ||*A*<=-<=*B*|| is minimum possible. Determine ||*A*<=-<=*B*||.
The first line contains two integers *a* and *b* (|*a*|,<=|*b*|<=≤<=109), the elements of the first row of matrix *A*. The second line contains two integers *c* and *d* (|*c*|,<=|*d*|<=≤<=109) the elements of the second row of matrix *A*.
Output a single real number, the minimum possible value of ||*A*<=-<=*B*||. Your answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=9.
[ "1 2\n3 4\n", "1 0\n0 1\n" ]
[ "0.2000000000\n", "0.5000000000\n" ]
In the first sample matrix *B* is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ce214ad27bde5d77f87492eedd74d34c745f72a1.png" style="max-width: 100.0%;max-height: 100.0%;"/> In the second sample matrix *B* is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a07c34fbc6e9328bcb519d3f780eea6e02e5dc87.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,500
[ { "input": "1 2\n3 4", "output": "0.2000000000" }, { "input": "1 0\n0 1", "output": "0.5000000000" }, { "input": "1000000000 0\n0 1000000000", "output": "500000000.0000000000" }, { "input": "8205 9482\n11 -63", "output": "35.0198432832" }, { "input": "0 0\n0 0", "output": "0.0000000000" }, { "input": "1000000000 -1000000000\n1000000000 1000000000", "output": "1000000000.0000000000" }, { "input": "1000000000 1000000000\n1000000000 -1000000000", "output": "1000000000.0000000000" }, { "input": "-1 -1\n1 0", "output": "0.3333333333" }, { "input": "5 2\n-15 -6", "output": "0.0000000000" }, { "input": "2 -5\n-3 2", "output": "0.9166666667" }, { "input": "-5 -2\n-1 -3", "output": "1.1818181818" }, { "input": "-5 8\n1 6", "output": "2.1111111111" }, { "input": "1 3\n3 2", "output": "0.7777777778" }, { "input": "-42 63\n77 -32", "output": "16.3878504673" }, { "input": "91 -7\n-21 91", "output": "38.7333333333" }, { "input": "-67 -77\n-56 -75", "output": "2.5927272727" }, { "input": "-26 53\n-48 -89", "output": "29.6219512195" }, { "input": "97 -934\n-707 184", "output": "334.2819979188" }, { "input": "689 412\n-794 -421", "output": "16.0012953368" }, { "input": "-718 -387\n972 972", "output": "105.5204985241" }, { "input": "-126 -376\n75 367", "output": "19.1122881356" }, { "input": "-7 -3674\n845 5737", "output": "298.5843320666" }, { "input": "-9912 755\n-8220 6419", "output": "2268.9886983324" }, { "input": "-3928 5185\n4331 6665", "output": "3969.3426099731" }, { "input": "2056 9614\n-5171 8965", "output": "3141.2387756983" }, { "input": "41642 63236\n-59604 20357", "output": "32033.4760659150" }, { "input": "-38387 -93294\n-52918 -51288", "output": "12582.8868737997" }, { "input": "92812 73253\n-46231 11374", "output": "22109.0927374802" }, { "input": "12784 -94506\n26149 85264", "output": "18439.1869417765" }, { "input": "955162 -709099\n-743655 578837", "output": "8557.1487662354" }, { "input": "160382 -103968\n301943 -156088", "output": "8802.4244934460" }, { "input": "-634398 -468280\n447621 78431", "output": "98147.3248125840" }, { "input": "-398622 -832591\n-506781 -656493", "output": "66924.0413186624" }, { "input": "-2665612 -7693032\n-2861368 -6201836", "output": "282203.1726406262" }, { "input": "1762462 700391\n-7134185 5042962", "output": "1048758.9114990780" }, { "input": "6190536 5693104\n-8006293 -3712238", "output": "957535.4624752104" }, { "input": "553632 5653328\n-7246622 9164341", "output": "2140390.1895580233" }, { "input": "43469186 94408326\n78066381 -19616812", "output": "41883387.4306073852" }, { "input": "25683826 49101909\n88380777 46573745", "output": "14987456.1603828062" }, { "input": "-87068851 98762810\n3727856 -87235696", "output": "26110777.7289122988" }, { "input": "95145788 53456393\n42406028 83987544", "output": "20815549.6776987243" }, { "input": "876432079 -414820618\n-816514132 -914565422", "output": "520028295.4718751899" }, { "input": "-240038673 376842703\n-241080203 410087456", "output": "5983627.7655281517" }, { "input": "938457872 -536526676\n867891897 -855194260", "output": "105349963.0995401485" }, { "input": "116954418 255136645\n-851641472 174491320", "output": "204147910.8375163887" }, { "input": "1 1\n1 5", "output": "0.5000000000" }, { "input": "1 5\n1 1", "output": "0.5000000000" }, { "input": "5 1\n1 1", "output": "0.5000000000" }, { "input": "1 1\n5 1", "output": "0.5000000000" }, { "input": "-1000000000 -1000000000\n1000000000 1000000000", "output": "0.0000000000" }, { "input": "-1000000000 -1000000000\n999999999 999999999", "output": "0.0000000000" }, { "input": "536870912 88\n536870912 22528", "output": "11219.7636804586" }, { "input": "268435456 268435456\n22512 22528", "output": "7.9993289080" }, { "input": "-1 1\n1 1", "output": "1.0000000000" }, { "input": "-1000 -999\n-1 0", "output": "0.4995000000" }, { "input": "-801658422 -738703776\n910442649 -920729415", "output": "744753719.5468964978" }, { "input": "-203893419 -777818\n295920256 -474540430", "output": "99618123.5339717944" }, { "input": "448944609 529185527\n946362390 958011342", "output": "24529803.2444389601" }, { "input": "348741875 -606207234\n-279810821 -14278204", "output": "143060520.9047362779" }, { "input": "-202195424 182466434\n-722509868 -838173079", "output": "190651913.7089770083" }, { "input": "-48 9\n17 -67", "output": "21.7234042553" }, { "input": "12 180\n79 47", "output": "42.9433962264" }, { "input": "-131 -87\n-66 -109", "output": "21.7226463104" }, { "input": "171 17\n9 93", "output": "54.3103448276" }, { "input": "221 20\n-22 -200", "output": "94.5140388769" }, { "input": "372 -352\n-160 -423", "output": "216.4903748734" }, { "input": "480 37\n-3 -459", "output": "224.9325842697" }, { "input": "-535 -395\n-264 513", "output": "321.2340966921" }, { "input": "-498 -685\n-532 526", "output": "503.1068273092" }, { "input": "-16 450\n-848 27", "output": "284.2416107383" }, { "input": "-621967643 610314360\n-660274542 -772630232", "output": "611623765.8647500770" }, { "input": "222416863 97256131\n897661932 -426944193", "output": "125718637.9005708302" }, { "input": "67861199 302935298\n883117733 559626116", "output": "126575973.2879779836" }, { "input": "1000000000 1\n1000000000 2", "output": "0.4999999993" }, { "input": "-2 1\n1 -2", "output": "0.5000000000" }, { "input": "1000000000 999999995\n99999999 -199992543", "output": "142854098.7306812546" } ]
1,435,555,094
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
4
62
0
a,b=map(int,input().split()) c,d=map(int,input().split()) x=max(abs(a+b+c+d),abs(a+b-c-d),abs(a-b+c-d),abs(a-b-c+d)) print(abs((a*d-b*c)/x))
Title: Degenerate Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: The determinant of a matrix 2<=×<=2 is defined as follows: A matrix is called degenerate if its determinant is equal to zero. The norm ||*A*|| of a matrix *A* is defined as a maximum of absolute values of its elements. You are given a matrix . Consider any degenerate matrix *B* such that norm ||*A*<=-<=*B*|| is minimum possible. Determine ||*A*<=-<=*B*||. Input Specification: The first line contains two integers *a* and *b* (|*a*|,<=|*b*|<=≤<=109), the elements of the first row of matrix *A*. The second line contains two integers *c* and *d* (|*c*|,<=|*d*|<=≤<=109) the elements of the second row of matrix *A*. Output Specification: Output a single real number, the minimum possible value of ||*A*<=-<=*B*||. Your answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=9. Demo Input: ['1 2\n3 4\n', '1 0\n0 1\n'] Demo Output: ['0.2000000000\n', '0.5000000000\n'] Note: In the first sample matrix *B* is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ce214ad27bde5d77f87492eedd74d34c745f72a1.png" style="max-width: 100.0%;max-height: 100.0%;"/> In the second sample matrix *B* is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a07c34fbc6e9328bcb519d3f780eea6e02e5dc87.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python a,b=map(int,input().split()) c,d=map(int,input().split()) x=max(abs(a+b+c+d),abs(a+b-c-d),abs(a-b+c-d),abs(a-b-c+d)) print(abs((a*d-b*c)/x)) ```
-1
934
A
A Compatible Pair
PROGRAMMING
1,400
[ "brute force", "games" ]
null
null
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively. Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. You are asked to find the brightness of the chosen pair if both of them choose optimally.
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*. The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*. All the integers range from <=-<=109 to 109.
Print a single integer — the brightness of the chosen pair.
[ "2 2\n20 18\n2 14\n", "5 3\n-1 0 1 2 3\n-1 0 1\n" ]
[ "252\n", "2\n" ]
In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself. In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
500
[ { "input": "2 2\n20 18\n2 14", "output": "252" }, { "input": "5 3\n-1 0 1 2 3\n-1 0 1", "output": "2" }, { "input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7", "output": "70" }, { "input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 2 6 7 9 4 3 7 2 0\n0 5 9 4 4 6 1 8 2 1 6 6 8 6 4 4 7 2 1 8 6 7 4 9 8 3 0 2 0 10 7 1 4 9 4 4 2 5 3 5 1 3 2 4 1 6 5 3 8 6", "output": "100" }, { "input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n-775179088 631683023 -974858199 -157471745 -629658630 71825477 -6235611", "output": "127184126241438168" }, { "input": "16 15\n-94580188 -713689767 -559972014 -632609438 -930348091 -567718487 -611395744 -819913097 -924009672 -427913920 -812510647 -546415480 -982072775 -693369647 -693004777 -714181162\n-772924706 -202246100 -165871667 -991426281 -490838183 209351416 134956137 -36128588 -754413937 -616596290 696201705 -201191199 967464971 -244181984 -729907974", "output": "922371547895579571" }, { "input": "12 22\n-102896616 -311161241 -67541276 -402842686 -830595520 -813834033 -44046671 -584806552 -598620444 -968935604 -303048547 -545969410\n545786451 262898403 442511997 -441241260 -479587986 -752123290 720443264 500646237 737842681 -571966572 -798463881 -477248830 89875164 410339460 -359022689 -251280099 -441455542 -538431186 -406793869 374561004 -108755237 -440143410", "output": "663200522440413120" }, { "input": "33 14\n-576562007 -218618150 -471719380 -583840778 -256368365 -68451917 -405045344 -775538133 -896830082 -439261765 -947070124 -716577019 -456110999 -689862512 -132480131 -10805271 -518903339 -196240188 -222292638 -828546042 -43887962 -161359263 -281422097 -484060534 963147664 -492377073 -154570101 -52145116 187803553 858844161 66540410 418777176 434025748\n-78301978 -319393213 -12393024 542953412 786804661 845642067 754996432 -985617475 -487171947 56142664 203173079 -268261708 -817080591 -511720682", "output": "883931400924882950" }, { "input": "15 8\n-966400308 -992207261 -302395973 -837980754 -516443826 -492405613 -378127629 -762650324 -519519776 -36132939 -286460372 -351445284 -407653342 -604960925 -523442015\n610042288 27129580 -103108347 -942517864 842060508 -588904868 614786155 37455106", "output": "910849554065102112" }, { "input": "6 30\n-524297819 -947277203 -444186475 -182837689 -385379656 -453917269\n834529938 35245081 663687669 585422565 164412867 850052113 796429008 -307345676 -127653313 426960600 211854713 -733687358 251466836 -33491050 -882811238 455544614 774581544 768447941 -241033484 441104324 -493975870 308277556 275268265 935941507 -152292053 -961509996 -740482111 -954176110 -924254634 -518710544", "output": "504117593849498724" }, { "input": "5 32\n-540510995 -841481393 -94342377 -74818927 -93445356\n686714668 -82581175 736472406 502016312 575563638 -899308712 503504178 -644271272 -437408397 385778869 -746757839 306275973 -663503743 -431116516 -418708278 -515261493 -988182324 900230931 218258353 -714420102 -241118202 294802602 -937785552 -857537498 -723195312 -690515139 -214508504 -44086454 -231621215 -418360090 -810003786 -675944617", "output": "534123411186652380" }, { "input": "32 13\n-999451897 -96946179 -524159869 -906101658 -63367320 -629803888 -968586834 -658416130 -874232857 -926556428 -749908220 -517073321 -659752288 -910152878 -786916085 -607633039 -191428642 -867952926 -873793977 -584331784 -733245792 -779809700 -554228536 -464503499 561577340 258991071 -569805979 -372655165 -106685554 -619607960 188856473 -268960803\n886429660 -587284372 911396803 -462990289 -228681210 -876239914 -822830527 -750131315 -401234943 116991909 -582713480 979631847 813552478", "output": "848714444125692276" }, { "input": "12 25\n-464030345 -914672073 -483242132 -856226270 -925135169 -353124606 -294027092 -619650850 -490724485 -240424784 -483066792 -921640365\n279850608 726838739 -431610610 242749870 -244020223 -396865433 129534799 182767854 -939698671 342579400 330027106 893561388 -263513962 643369418 276245179 -99206565 -473767261 -168908664 -853755837 -270920164 -661186118 199341055 765543053 908211534 -93363867", "output": "866064226130454915" }, { "input": "10 13\n-749120991 -186261632 -335412349 -231354880 -195919225 -808736065 -481883825 -263383991 -664780611 -605377134\n718174936 -140362196 -669193674 -598621021 -464130929 450701419 -331183926 107203430 946959233 -565825915 -558199897 246556991 -666216081", "output": "501307028237810934" }, { "input": "17 13\n-483786205 -947257449 -125949195 -294711143 -420288876 -812462057 -250049555 -911026413 -188146919 -129501682 -869006661 -649643966 -26976411 -275761039 -869067490 -272248209 -342067346\n445539900 529728842 -808170728 673157826 -70778491 642872105 299298867 -76674218 -902394063 377664752 723887448 -121522827 906464625", "output": "822104826327386019" }, { "input": "15 29\n-716525085 -464205793 -577203110 -979997115 -491032521 -70793687 -770595947 -817983495 -767886763 -223333719 -971913221 -944656683 -200397825 -295615495 -945544540\n-877638425 -146878165 523758517 -158778747 -49535534 597311016 77325385 494128313 12111658 -4196724 295706874 477139483 375083042 726254399 -439255703 662913604 -481588088 673747948 -345999555 -723334478 -656721905 276267528 628773156 851420802 -585029291 -643535709 -968999740 -384418713 -510285542", "output": "941783658451562540" }, { "input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n449942926 482853427 861095072 316710734 194604468 20277633 668816604", "output": "-1288212069119760" }, { "input": "24 24\n-700068683 -418791905 -24650102 -167277317 -182309202 -517748507 -663050677 -854097070 -426998982 -197009558 -101944229 -746589957 -849018439 -774208211 -946709040 -594578249 -276703474 -434567489 -743600446 -625029074 -977300284 -895608684 -878936220 -850670748\n704881272 169877679 705460701 94083210 403943695 987978311 786162506 658067668 697640875 186287 295558596 286470276 251313879 353071193 755450449 173370603 805550377 192465301 168935494 110161743 285139426 985238736 723221868 520679017", "output": "-18990884587723" }, { "input": "39 9\n44558618 981372779 318891054 283079237 285093436 907256321 414759796 652683534 79042330 249010687 7020063 309415438 788425492 138577429 714835649 954204512 795507844 389962019 507308352 408180613 194676444 44962879 922688019 101163040 327953325 560462120 183657590 273616448 226876035 233697890 720185285 689340674 372938362 15088928 283418109 796807778 149989495 694808087 276385512\n-681609072 -210918688 -757170622 -205635977 -597872997 -496188744 -97031207 -311654366 -389141528", "output": "-1464096896176096" }, { "input": "5 7\n869535768 926886134 457905290 946881177 936471280\n-550057074 -517146573 -138904928 -683289266 -805395532 -979722367 -331183396", "output": "-120782803247464704" }, { "input": "24 24\n299931317 581208095 975349898 832722683 817690798 482251493 336949323 145902930 573001018 802990442 898055771 253410043 150981561 225791789 53290960 405421751 723296526 565432511 256399554 374970926 22699716 104391316 121063780 149329252\n-295118728 -830122321 -294539299 -905916790 -596056305 -12021689 -213837494 -341932332 -302359125 -999813713 -704441404 -713529724 -748686121 -646928807 -244549551 -826629397 -194449623 -807534699 -831064506 -889838257 -714860574 -14761264 -276778132 -479320983", "output": "-640647347631440" }, { "input": "14 8\n-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "-1000000000000000000" } ]
1,521,366,602
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
93
7,065,600
input() t_array = list(map(int, input().split())) b_array = list(map(int, input().split())) t_array.sort() b_array.sort() print(t_array[-2]*b_array[-1])
Title: A Compatible Pair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively. Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. You are asked to find the brightness of the chosen pair if both of them choose optimally. Input Specification: The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*. The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*. All the integers range from <=-<=109 to 109. Output Specification: Print a single integer — the brightness of the chosen pair. Demo Input: ['2 2\n20 18\n2 14\n', '5 3\n-1 0 1 2 3\n-1 0 1\n'] Demo Output: ['252\n', '2\n'] Note: In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself. In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.
```python input() t_array = list(map(int, input().split())) b_array = list(map(int, input().split())) t_array.sort() b_array.sort() print(t_array[-2]*b_array[-1]) ```
0
630
C
Lucky Numbers
PROGRAMMING
1,100
[ "combinatorics", "math" ]
null
null
The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than *n* digits.
The only line of input contains one integer *n* (1<=≤<=*n*<=≤<=55) — the maximum length of a number that a door-plate can hold.
Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than *n* digits.
[ "2\n" ]
[ "6" ]
none
0
[ { "input": "2", "output": "6" }, { "input": "1", "output": "2" }, { "input": "3", "output": "14" }, { "input": "5", "output": "62" }, { "input": "12", "output": "8190" }, { "input": "34", "output": "34359738366" }, { "input": "43", "output": "17592186044414" }, { "input": "49", "output": "1125899906842622" }, { "input": "54", "output": "36028797018963966" }, { "input": "55", "output": "72057594037927934" } ]
1,695,455,692
2,147,483,647
Python 3
OK
TESTS
10
46
0
cnt = 0 for i in range(1,int(input())+1): cnt += 2**i print(cnt) # Sat Sep 23 2023 10:26:19 GMT+0300 (Moscow Standard Time)
Title: Lucky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than *n* digits. Input Specification: The only line of input contains one integer *n* (1<=≤<=*n*<=≤<=55) — the maximum length of a number that a door-plate can hold. Output Specification: Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than *n* digits. Demo Input: ['2\n'] Demo Output: ['6'] Note: none
```python cnt = 0 for i in range(1,int(input())+1): cnt += 2**i print(cnt) # Sat Sep 23 2023 10:26:19 GMT+0300 (Moscow Standard Time) ```
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,670,752,560
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
a, b = int(input()), int(input()) print(min(a, b), '', (a - min(a, b) + b - min(a, b))//2)
Title: Vasya the Hipster Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him? Input Specification: The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. Output Specification: Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. Demo Input: ['3 1\n', '2 3\n', '7 3\n'] Demo Output: ['1 1\n', '2 0\n', '3 2\n'] Note: In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
```python a, b = int(input()), int(input()) print(min(a, b), '', (a - min(a, b) + b - min(a, b))//2) ```
-1
461
A
Appleman and Toastman
PROGRAMMING
1,200
[ "greedy", "sortings" ]
null
null
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman.
Print a single integer — the largest possible score.
[ "3\n3 1 5\n", "1\n10\n" ]
[ "26\n", "10\n" ]
Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
500
[ { "input": "3\n3 1 5", "output": "26" }, { "input": "1\n10", "output": "10" }, { "input": "10\n8 10 2 5 6 2 4 7 2 1", "output": "376" }, { "input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821", "output": "40204082" }, { "input": "10\n1 2 2 2 4 5 6 7 8 10", "output": "376" }, { "input": "10\n161821 171308 228496 397870 431255 542924 718337 724672 888642 892002", "output": "40204082" }, { "input": "1\n397870", "output": "397870" }, { "input": "1\n1000000", "output": "1000000" }, { "input": "10\n10 8 7 6 5 4 2 2 2 1", "output": "376" }, { "input": "10\n892002 888642 724672 718337 542924 431255 397870 228496 171308 161821", "output": "40204082" }, { "input": "10\n5 2 6 10 10 10 10 2 2 5", "output": "485" }, { "input": "10\n431255 724672 228496 397870 397870 397870 397870 724672 888642 431255", "output": "36742665" }, { "input": "10\n2 2 2 5 5 6 10 10 10 10", "output": "485" }, { "input": "10\n228496 397870 397870 397870 397870 431255 431255 724672 724672 888642", "output": "36742665" }, { "input": "10\n10 10 10 10 6 5 5 2 2 2", "output": "485" }, { "input": "10\n888642 724672 724672 431255 431255 397870 397870 397870 397870 228496", "output": "36742665" }, { "input": "10\n10 10 10 10 10 10 10 10 10 10", "output": "640" }, { "input": "10\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000", "output": "64000000" }, { "input": "1\n397870", "output": "397870" }, { "input": "2\n1 2", "output": "6" }, { "input": "2\n2 3", "output": "10" }, { "input": "2\n1 1", "output": "4" } ]
1,454,534,641
2,147,483,647
Python 3
OK
TESTS
36
420
20,992,000
n = int(input()) xs = sorted(map(int, input().split())) r = 0 for i, x in enumerate(xs, start=1): r += x * (i + 1 if i < n else i) print(r)
Title: Appleman and Toastman Time Limit: None seconds Memory Limit: None megabytes Problem Description: Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. Output Specification: Print a single integer — the largest possible score. Demo Input: ['3\n3 1 5\n', '1\n10\n'] Demo Output: ['26\n', '10\n'] Note: Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
```python n = int(input()) xs = sorted(map(int, input().split())) r = 0 for i, x in enumerate(xs, start=1): r += x * (i + 1 if i < n else i) print(r) ```
3
962
A
Equator
PROGRAMMING
1,300
[ "implementation" ]
null
null
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems. Determine the index of day when Polycarp will celebrate the equator.
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests. The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day.
Print the index of the day when Polycarp will celebrate the equator.
[ "4\n1 3 2 1\n", "6\n2 2 2 2 2 2\n" ]
[ "2\n", "3\n" ]
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $6$ out of $12$ scheduled problems on six days of the training.
0
[ { "input": "4\n1 3 2 1", "output": "2" }, { "input": "6\n2 2 2 2 2 2", "output": "3" }, { "input": "1\n10000", "output": "1" }, { "input": "3\n2 1 1", "output": "1" }, { "input": "2\n1 3", "output": "2" }, { "input": "4\n2 1 1 3", "output": "3" }, { "input": "3\n1 1 3", "output": "3" }, { "input": "3\n1 1 1", "output": "2" }, { "input": "2\n1 2", "output": "2" }, { "input": "3\n2 1 2", "output": "2" }, { "input": "5\n1 2 4 3 5", "output": "4" }, { "input": "5\n2 2 2 4 3", "output": "4" }, { "input": "4\n1 2 3 1", "output": "3" }, { "input": "6\n7 3 10 7 3 11", "output": "4" }, { "input": "2\n3 4", "output": "2" }, { "input": "5\n1 1 1 1 1", "output": "3" }, { "input": "4\n1 3 2 3", "output": "3" }, { "input": "2\n2 3", "output": "2" }, { "input": "3\n32 10 23", "output": "2" }, { "input": "7\n1 1 1 1 1 1 1", "output": "4" }, { "input": "3\n1 2 4", "output": "3" }, { "input": "6\n3 3 3 2 4 4", "output": "4" }, { "input": "9\n1 1 1 1 1 1 1 1 1", "output": "5" }, { "input": "5\n1 3 3 1 1", "output": "3" }, { "input": "4\n1 1 1 2", "output": "3" }, { "input": "4\n1 2 1 3", "output": "3" }, { "input": "3\n2 2 1", "output": "2" }, { "input": "4\n2 3 3 3", "output": "3" }, { "input": "4\n3 2 3 3", "output": "3" }, { "input": "4\n2 1 1 1", "output": "2" }, { "input": "3\n2 1 4", "output": "3" }, { "input": "2\n6 7", "output": "2" }, { "input": "4\n3 3 4 3", "output": "3" }, { "input": "4\n1 1 2 5", "output": "4" }, { "input": "4\n1 8 7 3", "output": "3" }, { "input": "6\n2 2 2 2 2 3", "output": "4" }, { "input": "3\n2 2 5", "output": "3" }, { "input": "4\n1 1 2 1", "output": "3" }, { "input": "5\n1 1 2 2 3", "output": "4" }, { "input": "5\n9 5 3 4 8", "output": "3" }, { "input": "3\n3 3 1", "output": "2" }, { "input": "4\n1 2 2 2", "output": "3" }, { "input": "3\n1 3 5", "output": "3" }, { "input": "4\n1 1 3 6", "output": "4" }, { "input": "6\n1 2 1 1 1 1", "output": "3" }, { "input": "3\n3 1 3", "output": "2" }, { "input": "5\n3 4 5 1 2", "output": "3" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "6" }, { "input": "5\n3 1 2 5 2", "output": "4" }, { "input": "4\n1 1 1 4", "output": "4" }, { "input": "4\n2 6 1 10", "output": "4" }, { "input": "4\n2 2 3 2", "output": "3" }, { "input": "4\n4 2 2 1", "output": "2" }, { "input": "6\n1 1 1 1 1 4", "output": "5" }, { "input": "3\n3 2 2", "output": "2" }, { "input": "6\n1 3 5 1 7 4", "output": "5" }, { "input": "5\n1 2 4 8 16", "output": "5" }, { "input": "5\n1 2 4 4 4", "output": "4" }, { "input": "6\n4 2 1 2 3 1", "output": "3" }, { "input": "4\n3 2 1 5", "output": "3" }, { "input": "1\n1", "output": "1" }, { "input": "3\n2 4 7", "output": "3" }, { "input": "5\n1 1 1 1 3", "output": "4" }, { "input": "3\n3 1 5", "output": "3" }, { "input": "4\n1 2 3 7", "output": "4" }, { "input": "3\n1 4 6", "output": "3" }, { "input": "4\n2 1 2 2", "output": "3" }, { "input": "2\n4 5", "output": "2" }, { "input": "5\n1 2 1 2 1", "output": "3" }, { "input": "3\n2 3 6", "output": "3" }, { "input": "6\n1 1 4 1 1 5", "output": "4" }, { "input": "5\n2 2 2 2 1", "output": "3" }, { "input": "2\n5 6", "output": "2" }, { "input": "4\n2 2 1 4", "output": "3" }, { "input": "5\n2 2 3 4 4", "output": "4" }, { "input": "4\n3 1 1 2", "output": "2" }, { "input": "5\n3 4 1 4 5", "output": "4" }, { "input": "4\n1 3 1 6", "output": "4" }, { "input": "5\n1 1 1 2 2", "output": "4" }, { "input": "4\n1 4 2 4", "output": "3" }, { "input": "10\n1 1 1 1 1 1 1 1 1 8", "output": "9" }, { "input": "4\n1 4 5 1", "output": "3" }, { "input": "5\n1 1 1 1 5", "output": "5" }, { "input": "4\n1 3 4 1", "output": "3" }, { "input": "4\n2 2 2 3", "output": "3" }, { "input": "4\n2 3 2 4", "output": "3" }, { "input": "5\n2 2 1 2 2", "output": "3" }, { "input": "3\n4 3 2", "output": "2" }, { "input": "3\n6 5 2", "output": "2" }, { "input": "69\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "35" }, { "input": "6\n1 1 1 1 1 2", "output": "4" }, { "input": "5\n1 2 5 4 5", "output": "4" }, { "input": "2\n9 10", "output": "2" }, { "input": "3\n1 1 5", "output": "3" }, { "input": "4\n3 4 3 5", "output": "3" }, { "input": "4\n1 4 3 3", "output": "3" }, { "input": "4\n7 1 3 4", "output": "2" }, { "input": "3\n100 100 1", "output": "2" }, { "input": "4\n5 2 2 2", "output": "2" } ]
1,679,446,472
2,147,483,647
PyPy 3-64
OK
TESTS
106
93
21,504,000
# -*- coding: utf-8 -*- def solve(): n = int(input()) a = list(map(int, input().split(' '))) sum = 0 for i in range(n): sum += a[i] sum = (sum + 1) // 2 cur = 0 for i in range(n): cur += a[i] if (cur >= sum): print(i + 1) return def main(): t = 1 # t = int(input()) for i in range(t): solve() if __name__ == "__main__": main()
Title: Equator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems. Determine the index of day when Polycarp will celebrate the equator. Input Specification: The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests. The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. Output Specification: Print the index of the day when Polycarp will celebrate the equator. Demo Input: ['4\n1 3 2 1\n', '6\n2 2 2 2 2 2\n'] Demo Output: ['2\n', '3\n'] Note: In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $6$ out of $12$ scheduled problems on six days of the training.
```python # -*- coding: utf-8 -*- def solve(): n = int(input()) a = list(map(int, input().split(' '))) sum = 0 for i in range(n): sum += a[i] sum = (sum + 1) // 2 cur = 0 for i in range(n): cur += a[i] if (cur >= sum): print(i + 1) return def main(): t = 1 # t = int(input()) for i in range(t): solve() if __name__ == "__main__": main() ```
3
672
B
Different is Good
PROGRAMMING
1,000
[ "constructive algorithms", "implementation", "strings" ]
null
null
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba". If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible. Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*. The second line contains the string *s* of length *n* consisting of only lowercase English letters.
If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
[ "2\naa\n", "4\nkoko\n", "5\nmurat\n" ]
[ "1\n", "2\n", "0\n" ]
In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
1,000
[ { "input": "2\naa", "output": "1" }, { "input": "4\nkoko", "output": "2" }, { "input": "5\nmurat", "output": "0" }, { "input": "6\nacbead", "output": "1" }, { "input": "7\ncdaadad", "output": "4" }, { "input": "25\npeoaicnbisdocqofsqdpgobpn", "output": "12" }, { "input": "25\ntcqpchnqskqjacruoaqilgebu", "output": "7" }, { "input": "13\naebaecedabbee", "output": "8" }, { "input": "27\naaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "-1" }, { "input": "10\nbababbdaee", "output": "6" }, { "input": "11\ndbadcdbdbca", "output": "7" }, { "input": "12\nacceaabddaaa", "output": "7" }, { "input": "13\nabddfbfaeecfa", "output": "7" }, { "input": "14\neeceecacdbcbbb", "output": "9" }, { "input": "15\ndcbceaaggabaheb", "output": "8" }, { "input": "16\nhgiegfbadgcicbhd", "output": "7" }, { "input": "17\nabhfibbdddfghgfdi", "output": "10" }, { "input": "26\nbbbbbabbaababaaabaaababbaa", "output": "24" }, { "input": "26\nahnxdnbfbcrirerssyzydihuee", "output": "11" }, { "input": "26\nhwqeqhkpxwulbsiwmnlfyhgknc", "output": "8" }, { "input": "26\nrvxmulriorilidecqwmfaemifj", "output": "10" }, { "input": "26\naowpmreooavnmamogdoopuisge", "output": "12" }, { "input": "26\ninimevtuefhvuefirdehmmfudh", "output": "15" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "25" }, { "input": "27\nqdcfjtblgglnilgassirrjekcjt", "output": "-1" }, { "input": "27\nabcdefghijklmnopqrstuvwxyza", "output": "-1" }, { "input": "26\nqwertyuiopasdfghjklzxcvbnm", "output": "0" }, { "input": "5\nzzzzz", "output": "4" }, { "input": "27\naaaaaaaaaaaaaaaaabaaaaaaaaa", "output": "-1" }, { "input": "1\nq", "output": "0" }, { "input": "27\nqwertyuioplkjhgfdsazxcvbnmm", "output": "-1" }, { "input": "9\nxxxyyyzzz", "output": "6" }, { "input": "45\naaabbbcccdddeeefffgghhiijjkkkkkkkkkkkkkkkkkkk", "output": "-1" }, { "input": "27\nqwertyuiopasdfghjklzxcvbnmm", "output": "-1" }, { "input": "26\nabcdefghijklmnopqrstuvwxyz", "output": "0" }, { "input": "26\nabcdefghijklmnopqrstuvwxya", "output": "1" }, { "input": "27\nabcdefghijklmnopqrstuvwxyzz", "output": "-1" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "25" }, { "input": "26\nqwertyuioplkjhgfdsazxcvbnm", "output": "0" }, { "input": "10\nzzzzzzzzzz", "output": "9" }, { "input": "1\na", "output": "0" }, { "input": "30\nabcdefghtyabcdefghtyabcdefghty", "output": "-1" } ]
1,677,135,290
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
31
0
a=int(input()) b=input() c=abs(len(set(b))-len(b)) print(c if c < 100000 else -1)
Title: Different is Good Time Limit: None seconds Memory Limit: None megabytes Problem Description: A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba". If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible. Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*. The second line contains the string *s* of length *n* consisting of only lowercase English letters. Output Specification: If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. Demo Input: ['2\naa\n', '4\nkoko\n', '5\nmurat\n'] Demo Output: ['1\n', '2\n', '0\n'] Note: In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
```python a=int(input()) b=input() c=abs(len(set(b))-len(b)) print(c if c < 100000 else -1) ```
0
99
B
Help Chef Gerasim
PROGRAMMING
1,300
[ "implementation", "sortings" ]
B. Help Chef Gerasim
0
256
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently. To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice.
The first line contains integer *n* — the number of cups on the royal table (1<=≤<=*n*<=≤<=1000). Next *n* lines contain volumes of juice in each cup — non-negative integers, not exceeding 104.
If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "*v* ml. from cup #*a* to cup #*b*." (without the quotes), where *v* represents the volume of poured juice, *a* represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), *b* represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes).
[ "5\n270\n250\n250\n230\n250\n", "5\n250\n250\n250\n250\n250\n", "5\n270\n250\n249\n230\n250\n" ]
[ "20 ml. from cup #4 to cup #1.\n", "Exemplary pages.\n", "Unrecoverable configuration.\n" ]
none
1,000
[ { "input": "5\n270\n250\n250\n230\n250", "output": "20 ml. from cup #4 to cup #1." }, { "input": "5\n250\n250\n250\n250\n250", "output": "Exemplary pages." }, { "input": "5\n270\n250\n249\n230\n250", "output": "Unrecoverable configuration." }, { "input": "4\n200\n190\n210\n200", "output": "10 ml. from cup #2 to cup #3." }, { "input": "4\n1\n2\n3\n4", "output": "Unrecoverable configuration." }, { "input": "1\n0", "output": "Exemplary pages." }, { "input": "2\n0\n0", "output": "Exemplary pages." }, { "input": "2\n0\n1", "output": "Unrecoverable configuration." }, { "input": "2\n0\n2", "output": "1 ml. from cup #1 to cup #2." }, { "input": "2\n1\n0", "output": "Unrecoverable configuration." }, { "input": "2\n1\n1", "output": "Exemplary pages." }, { "input": "2\n1\n2", "output": "Unrecoverable configuration." }, { "input": "2\n2\n0", "output": "1 ml. from cup #2 to cup #1." }, { "input": "2\n2\n1", "output": "Unrecoverable configuration." }, { "input": "2\n2\n2", "output": "Exemplary pages." }, { "input": "3\n0\n0\n0", "output": "Exemplary pages." }, { "input": "3\n0\n0\n1", "output": "Unrecoverable configuration." }, { "input": "3\n0\n0\n2", "output": "Unrecoverable configuration." }, { "input": "3\n0\n1\n0", "output": "Unrecoverable configuration." }, { "input": "3\n0\n1\n1", "output": "Unrecoverable configuration." }, { "input": "3\n0\n1\n2", "output": "1 ml. from cup #1 to cup #3." }, { "input": "3\n0\n2\n0", "output": "Unrecoverable configuration." }, { "input": "3\n0\n2\n1", "output": "1 ml. from cup #1 to cup #2." }, { "input": "3\n0\n2\n2", "output": "Unrecoverable configuration." }, { "input": "3\n1\n0\n0", "output": "Unrecoverable configuration." }, { "input": "3\n1\n0\n1", "output": "Unrecoverable configuration." }, { "input": "3\n1\n0\n2", "output": "1 ml. from cup #2 to cup #3." }, { "input": "3\n1\n1\n0", "output": "Unrecoverable configuration." }, { "input": "3\n1\n1\n1", "output": "Exemplary pages." }, { "input": "3\n1\n1\n2", "output": "Unrecoverable configuration." }, { "input": "3\n1\n2\n0", "output": "1 ml. from cup #3 to cup #2." }, { "input": "3\n1\n2\n1", "output": "Unrecoverable configuration." }, { "input": "3\n1\n2\n2", "output": "Unrecoverable configuration." }, { "input": "3\n2\n0\n0", "output": "Unrecoverable configuration." }, { "input": "3\n2\n0\n1", "output": "1 ml. from cup #2 to cup #1." }, { "input": "3\n2\n0\n2", "output": "Unrecoverable configuration." }, { "input": "3\n2\n1\n0", "output": "1 ml. from cup #3 to cup #1." }, { "input": "3\n2\n1\n1", "output": "Unrecoverable configuration." }, { "input": "3\n2\n1\n2", "output": "Unrecoverable configuration." }, { "input": "3\n2\n2\n0", "output": "Unrecoverable configuration." }, { "input": "3\n2\n2\n1", "output": "Unrecoverable configuration." }, { "input": "3\n2\n2\n2", "output": "Exemplary pages." }, { "input": "4\n0\n0\n0\n0", "output": "Exemplary pages." }, { "input": "4\n0\n0\n0\n1", "output": "Unrecoverable configuration." }, { "input": "4\n0\n0\n0\n2", "output": "Unrecoverable configuration." }, { "input": "4\n0\n0\n1\n0", "output": "Unrecoverable configuration." }, { "input": "4\n0\n0\n1\n1", "output": "Unrecoverable configuration." }, { "input": "4\n0\n0\n1\n2", "output": "Unrecoverable configuration." }, { "input": "4\n0\n0\n2\n0", "output": "Unrecoverable configuration." }, { "input": "4\n0\n0\n2\n1", "output": "Unrecoverable configuration." }, { "input": "4\n0\n0\n2\n2", "output": "Unrecoverable configuration." }, { "input": "4\n0\n1\n0\n0", "output": "Unrecoverable configuration." }, { "input": "4\n0\n1\n0\n1", "output": "Unrecoverable configuration." }, { "input": "4\n0\n1\n0\n2", "output": "Unrecoverable configuration." }, { "input": "4\n0\n1\n1\n0", "output": "Unrecoverable configuration." }, { "input": "4\n0\n1\n1\n1", "output": "Unrecoverable configuration." }, { "input": "4\n0\n1\n1\n2", "output": "1 ml. from cup #1 to cup #4." }, { "input": "4\n0\n1\n2\n0", "output": "Unrecoverable configuration." }, { "input": "4\n0\n1\n2\n1", "output": "1 ml. from cup #1 to cup #3." }, { "input": "4\n0\n1\n2\n2", "output": "Unrecoverable configuration." }, { "input": "4\n0\n2\n0\n0", "output": "Unrecoverable configuration." }, { "input": "4\n0\n2\n0\n1", "output": "Unrecoverable configuration." }, { "input": "4\n0\n2\n0\n2", "output": "Unrecoverable configuration." }, { "input": "4\n0\n2\n1\n0", "output": "Unrecoverable configuration." }, { "input": "4\n0\n2\n1\n1", "output": "1 ml. from cup #1 to cup #2." }, { "input": "4\n0\n2\n1\n2", "output": "Unrecoverable configuration." }, { "input": "4\n0\n2\n2\n0", "output": "Unrecoverable configuration." }, { "input": "4\n0\n2\n2\n1", "output": "Unrecoverable configuration." }, { "input": "4\n0\n2\n2\n2", "output": "Unrecoverable configuration." }, { "input": "4\n1\n0\n0\n0", "output": "Unrecoverable configuration." }, { "input": "4\n1\n0\n0\n1", "output": "Unrecoverable configuration." }, { "input": "4\n1\n0\n0\n2", "output": "Unrecoverable configuration." }, { "input": "4\n1\n0\n1\n0", "output": "Unrecoverable configuration." }, { "input": "4\n1\n0\n1\n1", "output": "Unrecoverable configuration." }, { "input": "4\n1\n0\n1\n2", "output": "1 ml. from cup #2 to cup #4." }, { "input": "4\n1\n0\n2\n0", "output": "Unrecoverable configuration." }, { "input": "4\n1\n0\n2\n1", "output": "1 ml. from cup #2 to cup #3." }, { "input": "4\n1\n0\n2\n2", "output": "Unrecoverable configuration." }, { "input": "4\n1\n1\n0\n0", "output": "Unrecoverable configuration." }, { "input": "4\n1\n1\n0\n1", "output": "Unrecoverable configuration." }, { "input": "4\n1\n1\n0\n2", "output": "1 ml. from cup #3 to cup #4." }, { "input": "4\n1\n1\n1\n0", "output": "Unrecoverable configuration." }, { "input": "4\n1\n1\n1\n1", "output": "Exemplary pages." }, { "input": "4\n1\n1\n1\n2", "output": "Unrecoverable configuration." }, { "input": "4\n1\n1\n2\n0", "output": "1 ml. from cup #4 to cup #3." }, { "input": "4\n1\n1\n2\n1", "output": "Unrecoverable configuration." }, { "input": "4\n1\n1\n2\n2", "output": "Unrecoverable configuration." }, { "input": "4\n1\n2\n0\n0", "output": "Unrecoverable configuration." }, { "input": "4\n1\n2\n0\n1", "output": "1 ml. from cup #3 to cup #2." }, { "input": "4\n1\n2\n0\n2", "output": "Unrecoverable configuration." }, { "input": "4\n1\n2\n1\n0", "output": "1 ml. from cup #4 to cup #2." }, { "input": "4\n1\n2\n1\n1", "output": "Unrecoverable configuration." }, { "input": "4\n1\n2\n1\n2", "output": "Unrecoverable configuration." }, { "input": "4\n1\n2\n2\n0", "output": "Unrecoverable configuration." }, { "input": "4\n1\n2\n2\n1", "output": "Unrecoverable configuration." }, { "input": "4\n1\n2\n2\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n0\n0\n0", "output": "Unrecoverable configuration." }, { "input": "4\n2\n0\n0\n1", "output": "Unrecoverable configuration." }, { "input": "4\n2\n0\n0\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n0\n1\n0", "output": "Unrecoverable configuration." }, { "input": "4\n2\n0\n1\n1", "output": "1 ml. from cup #2 to cup #1." }, { "input": "4\n2\n0\n1\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n0\n2\n0", "output": "Unrecoverable configuration." }, { "input": "4\n2\n0\n2\n1", "output": "Unrecoverable configuration." }, { "input": "4\n2\n0\n2\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n1\n0\n0", "output": "Unrecoverable configuration." }, { "input": "4\n2\n1\n0\n1", "output": "1 ml. from cup #3 to cup #1." }, { "input": "4\n2\n1\n0\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n1\n1\n0", "output": "1 ml. from cup #4 to cup #1." }, { "input": "4\n2\n1\n1\n1", "output": "Unrecoverable configuration." }, { "input": "4\n2\n1\n1\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n1\n2\n0", "output": "Unrecoverable configuration." }, { "input": "4\n2\n1\n2\n1", "output": "Unrecoverable configuration." }, { "input": "4\n2\n1\n2\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n0\n0", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n0\n1", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n0\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n1\n0", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n1\n1", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n1\n2", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n2\n0", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n2\n1", "output": "Unrecoverable configuration." }, { "input": "4\n2\n2\n2\n2", "output": "Exemplary pages." }, { "input": "27\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n2626\n5599\n5599\n5599\n5599\n5599\n8572\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599", "output": "2973 ml. from cup #11 to cup #17." }, { "input": "98\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n1204\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n197\n702\n702\n702\n702\n702\n702\n702\n702\n702", "output": "Unrecoverable configuration." }, { "input": "54\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6859\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n5389\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124", "output": "735 ml. from cup #37 to cup #29." }, { "input": "50\n9636\n9678\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9596\n9636\n9636\n9636\n9636\n9636\n9636", "output": "Unrecoverable configuration." }, { "input": "19\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n82\n5001\n9919\n5001\n5001", "output": "Unrecoverable configuration." }, { "input": "74\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n3918\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n6742\n5330\n5330", "output": "1412 ml. from cup #36 to cup #72." } ]
1,600,366,233
2,147,483,647
Python 3
OK
TESTS
200
109
307,200
n=int(input()) l=[] for i in range(n): l.append(int(input())) a=set(l) if(len(a)==1): print("Exemplary pages.") else: m=min(l) n=max(l) r=(n-m)//2 q=l.index(n) w=l.index(m) l[q]-=r l[w]+=r b=set(l) if(len(b)==1): print(str(r)+" ml. from cup #"+str(w+1)+" to cup #"+str(q+1)+".") else: print("Unrecoverable configuration.")
Title: Help Chef Gerasim Time Limit: 0 seconds Memory Limit: 256 megabytes Problem Description: In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently. To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice. Input Specification: The first line contains integer *n* — the number of cups on the royal table (1<=≤<=*n*<=≤<=1000). Next *n* lines contain volumes of juice in each cup — non-negative integers, not exceeding 104. Output Specification: If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "*v* ml. from cup #*a* to cup #*b*." (without the quotes), where *v* represents the volume of poured juice, *a* represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), *b* represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes). Demo Input: ['5\n270\n250\n250\n230\n250\n', '5\n250\n250\n250\n250\n250\n', '5\n270\n250\n249\n230\n250\n'] Demo Output: ['20 ml. from cup #4 to cup #1.\n', 'Exemplary pages.\n', 'Unrecoverable configuration.\n'] Note: none
```python n=int(input()) l=[] for i in range(n): l.append(int(input())) a=set(l) if(len(a)==1): print("Exemplary pages.") else: m=min(l) n=max(l) r=(n-m)//2 q=l.index(n) w=l.index(m) l[q]-=r l[w]+=r b=set(l) if(len(b)==1): print(str(r)+" ml. from cup #"+str(w+1)+" to cup #"+str(q+1)+".") else: print("Unrecoverable configuration.") ```
3
282
A
Bit++
PROGRAMMING
800
[ "implementation" ]
null
null
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
Print a single integer — the final value of *x*.
[ "1\n++X\n", "2\nX++\n--X\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "1\n++X", "output": "1" }, { "input": "2\nX++\n--X", "output": "0" }, { "input": "3\n++X\n++X\n++X", "output": "3" }, { "input": "2\n--X\n--X", "output": "-2" }, { "input": "5\n++X\n--X\n++X\n--X\n--X", "output": "-1" }, { "input": "28\nX--\n++X\nX++\nX++\nX++\n--X\n--X\nX++\nX--\n++X\nX++\n--X\nX--\nX++\nX--\n++X\n++X\nX++\nX++\nX++\nX++\n--X\n++X\n--X\n--X\n--X\n--X\nX++", "output": "4" }, { "input": "94\nX++\nX++\n++X\n++X\nX--\n--X\nX++\n--X\nX++\n++X\nX++\n++X\n--X\n--X\n++X\nX++\n--X\nX--\nX--\n--X\nX--\nX--\n--X\n++X\n--X\nX--\nX--\nX++\n++X\n--X\nX--\n++X\n--X\n--X\nX--\nX--\nX++\nX++\nX--\nX++\nX--\nX--\nX--\n--X\nX--\nX--\nX--\nX++\n++X\nX--\n++X\nX++\n--X\n--X\n--X\n--X\n++X\nX--\n--X\n--X\n++X\nX--\nX--\nX++\n++X\nX++\n++X\n--X\n--X\nX--\n++X\nX--\nX--\n++X\n++X\n++X\n++X\nX++\n++X\n--X\nX++\n--X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\nX--\nX--\n--X\n++X\nX++", "output": "-10" }, { "input": "56\n--X\nX--\n--X\n--X\nX--\nX--\n--X\nX++\n++X\n--X\nX++\nX--\n--X\n++X\n--X\nX--\nX--\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\n++X\nX++\nX++\n--X\nX++\nX--\n--X\nX--\n--X\nX++\n++X\n--X\n++X\nX++\nX--\n--X\n--X\n++X\nX--\nX--\n--X\nX--\n--X\nX++\n--X\n++X\n--X", "output": "-14" }, { "input": "59\nX--\n--X\nX++\n++X\nX--\n--X\n--X\n++X\n++X\n++X\n++X\nX++\n++X\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX++\n--X\n++X\nX++\n--X\n--X\nX++\nX++\n--X\nX++\nX++\nX++\nX--\nX--\n--X\nX++\nX--\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\nX--\n++X\n--X\nX++\nX++\nX--\nX++\n++X\nX--\nX++\nX--\nX--\n++X", "output": "3" }, { "input": "87\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\nX--\n++X\n--X\n--X\nX++\n--X\nX--\nX++\n++X\n--X\n++X\n++X\n--X\n++X\n--X\nX--\n++X\n++X\nX--\nX++\nX++\n--X\n--X\n++X\nX--\n--X\n++X\n--X\nX++\n--X\n--X\nX--\n++X\n++X\n--X\nX--\nX--\nX--\nX--\nX--\nX++\n--X\n++X\n--X\nX++\n++X\nX++\n++X\n--X\nX++\n++X\nX--\n--X\nX++\n++X\nX++\nX++\n--X\n--X\n++X\n--X\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX--\n--X\n++X\n++X", "output": "-5" }, { "input": "101\nX++\nX++\nX++\n++X\n--X\nX--\nX++\nX--\nX--\n--X\n--X\n++X\nX++\n++X\n++X\nX--\n--X\n++X\nX++\nX--\n++X\n--X\n--X\n--X\n++X\n--X\n++X\nX++\nX++\n++X\n--X\nX++\nX--\nX++\n++X\n++X\nX--\nX--\nX--\nX++\nX++\nX--\nX--\nX++\n++X\n++X\n++X\n--X\n--X\n++X\nX--\nX--\n--X\n++X\nX--\n++X\nX++\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n++X\n--X\nX++\n++X\nX--\n++X\nX--\n++X\nX++\nX--\n++X\nX++\n--X\nX++\nX++\n++X\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\n++X\n++X\n--X\nX--\nX--\nX--\nX--\n--X\n--X\n--X\n++X\n--X\n--X", "output": "1" }, { "input": "63\n--X\nX--\n++X\n--X\n++X\nX++\n--X\n--X\nX++\n--X\n--X\nX++\nX--\nX--\n--X\n++X\nX--\nX--\nX++\n++X\nX++\nX++\n--X\n--X\n++X\nX--\nX--\nX--\n++X\nX++\nX--\n--X\nX--\n++X\n++X\nX++\n++X\nX++\nX++\n--X\nX--\n++X\nX--\n--X\nX--\nX--\nX--\n++X\n++X\n++X\n++X\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n++X\nX--\n++X\n++X\nX--", "output": "1" }, { "input": "45\n--X\n++X\nX--\n++X\n++X\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX++\n++X\nX--\n++X\n++X\nX--\nX++\nX--\n--X\nX--\n++X\n++X\n--X\n--X\nX--\nX--\n--X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\nX--\n++X\n++X\nX++\nX++\n++X\n++X\nX++", "output": "-3" }, { "input": "21\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX--\nX++\nX--\nX--\nX--\nX++\n++X\nX++\n++X\n--X\nX--\n--X\nX++\n++X", "output": "1" }, { "input": "100\n--X\n++X\nX++\n++X\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\n++X\nX--\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n++X\nX++\n++X\nX--\n--X\n++X\nX--\n--X\n++X\n++X\nX--\nX++\nX++\nX++\n++X\n--X\n++X\nX++\nX--\n++X\n++X\n--X\n++X\nX--\nX--\nX--\nX++\nX--\nX--\nX++\nX++\n--X\nX++\nX++\n--X\nX--\n--X\n++X\n--X\n++X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\n++X\nX++\nX--\nX++\nX--\nX++\nX++\n--X\nX--\nX--\n++X\nX--\n--X\n--X\nX++\n--X\n--X\nX--\nX--\n++X\n++X\nX--\n++X\nX++\n--X\n++X\n++X\nX++\n--X\n--X\nX++", "output": "8" }, { "input": "17\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n--X\nX--\nX++\nX--\n--X\n--X\nX--\n++X\nX--\nX++", "output": "-1" }, { "input": "77\n++X\nX++\n--X\nX--\n--X\n--X\nX--\nX++\nX--\nX++\nX--\n++X\n--X\n--X\n--X\n--X\n++X\nX--\nX++\nX--\n--X\nX--\n--X\nX--\n++X\n--X\n++X\n++X\nX++\nX++\nX--\n--X\nX--\nX--\nX++\n--X\n--X\n++X\nX--\nX--\n++X\nX++\nX--\n++X\n--X\nX++\nX--\n++X\n++X\n++X\nX--\nX--\nX--\n--X\n++X\n++X\n++X\nX++\n--X\n--X\n++X\n--X\nX--\nX++\n++X\nX++\n++X\nX--\nX++\nX++\n--X\nX++\nX++\nX++\n--X\nX++\nX--", "output": "-5" }, { "input": "21\nX--\n++X\n--X\nX--\n++X\nX--\n++X\nX--\n--X\n++X\nX++\n++X\nX++\n++X\nX--\n--X\nX++\nX++\nX--\n++X\nX--", "output": "1" }, { "input": "1\nX--", "output": "-1" } ]
1,696,587,239
2,147,483,647
PyPy 3-64
OK
TESTS
36
77
0
a = int(input()) d = [] for i in range(a): n = input() d.append(n) k = 0 for j in d: if "++" in j: k+=1 else: k-=1 print(k)
Title: Bit++ Time Limit: None seconds Memory Limit: None megabytes Problem Description: The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed). Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order. Output Specification: Print a single integer — the final value of *x*. Demo Input: ['1\n++X\n', '2\nX++\n--X\n'] Demo Output: ['1\n', '0\n'] Note: none
```python a = int(input()) d = [] for i in range(a): n = input() d.append(n) k = 0 for j in d: if "++" in j: k+=1 else: k-=1 print(k) ```
3
343
B
Alternating Current
PROGRAMMING
1,600
[ "data structures", "greedy", "implementation" ]
null
null
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples.
The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.
Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled.
[ "-++-\n", "+-\n", "++\n", "-\n" ]
[ "Yes\n", "No\n", "Yes\n", "No\n" ]
The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:
1,000
[ { "input": "-++-", "output": "Yes" }, { "input": "+-", "output": "No" }, { "input": "++", "output": "Yes" }, { "input": "-", "output": "No" }, { "input": "+-+-", "output": "No" }, { "input": "-+-", "output": "No" }, { "input": "-++-+--+", "output": "Yes" }, { "input": "+", "output": "No" }, { "input": "-+", "output": "No" }, { "input": "--", "output": "Yes" }, { "input": "+++", "output": "No" }, { "input": "--+", "output": "No" }, { "input": "++--++", "output": "Yes" }, { "input": "+-++-+", "output": "Yes" }, { "input": "+-+--+", "output": "No" }, { "input": "--++-+", "output": "No" }, { "input": "-+-+--", "output": "No" }, { "input": "+-+++-", "output": "No" }, { "input": "-+-+-+", "output": "No" }, { "input": "-++-+--++--+-++-", "output": "Yes" }, { "input": "+-----+-++---+------+++-++++", "output": "No" }, { "input": "-+-++--+++-++++---+--+----+--+-+-+++-+++-+---++-++++-+--+--+--+-+-++-+-+-++++++---++--+++++-+--++--+-+--++-----+--+-++---+++---++----+++-++++--++-++-", "output": "No" }, { "input": "-+-----++++--++-+-++", "output": "Yes" }, { "input": "+--+--+------+++++++-+-+++--++---+--+-+---+--+++-+++-------+++++-+-++++--+-+-+++++++----+----+++----+-+++-+++-----+++-+-++-+-+++++-+--++----+--+-++-----+-+-++++---+++---+-+-+-++++--+--+++---+++++-+---+-----+++-++--+++---++-++-+-+++-+-+-+---+++--+--++++-+-+--++-------+--+---++-----+++--+-+++--++-+-+++-++--+++-++++++++++-++-++++++-+++--+--++-+++--+++-++++----+++---+-+----++++-+-+", "output": "Yes" }, { "input": "-+-+-++-+-+-", "output": "Yes" }, { "input": "-+-++-+-", "output": "Yes" }, { "input": "-+-++-+-+-", "output": "No" }, { "input": "++-+-+-+-+--+", "output": "No" }, { "input": "+++---", "output": "No" }, { "input": "+-+-+-+-+--+-+-+-+-++--++--+", "output": "Yes" }, { "input": "+-+-++", "output": "No" }, { "input": "-++--+--+++-+-+-+-+-", "output": "No" }, { "input": "+---+-+-", "output": "No" }, { "input": "+-+--+-+", "output": "Yes" }, { "input": "+++---+++---", "output": "No" }, { "input": "-+++++", "output": "No" }, { "input": "-+-+-+-+-+-+-++-+-+-+-+-+-+-", "output": "Yes" }, { "input": "-+++--", "output": "No" }, { "input": "+---+", "output": "No" }, { "input": "-++", "output": "No" }, { "input": "-+--+-", "output": "Yes" }, { "input": "+---++--++", "output": "No" }, { "input": "+++-", "output": "No" }, { "input": "--+++", "output": "No" }, { "input": "++-+", "output": "No" } ]
1,694,751,706
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
#include <iostream> #include <stack> #include <string> using namespace std; #define ll long long #define llu unsigned long long #define lld long double #define endl "\n" #define ENDL "\n" #define SYSTEM_ON ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define SYSTEM_OFF return (0); int main(void) { SYSTEM_ON string str; stack <char> sign; int i; cin >> str; for (i = 0; i < str.size(); i++) { if (sign.empty()) sign.push(str[i]); else { if (str[i] == sign.top()) sign.pop(); else sign.push(str[i]); } } if (sign.empty()) cout << "Yes" << endl; else cout << "No" << endl; SYSTEM_OFF }
Title: Alternating Current Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again. The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut. To understand the problem better please read the notes to the test samples. Input Specification: The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. Output Specification: Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. Demo Input: ['-++-\n', '+-\n', '++\n', '-\n'] Demo Output: ['Yes\n', 'No\n', 'Yes\n', 'No\n'] Note: The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses. In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:
```python #include <iostream> #include <stack> #include <string> using namespace std; #define ll long long #define llu unsigned long long #define lld long double #define endl "\n" #define ENDL "\n" #define SYSTEM_ON ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define SYSTEM_OFF return (0); int main(void) { SYSTEM_ON string str; stack <char> sign; int i; cin >> str; for (i = 0; i < str.size(); i++) { if (sign.empty()) sign.push(str[i]); else { if (str[i] == sign.top()) sign.pop(); else sign.push(str[i]); } } if (sign.empty()) cout << "Yes" << endl; else cout << "No" << endl; SYSTEM_OFF } ```
-1
443
A
Anton and Letters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Print a single number — the number of distinct letters in Anton's set.
[ "{a, b, c}\n", "{b, a, b, a}\n", "{}\n" ]
[ "3\n", "2\n", "0\n" ]
none
500
[ { "input": "{a, b, c}", "output": "3" }, { "input": "{b, a, b, a}", "output": "2" }, { "input": "{}", "output": "0" }, { "input": "{a, a, c, b, b, b, c, c, c, c}", "output": "3" }, { "input": "{a, c, b, b}", "output": "3" }, { "input": "{a, b}", "output": "2" }, { "input": "{a}", "output": "1" }, { "input": "{b, a, b, a, b, c, c, b, c, b}", "output": "3" }, { "input": "{e, g, c, e}", "output": "3" }, { "input": "{a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a}", "output": "1" }, { "input": "{a, a, b}", "output": "2" }, { "input": "{a, b, b, b, a, b, a, a, a, a, a, a, b, a, b, a, a, a, a, a, b, a, b, a}", "output": "2" }, { "input": "{j, u, a, c, f, w, e, w, x, t, h, p, v, n, i, l, x, n, i, b, u, c, a, a}", "output": "16" }, { "input": "{x, i, w, c, p, e, h, z, k, i}", "output": "9" }, { "input": "{t, k, o, x, r, d, q, j, k, e, z, w, y, r, z, s, s, e, s, b, k, i}", "output": "15" }, { "input": "{y}", "output": "1" }, { "input": "{x}", "output": "1" }, { "input": "{b, z, a, z}", "output": "3" }, { "input": "{z}", "output": "1" }, { "input": "{a, z}", "output": "2" }, { "input": "{a, b, z}", "output": "3" }, { "input": "{s, q, z, r, t, a, b, h, j, i, o, z, r, q}", "output": "11" } ]
1,697,435,251
2,147,483,647
PyPy 3-64
OK
TESTS
27
62
0
s = input() l = [] p = [] for i in range(len(s)): if s[i].isalpha(): l.append(s[i]) for q in range(len(l)): if l[q] not in p: p.append(l[q]) print(len(p))
Title: Anton and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set. Input Specification: The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. Output Specification: Print a single number — the number of distinct letters in Anton's set. Demo Input: ['{a, b, c}\n', '{b, a, b, a}\n', '{}\n'] Demo Output: ['3\n', '2\n', '0\n'] Note: none
```python s = input() l = [] p = [] for i in range(len(s)): if s[i].isalpha(): l.append(s[i]) for q in range(len(l)): if l[q] not in p: p.append(l[q]) print(len(p)) ```
3
5
C
Longest Regular Bracket Sequence
PROGRAMMING
1,900
[ "constructive algorithms", "data structures", "dp", "greedy", "sortings", "strings" ]
C. Longest Regular Bracket Sequence
2
256
This is yet another problem dealing with regular bracket sequences. We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. You are given a string of «(» and «)» characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well.
The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106.
Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1".
[ ")((())))(()())\n", "))(\n" ]
[ "6 2\n", "0 1\n" ]
none
0
[ { "input": ")((())))(()())", "output": "6 2" }, { "input": "))(", "output": "0 1" }, { "input": "()(())()", "output": "8 1" }, { "input": "((((()(((", "output": "2 1" }, { "input": "))))()())))", "output": "4 1" }, { "input": "(()())()(())()()())())()((()(()(())()()())((()(())()(()()()()))()(())()(((()())()(()((())()(())(()))", "output": "28 1" }, { "input": ")(()(((((())))))(((()))))))((()(((((((())())()))))((((((((())))((((((())))))(()((((()))))(()))))))))", "output": "68 1" }, { "input": "())(((((())())((((()))(())))())())(((()(()()()())(())()))((()(())())()()))()(()())))))(()))((())((((", "output": "80 1" }, { "input": "))(((((((()((((())(((((((((()()))))(()())()((())())))((((()))(()()()))))(()()))())))))((())())()))((", "output": "92 1" } ]
1,532,072,574
2,147,483,647
Python 3
OK
TESTS
43
1,496
26,931,200
# @author: guoyc # @date: 2018/7/20 s = input() N = len(s) # dp = [0] * (N + 1) # # ml = 0 # cnt = 1 # # for i in range(1, N): # if s[i] == '(': # continue # if s[i - 1] == '(': # dp[i] = 2 + dp[i - 2] # elif (i - 1) - dp[i - 1] >= 0: # if s[(i - 1) - dp[i - 1]] == '(': # dp[i] = dp[i - 1] + 2 + dp[(i - 1) - dp[i - 1] - 1] # if dp[i] > ml: # ml = dp[i] # cnt = 1 # elif dp[i] == ml: # cnt += 1 # # if ml == 0: # print(0, 1) # else: # print(ml, cnt) st = [-1] ml, cnt = 0, 1 for i, c in enumerate(s): if c == '(': st.append(i) else: if len(st) > 1: st.pop(-1) ll = i - st[-1] if ll > ml: ml, cnt = ll, 1 elif ll == ml: cnt += 1 else: st[0] = i print(ml, cnt)
Title: Longest Regular Bracket Sequence Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: This is yet another problem dealing with regular bracket sequences. We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. You are given a string of «(» and «)» characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well. Input Specification: The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106. Output Specification: Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1". Demo Input: [')((())))(()())\n', '))(\n'] Demo Output: ['6 2\n', '0 1\n'] Note: none
```python # @author: guoyc # @date: 2018/7/20 s = input() N = len(s) # dp = [0] * (N + 1) # # ml = 0 # cnt = 1 # # for i in range(1, N): # if s[i] == '(': # continue # if s[i - 1] == '(': # dp[i] = 2 + dp[i - 2] # elif (i - 1) - dp[i - 1] >= 0: # if s[(i - 1) - dp[i - 1]] == '(': # dp[i] = dp[i - 1] + 2 + dp[(i - 1) - dp[i - 1] - 1] # if dp[i] > ml: # ml = dp[i] # cnt = 1 # elif dp[i] == ml: # cnt += 1 # # if ml == 0: # print(0, 1) # else: # print(ml, cnt) st = [-1] ml, cnt = 0, 1 for i, c in enumerate(s): if c == '(': st.append(i) else: if len(st) > 1: st.pop(-1) ll = i - st[-1] if ll > ml: ml, cnt = ll, 1 elif ll == ml: cnt += 1 else: st[0] = i print(ml, cnt) ```
3.575837
999
C
Alphabetic Removals
PROGRAMMING
1,200
[ "implementation" ]
null
null
You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: - if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - ... - remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly $k$ times, thus removing exactly $k$ characters. Help Polycarp find the resulting string.
The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove. The second line contains the string $s$ consisting of $n$ lowercase Latin letters.
Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break).
[ "15 3\ncccaabababaccbc\n", "15 9\ncccaabababaccbc\n", "1 1\nu\n" ]
[ "cccbbabaccbc\n", "cccccc\n", "" ]
none
0
[ { "input": "15 3\ncccaabababaccbc", "output": "cccbbabaccbc" }, { "input": "15 9\ncccaabababaccbc", "output": "cccccc" }, { "input": "5 2\nzyzyx", "output": "zzy" }, { "input": "4 3\nhack", "output": "k" }, { "input": "4 3\nzzzz", "output": "z" }, { "input": "6 5\naaccdd", "output": "d" }, { "input": "2 1\nzz", "output": "z" }, { "input": "14 5\nhxehmvkybeklnj", "output": "xmvkyklnj" } ]
1,635,436,770
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
2,000
11,571,200
n,k=map(int,input().split()) s=list(input()) for i in range(k): b=sorted(s) s.pop(s.index(b[0])) print(''.join(s))
Title: Alphabetic Removals Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: - if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - ... - remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly $k$ times, thus removing exactly $k$ characters. Help Polycarp find the resulting string. Input Specification: The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove. The second line contains the string $s$ consisting of $n$ lowercase Latin letters. Output Specification: Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). Demo Input: ['15 3\ncccaabababaccbc\n', '15 9\ncccaabababaccbc\n', '1 1\nu\n'] Demo Output: ['cccbbabaccbc\n', 'cccccc\n', ''] Note: none
```python n,k=map(int,input().split()) s=list(input()) for i in range(k): b=sorted(s) s.pop(s.index(b[0])) print(''.join(s)) ```
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,597,363,160
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
1,000
1,740,800
import math a, b = map(float, input().split()) first_numbers = math.factorial(b) second_number = math.factorial(a) result = (first_numbers / second_number) % 10 print(int(result))
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 import math a, b = map(float, input().split()) first_numbers = math.factorial(b) second_number = math.factorial(a) result = (first_numbers / second_number) % 10 print(int(result)) ```
0
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,135,536
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
13,516,800
# LUOGU_RID: 131353811 a,b=map(int,input().split());c=input().split();d=[0]*a;e={} for i in range(a):e[c[i]]=i for i in e: for j in range(e[i]+1):d[j]+=1 for i in range(b):print(d[int(input())-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 # LUOGU_RID: 131353811 a,b=map(int,input().split());c=input().split();d=[0]*a;e={} for i in range(a):e[c[i]]=i for i in e: for j in range(e[i]+1):d[j]+=1 for i in range(b):print(d[int(input())-1]) ```
0
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,693,470,024
2,147,483,647
Python 3
OK
TESTS
48
46
0
str_input = input() data_list = str_input.split() x_list = [] for data in data_list: x_list.append(int(data)) x_list.sort() min_x = min(x_list) for i in range(0, len(x_list)): x_list[i] -= min_x max_x = max(x_list) distance_list = [] for x in range(0, max_x + 1): distance = abs(x_list[0] - x) + abs(x_list[1] - x) + abs(x_list[2] - x) distance_list.append(distance) print(min(distance_list))
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 str_input = input() data_list = str_input.split() x_list = [] for data in data_list: x_list.append(int(data)) x_list.sort() min_x = min(x_list) for i in range(0, len(x_list)): x_list[i] -= min_x max_x = max(x_list) distance_list = [] for x in range(0, max_x + 1): distance = abs(x_list[0] - x) + abs(x_list[1] - x) + abs(x_list[2] - x) distance_list.append(distance) print(min(distance_list)) ```
3
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,525,525,304
704
Python 3
WRONG_ANSWER
TESTS
4
78
7,065,600
R = lambda: map(int, input().split()) k, n, s, p = R() num=0 num=int((((n-1)/s+1)*k-1)/p+1) print(num)
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 R = lambda: map(int, input().split()) k, n, s, p = R() num=0 num=int((((n-1)/s+1)*k-1)/p+1) print(num) ```
0
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions.
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "output": "5" }, { "input": "2 6", "output": "6" }, { "input": "2 7", "output": "7" }, { "input": "2 14", "output": "14" }, { "input": "2 15", "output": "15" }, { "input": "1 4", "output": "2" }, { "input": "2 16", "output": "16" }, { "input": "3 5", "output": "7" }, { "input": "3 6", "output": "9" }, { "input": "3 10", "output": "15" }, { "input": "3 14", "output": "21" }, { "input": "3 15", "output": "22" }, { "input": "3 16", "output": "24" }, { "input": "5 7", "output": "17" }, { "input": "16 16", "output": "128" }, { "input": "15 16", "output": "120" }, { "input": "2 3", "output": "3" }, { "input": "15 15", "output": "112" }, { "input": "14 16", "output": "112" }, { "input": "11 13", "output": "71" }, { "input": "5 16", "output": "40" }, { "input": "8 15", "output": "60" }, { "input": "2 2", "output": "2" }, { "input": "3 4", "output": "6" }, { "input": "4 4", "output": "8" }, { "input": "1 1", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "14 15", "output": "105" } ]
1,633,336,987
2,147,483,647
Python 3
OK
TESTS
35
124
6,758,400
#a,b=map(int,input().split()) #print(a*b//2) from math import * print(round(exp(sum(map(lambda x:log(int(x)),input().split()))))//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 #a,b=map(int,input().split()) #print(a*b//2) from math import * print(round(exp(sum(map(lambda x:log(int(x)),input().split()))))//2) ```
3.956411
485
A
Factory
PROGRAMMING
1,400
[ "implementation", "math", "matrices" ]
null
null
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory. The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by *m*). Given the number of details *a* on the first day and number *m* check if the production stops at some moment.
The first line contains two integers *a* and *m* (1<=≤<=*a*,<=*m*<=≤<=105).
Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
[ "1 5\n", "3 6\n" ]
[ "No\n", "Yes\n" ]
none
1,000
[ { "input": "1 5", "output": "No" }, { "input": "3 6", "output": "Yes" }, { "input": "1 8", "output": "Yes" }, { "input": "2 3", "output": "No" }, { "input": "3 24", "output": "Yes" }, { "input": "1 1", "output": "Yes" }, { "input": "100000 100000", "output": "Yes" }, { "input": "1 99989", "output": "No" }, { "input": "512 2", "output": "Yes" }, { "input": "100 24", "output": "No" }, { "input": "1 100000", "output": "No" }, { "input": "100000 1", "output": "Yes" }, { "input": "3 99929", "output": "No" }, { "input": "99961 99971", "output": "No" }, { "input": "1 65536", "output": "Yes" }, { "input": "4 65536", "output": "Yes" }, { "input": "3 65536", "output": "Yes" }, { "input": "32768 65536", "output": "Yes" }, { "input": "65535 65536", "output": "Yes" }, { "input": "1 65535", "output": "No" }, { "input": "98812 100000", "output": "No" }, { "input": "10 5", "output": "Yes" }, { "input": "6 8", "output": "Yes" } ]
1,638,222,764
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
a = list(map(int, input().split())) mat = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536] done = 0 if a[1] % 2 != 0: print('No') done = 1 b = [a[0] % a[1]] c = a[0] % a[1] while 1 and done == 0: while c < a[1]: c *= 2 if c % a[1] in b and c % a[1] != 0: print('No') break break elif c % a[1] == 0: print('Yes') break break b.append(c % a[1])
Title: Factory Time Limit: None seconds Memory Limit: None megabytes Problem Description: One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory. The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by *m*). Given the number of details *a* on the first day and number *m* check if the production stops at some moment. Input Specification: The first line contains two integers *a* and *m* (1<=≤<=*a*,<=*m*<=≤<=105). Output Specification: Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No". Demo Input: ['1 5\n', '3 6\n'] Demo Output: ['No\n', 'Yes\n'] Note: none
```python a = list(map(int, input().split())) mat = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536] done = 0 if a[1] % 2 != 0: print('No') done = 1 b = [a[0] % a[1]] c = a[0] % a[1] while 1 and done == 0: while c < a[1]: c *= 2 if c % a[1] in b and c % a[1] != 0: print('No') break break elif c % a[1] == 0: print('Yes') break break b.append(c % a[1]) ```
0
588
B
Duff in Love
PROGRAMMING
1,300
[ "math" ]
null
null
Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=&gt;<=1 such that *a*2 is a divisor of *x*. Malek has a number store! In his store, he has only divisors of positive integer *n* (and he has all of them). As a birthday present, Malek wants to give her a lovely number from his store. He wants this number to be as big as possible. Malek always had issues in math, so he asked for your help. Please tell him what is the biggest lovely number in his store.
The first and only line of input contains one integer, *n* (1<=≤<=*n*<=≤<=1012).
Print the answer in one line.
[ "10\n", "12\n" ]
[ "10\n", "6\n" ]
In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely. In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 2<sup class="upper-index">2</sup>, so 12 is not lovely, while 6 is indeed lovely.
1,000
[ { "input": "10", "output": "10" }, { "input": "12", "output": "6" }, { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "4", "output": "2" }, { "input": "8", "output": "2" }, { "input": "3", "output": "3" }, { "input": "31", "output": "31" }, { "input": "97", "output": "97" }, { "input": "1000000000000", "output": "10" }, { "input": "15", "output": "15" }, { "input": "894", "output": "894" }, { "input": "271", "output": "271" }, { "input": "2457", "output": "273" }, { "input": "2829", "output": "2829" }, { "input": "5000", "output": "10" }, { "input": "20", "output": "10" }, { "input": "68", "output": "34" }, { "input": "3096", "output": "258" }, { "input": "1024", "output": "2" }, { "input": "1048576", "output": "2" }, { "input": "413933789280", "output": "25870861830" }, { "input": "817634153013", "output": "817634153013" }, { "input": "56517269141", "output": "56517269141" }, { "input": "30707328551", "output": "30707328551" }, { "input": "279564127218", "output": "10354226934" }, { "input": "491159577042", "output": "18191095446" }, { "input": "734337660466", "output": "734337660466" }, { "input": "808453785117", "output": "808453785117" }, { "input": "55926835837", "output": "55926835837" }, { "input": "294809951965", "output": "294809951965" }, { "input": "537988035389", "output": "76855433627" }, { "input": "822722434952", "output": "205680608738" }, { "input": "699511759613", "output": "699511759613" }, { "input": "942689843037", "output": "104743315893" }, { "input": "663634158717", "output": "663634158717" }, { "input": "213612977250", "output": "11730" }, { "input": "999999999989", "output": "999999999989" }, { "input": "999999999988", "output": "499999999994" }, { "input": "87178291200", "output": "30030" }, { "input": "927668721948", "output": "463834360974" }, { "input": "562436815639", "output": "37927" }, { "input": "302981118597", "output": "35853" }, { "input": "5", "output": "5" }, { "input": "9", "output": "3" }, { "input": "36", "output": "6" }, { "input": "2231", "output": "2231" }, { "input": "27648", "output": "6" }, { "input": "40320", "output": "210" }, { "input": "648000", "output": "30" }, { "input": "999966000289", "output": "999983" }, { "input": "999985999949", "output": "999985999949" }, { "input": "991921850317", "output": "9973" } ]
1,623,910,356
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
9
124
1,331,200
n = int(input()) def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] Q = make_divisors(n) import math Q.reverse() for i in range(len(Q)): for j in range(2,10000000000): if Q[i] % j **2 == 0: break else: print(Q[i]) exit() if j**2 > Q[i]: break
Title: Duff in Love Time Limit: None seconds Memory Limit: None megabytes Problem Description: Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=&gt;<=1 such that *a*2 is a divisor of *x*. Malek has a number store! In his store, he has only divisors of positive integer *n* (and he has all of them). As a birthday present, Malek wants to give her a lovely number from his store. He wants this number to be as big as possible. Malek always had issues in math, so he asked for your help. Please tell him what is the biggest lovely number in his store. Input Specification: The first and only line of input contains one integer, *n* (1<=≤<=*n*<=≤<=1012). Output Specification: Print the answer in one line. Demo Input: ['10\n', '12\n'] Demo Output: ['10\n', '6\n'] Note: In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely. In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 2<sup class="upper-index">2</sup>, so 12 is not lovely, while 6 is indeed lovely.
```python n = int(input()) def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] Q = make_divisors(n) import math Q.reverse() for i in range(len(Q)): for j in range(2,10000000000): if Q[i] % j **2 == 0: break else: print(Q[i]) exit() if j**2 > Q[i]: break ```
0
0
none
none
none
0
[ "none" ]
null
null
Карта звёздного неба представляет собой прямоугольное поле, состоящее из *n* строк по *m* символов в каждой строке. Каждый символ — это либо «.» (означает пустой участок неба), либо «*» (означает то, что в этом месте на небе есть звезда). Новое издание карты звёздного неба будет напечатано на квадратных листах, поэтому требуется найти минимально возможную сторону квадрата, в который могут поместиться все звезды. Границы искомого квадрата должны быть параллельны сторонам заданного прямоугольного поля.
В первой строке входных данных записаны два числа *n* и *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — количество строк и столбцов на карте звездного неба. В следующих *n* строках задано по *m* символов. Каждый символ — это либо «.» (пустой участок неба), либо «*» (звезда). Гарантируется, что на небе есть хотя бы одна звезда.
Выведите одно число — минимально возможную сторону квадрата, которым можно накрыть все звезды.
[ "4 4\n....\n..*.\n...*\n..**\n", "1 3\n*.*\n", "2 1\n.\n*\n" ]
[ "3\n", "3\n", "1\n" ]
Один из возможных ответов на первый тестовый пример: Один из возможных ответов на второй тестовый пример (обратите внимание, что покрывающий квадрат выходит за пределы карты звездного неба): Ответ на третий тестовый пример:
0
[ { "input": "4 4\n....\n..*.\n...*\n..**", "output": "3" }, { "input": "1 3\n*.*", "output": "3" }, { "input": "2 1\n.\n*", "output": "1" }, { "input": "1 1\n*", "output": "1" }, { "input": "1 2\n.*", "output": "1" }, { "input": "1 2\n*.", "output": "1" }, { "input": "1 2\n**", "output": "2" }, { "input": "2 1\n.\n*", "output": "1" }, { "input": "2 1\n*\n.", "output": "1" }, { "input": "2 1\n*\n*", "output": "2" }, { "input": "5 3\n..*\n.**\n..*\n...\n..*", "output": "5" }, { "input": "1 1\n*", "output": "1" }, { "input": "1 2\n*.", "output": "1" }, { "input": "1 2\n**", "output": "2" }, { "input": "1 3\n.**", "output": "2" }, { "input": "1 3\n*.*", "output": "3" }, { "input": "1 4\n..**", "output": "2" }, { "input": "1 4\n*..*", "output": "4" }, { "input": "1 5\n.*.**", "output": "4" }, { "input": "1 5\n.*..*", "output": "4" }, { "input": "2 1\n*\n.", "output": "1" }, { "input": "2 1\n*\n*", "output": "2" }, { "input": "2 2\n.*\n..", "output": "1" }, { "input": "2 2\n*.\n.*", "output": "2" }, { "input": "2 3\n*..\n**.", "output": "2" }, { "input": "2 3\n*..\n..*", "output": "3" }, { "input": "2 4\n.***\n.*.*", "output": "3" }, { "input": "2 5\n*..**\n.*.*.", "output": "5" }, { "input": "2 5\n.....\n*.*..", "output": "3" }, { "input": "3 1\n*\n*\n*", "output": "3" }, { "input": "3 1\n*\n.\n*", "output": "3" }, { "input": "3 2\n..\n..\n**", "output": "2" }, { "input": "3 2\n.*\n.*\n..", "output": "2" }, { "input": "3 3\n*..\n.**\n***", "output": "3" }, { "input": "3 4\n..*.\n....\n..*.", "output": "3" }, { "input": "3 5\n.....\n.*...\n..*..", "output": "2" }, { "input": "4 1\n.\n.\n*\n*", "output": "2" }, { "input": "4 1\n*\n.\n*\n.", "output": "3" }, { "input": "4 2\n*.\n*.\n.*\n**", "output": "4" }, { "input": "4 2\n*.\n..\n..\n.*", "output": "4" }, { "input": "4 3\n..*\n...\n...\n*..", "output": "4" }, { "input": "4 4\n..*.\n..*.\n.*..\n***.", "output": "4" }, { "input": "4 4\n....\n...*\n....\n..*.", "output": "3" }, { "input": "5 1\n*\n*\n.\n.\n.", "output": "2" }, { "input": "5 1\n*\n.\n.\n.\n*", "output": "5" }, { "input": "5 2\n.*\n**\n**\n..\n**", "output": "5" }, { "input": "5 2\n*.\n..\n..\n..\n.*", "output": "5" }, { "input": "5 3\n...\n***\n..*\n.**\n**.", "output": "4" }, { "input": "5 3\n*..\n...\n...\n...\n.*.", "output": "5" }, { "input": "5 4\n*.**\n.*..\n.*..\n..*.\n*..*", "output": "5" }, { "input": "5 4\n....\n..*.\n....\n....\n..*.", "output": "4" }, { "input": "5 5\n....*\n....*\n....*\n..*..\n..*.*", "output": "5" }, { "input": "2 2\n**\n**", "output": "2" }, { "input": "2 2\n*.\n.*", "output": "2" }, { "input": "2 2\n.*\n*.", "output": "2" }, { "input": "2 2\n**\n..", "output": "2" }, { "input": "2 2\n..\n**", "output": "2" }, { "input": "2 2\n*.\n*.", "output": "2" }, { "input": "2 2\n.*\n.*", "output": "2" }, { "input": "2 2\n*.\n..", "output": "1" }, { "input": "2 2\n.*\n..", "output": "1" }, { "input": "2 2\n..\n*.", "output": "1" }, { "input": "2 2\n..\n.*", "output": "1" }, { "input": "2 2\n.*\n**", "output": "2" }, { "input": "2 2\n*.\n**", "output": "2" }, { "input": "2 2\n**\n.*", "output": "2" }, { "input": "2 2\n**\n*.", "output": "2" } ]
1,458,969,191
169,991
Python 3
WRONG_ANSWER
PRETESTS
3
61
4,608,000
def squareSide(): n, m = [int(_) for _ in input().strip().split(" ")] starMap = [] for _ in range(n): starMap.append(input()) def verticalMax(): up = 0 down = 0 for x in range(len(starMap)): if "*" in starMap[x]: up = x+1 break for x in range(-len(starMap), 1): if "*" in starMap[x]: down = -x+1 break return down-up+1 def horizontalMax(): hMax = [] for x in range(len(starMap)): i = starMap[x].find("*")+1 j = starMap[x].rfind("*")+1 hMax.append(j-i+1) return max(hMax) return max(verticalMax(), horizontalMax()) print(squareSide())
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Карта звёздного неба представляет собой прямоугольное поле, состоящее из *n* строк по *m* символов в каждой строке. Каждый символ — это либо «.» (означает пустой участок неба), либо «*» (означает то, что в этом месте на небе есть звезда). Новое издание карты звёздного неба будет напечатано на квадратных листах, поэтому требуется найти минимально возможную сторону квадрата, в который могут поместиться все звезды. Границы искомого квадрата должны быть параллельны сторонам заданного прямоугольного поля. Input Specification: В первой строке входных данных записаны два числа *n* и *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — количество строк и столбцов на карте звездного неба. В следующих *n* строках задано по *m* символов. Каждый символ — это либо «.» (пустой участок неба), либо «*» (звезда). Гарантируется, что на небе есть хотя бы одна звезда. Output Specification: Выведите одно число — минимально возможную сторону квадрата, которым можно накрыть все звезды. Demo Input: ['4 4\n....\n..*.\n...*\n..**\n', '1 3\n*.*\n', '2 1\n.\n*\n'] Demo Output: ['3\n', '3\n', '1\n'] Note: Один из возможных ответов на первый тестовый пример: Один из возможных ответов на второй тестовый пример (обратите внимание, что покрывающий квадрат выходит за пределы карты звездного неба): Ответ на третий тестовый пример:
```python def squareSide(): n, m = [int(_) for _ in input().strip().split(" ")] starMap = [] for _ in range(n): starMap.append(input()) def verticalMax(): up = 0 down = 0 for x in range(len(starMap)): if "*" in starMap[x]: up = x+1 break for x in range(-len(starMap), 1): if "*" in starMap[x]: down = -x+1 break return down-up+1 def horizontalMax(): hMax = [] for x in range(len(starMap)): i = starMap[x].find("*")+1 j = starMap[x].rfind("*")+1 hMax.append(j-i+1) return max(hMax) return max(verticalMax(), horizontalMax()) print(squareSide()) ```
0
628
C
Bear and String Distance
PROGRAMMING
1,300
[ "greedy", "strings" ]
null
null
Limak is a little polar bear. He likes nice strings — strings of length *n*, consisting of lowercase English letters only. The distance between two letters is defined as the difference between their positions in the alphabet. For example, , and . Also, the distance between two nice strings is defined as the sum of distances of corresponding letters. For example, , and . Limak gives you a nice string *s* and an integer *k*. He challenges you to find any nice string *s*' that . Find any *s*' satisfying the given conditions, or print "-1" if it's impossible to do so. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=106). The second line contains a string *s* of length *n*, consisting of lowercase English letters.
If there is no string satisfying the given conditions then print "-1" (without the quotes). Otherwise, print any nice string *s*' that .
[ "4 26\nbear\n", "2 7\naf\n", "3 1000\nhey\n" ]
[ "roar", "db\n", "-1\n" ]
none
0
[ { "input": "4 26\nbear", "output": "zcar" }, { "input": "2 7\naf", "output": "hf" }, { "input": "3 1000\nhey", "output": "-1" }, { "input": "5 50\nkzsij", "output": "zaiij" }, { "input": "5 500\nvsdxg", "output": "-1" }, { "input": "1 0\na", "output": "a" }, { "input": "1 1\ng", "output": "f" }, { "input": "1 25\nr", "output": "-1" }, { "input": "1 15\no", "output": "-1" }, { "input": "10 100\naddaiyssyp", "output": "zzzzcyssyp" }, { "input": "50 100\ntewducenaqgpilgftjcmzttrgebnyldwfgbtttrygaiqtkgbjb", "output": "azazecenaqgpilgftjcmzttrgebnyldwfgbtttrygaiqtkgbjb" }, { "input": "2 1\nzz", "output": "yz" }, { "input": "8 8\nabcdefgh", "output": "ibcdefgh" }, { "input": "1 25\nz", "output": "a" }, { "input": "1 24\nz", "output": "b" }, { "input": "1 24\ny", "output": "a" }, { "input": "2 49\nzz", "output": "ab" }, { "input": "1 26\na", "output": "-1" }, { "input": "1 25\na", "output": "z" }, { "input": "4 17\nrzsq", "output": "azsq" }, { "input": "69 1701\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzy", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaax" }, { "input": "2 9\nbc", "output": "kc" }, { "input": "2 48\nab", "output": "zy" }, { "input": "1 8\nc", "output": "k" }, { "input": "2 25\nyd", "output": "ac" }, { "input": "5 24\nizrqp", "output": "zsrqp" }, { "input": "1 13\nn", "output": "a" }, { "input": "5 21\nfmmqh", "output": "zlmqh" } ]
1,522,014,303
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
7,065,600
[n,k] = input().split(" ") s = input() ss = '' n = int(n) k = int(k) MaxD = [[0,0]]*n SumMaxD = 0 for i in list(range(0,n)): xl = -97 + ord(s[i]) xh = 122 - ord(s[i]) if(xl > xh): if(xl<k): ss =ss + chr(ord(s[i]) - xl) k = k - xl else: ss =ss + chr(ord(s[i]) - k) + s[(i+1):len(s):1] break SumMaxD = SumMaxD + xl else: if(xh<k): ss =ss + chr(ord(s[i]) + xh) k = k - xh else: ss =ss + chr(ord(s[i]) + k) + s[(i+1):len(s):1] break SumMaxD = SumMaxD + xh if(SumMaxD < k): print(-1) else: print(ss)
Title: Bear and String Distance Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. He likes nice strings — strings of length *n*, consisting of lowercase English letters only. The distance between two letters is defined as the difference between their positions in the alphabet. For example, , and . Also, the distance between two nice strings is defined as the sum of distances of corresponding letters. For example, , and . Limak gives you a nice string *s* and an integer *k*. He challenges you to find any nice string *s*' that . Find any *s*' satisfying the given conditions, or print "-1" if it's impossible to do so. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=106). The second line contains a string *s* of length *n*, consisting of lowercase English letters. Output Specification: If there is no string satisfying the given conditions then print "-1" (without the quotes). Otherwise, print any nice string *s*' that . Demo Input: ['4 26\nbear\n', '2 7\naf\n', '3 1000\nhey\n'] Demo Output: ['roar', 'db\n', '-1\n'] Note: none
```python [n,k] = input().split(" ") s = input() ss = '' n = int(n) k = int(k) MaxD = [[0,0]]*n SumMaxD = 0 for i in list(range(0,n)): xl = -97 + ord(s[i]) xh = 122 - ord(s[i]) if(xl > xh): if(xl<k): ss =ss + chr(ord(s[i]) - xl) k = k - xl else: ss =ss + chr(ord(s[i]) - k) + s[(i+1):len(s):1] break SumMaxD = SumMaxD + xl else: if(xh<k): ss =ss + chr(ord(s[i]) + xh) k = k - xh else: ss =ss + chr(ord(s[i]) + k) + s[(i+1):len(s):1] break SumMaxD = SumMaxD + xh if(SumMaxD < k): print(-1) else: print(ss) ```
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,561,562,679
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
186
0
u=0 s=0 word=input() word=list(word) for letter in word: if letter.islower(): s=s+1 else: u=u+1 word=str(word) if u>s: word=word.upper() else: word=word.lower() print(word)
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 u=0 s=0 word=input() word=list(word) for letter in word: if letter.islower(): s=s+1 else: u=u+1 word=str(word) if u>s: word=word.upper() else: word=word.lower() print(word) ```
0
981
A
Antipalindrome
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$. Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all. Some time ago Ann read the word $s$. What is the word she changed it into?
The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only.
If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique.
[ "mew\n", "wuffuw\n", "qqqqqqqq\n" ]
[ "3\n", "5\n", "0\n" ]
"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$. The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$. All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$.
500
[ { "input": "mew", "output": "3" }, { "input": "wuffuw", "output": "5" }, { "input": "qqqqqqqq", "output": "0" }, { "input": "ijvji", "output": "4" }, { "input": "iiiiiii", "output": "0" }, { "input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow", "output": "49" }, { "input": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "output": "0" }, { "input": "wobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy", "output": "50" }, { "input": "ijvxljt", "output": "7" }, { "input": "fyhcncnchyf", "output": "10" }, { "input": "ffffffffffff", "output": "0" }, { "input": "fyhcncfsepqj", "output": "12" }, { "input": "ybejrrlbcinttnicblrrjeby", "output": "23" }, { "input": "yyyyyyyyyyyyyyyyyyyyyyyyy", "output": "0" }, { "input": "ybejrrlbcintahovgjddrqatv", "output": "25" }, { "input": "oftmhcmclgyqaojljoaqyglcmchmtfo", "output": "30" }, { "input": "oooooooooooooooooooooooooooooooo", "output": "0" }, { "input": "oftmhcmclgyqaojllbotztajglsmcilv", "output": "32" }, { "input": "gxandbtgpbknxvnkjaajknvxnkbpgtbdnaxg", "output": "35" }, { "input": "gggggggggggggggggggggggggggggggggggg", "output": "0" }, { "input": "gxandbtgpbknxvnkjaygommzqitqzjfalfkk", "output": "36" }, { "input": "fcliblymyqckxvieotjooojtoeivxkcqymylbilcf", "output": "40" }, { "input": "fffffffffffffffffffffffffffffffffffffffffff", "output": "0" }, { "input": "fcliblymyqckxvieotjootiqwtyznhhvuhbaixwqnsy", "output": "43" }, { "input": "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr", "output": "0" }, { "input": "rajccqwqnqmshmerpvjyfepxwpxyldzpzhctqjnstxyfmlhiy", "output": "49" }, { "input": "a", "output": "0" }, { "input": "abca", "output": "4" }, { "input": "aaaaabaaaaa", "output": "10" }, { "input": "aba", "output": "2" }, { "input": "asaa", "output": "4" }, { "input": "aabaa", "output": "4" }, { "input": "aabbaa", "output": "5" }, { "input": "abcdaaa", "output": "7" }, { "input": "aaholaa", "output": "7" }, { "input": "abcdefghijka", "output": "12" }, { "input": "aaadcba", "output": "7" }, { "input": "aaaabaaaa", "output": "8" }, { "input": "abaa", "output": "4" }, { "input": "abcbaa", "output": "6" }, { "input": "ab", "output": "2" }, { "input": "l", "output": "0" }, { "input": "aaaabcaaaa", "output": "10" }, { "input": "abbaaaaaabba", "output": "11" }, { "input": "abaaa", "output": "5" }, { "input": "baa", "output": "3" }, { "input": "aaaaaaabbba", "output": "11" }, { "input": "ccbcc", "output": "4" }, { "input": "bbbaaab", "output": "7" }, { "input": "abaaaaaaaa", "output": "10" }, { "input": "abaaba", "output": "5" }, { "input": "aabsdfaaaa", "output": "10" }, { "input": "aaaba", "output": "5" }, { "input": "aaabaaa", "output": "6" }, { "input": "baaabbb", "output": "7" }, { "input": "ccbbabbcc", "output": "8" }, { "input": "cabc", "output": "4" }, { "input": "aabcd", "output": "5" }, { "input": "abcdea", "output": "6" }, { "input": "bbabb", "output": "4" }, { "input": "aaaaabababaaaaa", "output": "14" }, { "input": "bbabbb", "output": "6" }, { "input": "aababd", "output": "6" }, { "input": "abaaaa", "output": "6" }, { "input": "aaaaaaaabbba", "output": "12" }, { "input": "aabca", "output": "5" }, { "input": "aaabccbaaa", "output": "9" }, { "input": "aaaaaaaaaaaaaaaaaaaab", "output": "21" }, { "input": "babb", "output": "4" }, { "input": "abcaa", "output": "5" }, { "input": "qwqq", "output": "4" }, { "input": "aaaaaaaaaaabbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaa", "output": "48" }, { "input": "aaab", "output": "4" }, { "input": "aaaaaabaaaaa", "output": "12" }, { "input": "wwuww", "output": "4" }, { "input": "aaaaabcbaaaaa", "output": "12" }, { "input": "aaabbbaaa", "output": "8" }, { "input": "aabcbaa", "output": "6" }, { "input": "abccdefccba", "output": "11" }, { "input": "aabbcbbaa", "output": "8" }, { "input": "aaaabbaaaa", "output": "9" }, { "input": "aabcda", "output": "6" }, { "input": "abbca", "output": "5" }, { "input": "aaaaaabbaaa", "output": "11" }, { "input": "sssssspssssss", "output": "12" }, { "input": "sdnmsdcs", "output": "8" }, { "input": "aaabbbccbbbaaa", "output": "13" }, { "input": "cbdbdc", "output": "6" }, { "input": "abb", "output": "3" }, { "input": "abcdefaaaa", "output": "10" }, { "input": "abbbaaa", "output": "7" }, { "input": "v", "output": "0" }, { "input": "abccbba", "output": "7" }, { "input": "axyza", "output": "5" }, { "input": "abcdefgaaaa", "output": "11" }, { "input": "aaabcdaaa", "output": "9" }, { "input": "aaaacaaaa", "output": "8" }, { "input": "aaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaa", "output": "42" }, { "input": "abbbaa", "output": "6" }, { "input": "abcdee", "output": "6" }, { "input": "oom", "output": "3" }, { "input": "aabcaa", "output": "6" }, { "input": "abba", "output": "3" }, { "input": "aaca", "output": "4" }, { "input": "aacbca", "output": "6" }, { "input": "ababa", "output": "4" }, { "input": "abcda", "output": "5" }, { "input": "cccaaccc", "output": "7" }, { "input": "aaabcda", "output": "7" }, { "input": "aa", "output": "0" }, { "input": "aabaaaa", "output": "7" }, { "input": "abbaaaa", "output": "7" }, { "input": "aaabcbaaa", "output": "8" }, { "input": "aabba", "output": "5" }, { "input": "xyxx", "output": "4" }, { "input": "aaaaaaaaaaaabc", "output": "14" }, { "input": "bbaaaabb", "output": "7" }, { "input": "aaabaa", "output": "6" }, { "input": "sssssabsssss", "output": "12" }, { "input": "bbbaaaabbb", "output": "9" }, { "input": "abbbbaaaa", "output": "9" }, { "input": "wwufuww", "output": "6" }, { "input": "oowoo", "output": "4" }, { "input": "cccaccc", "output": "6" }, { "input": "aaa", "output": "0" }, { "input": "bbbcc", "output": "5" }, { "input": "abcdef", "output": "6" }, { "input": "abbba", "output": "4" }, { "input": "aab", "output": "3" }, { "input": "aaba", "output": "4" }, { "input": "azbyaaa", "output": "7" }, { "input": "oooooiooooo", "output": "10" }, { "input": "aabbbbbaaaaaa", "output": "13" } ]
1,695,165,873
2,147,483,647
Python 3
OK
TESTS
133
46
0
word = str(input()) reverse_word = word[::-1] if reverse_word == word: first_char = word[0] single_letter = True for char in word: if char != first_char: single_letter = False if single_letter: print(0) else: print(len(word) - 1) else: print(len(word))
Title: Antipalindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$. Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all. Some time ago Ann read the word $s$. What is the word she changed it into? Input Specification: The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. Output Specification: If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique. Demo Input: ['mew\n', 'wuffuw\n', 'qqqqqqqq\n'] Demo Output: ['3\n', '5\n', '0\n'] Note: "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$. The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$. All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$.
```python word = str(input()) reverse_word = word[::-1] if reverse_word == word: first_char = word[0] single_letter = True for char in word: if char != first_char: single_letter = False if single_letter: print(0) else: print(len(word) - 1) else: print(len(word)) ```
3
96
A
Football
PROGRAMMING
900
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "output": "NO" }, { "input": "1010010100000000010", "output": "YES" }, { "input": "101010101", "output": "NO" }, { "input": "000000000100000000000110101100000", "output": "YES" }, { "input": "100001000000110101100000", "output": "NO" }, { "input": "100001000011010110000", "output": "NO" }, { "input": "010", "output": "NO" }, { "input": "10101011111111111111111111111100", "output": "YES" }, { "input": "1001101100", "output": "NO" }, { "input": "1001101010", "output": "NO" }, { "input": "1111100111", "output": "NO" }, { "input": "00110110001110001111", "output": "NO" }, { "input": "11110001001111110001", "output": "NO" }, { "input": "10001111001011111101", "output": "NO" }, { "input": "10000010100000001000110001010100001001001010011", "output": "YES" }, { "input": "01111011111010111100101100001011001010111110000010", "output": "NO" }, { "input": "00100000100100101110011001011011101110110110010100", "output": "NO" }, { "input": "10110100110001001011110101110010100010000000000100101010111110111110100011", "output": "YES" }, { "input": "00011101010101111001011011001101101011111101000010100000111000011100101011", "output": "NO" }, { "input": "01110000110100110101110100111000101101011101011110110100100111100001110111", "output": "NO" }, { "input": "11110110011000100111100111101101011111110100010101011011111101110110110111", "output": "YES" }, { "input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100", "output": "NO" }, { "input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010", "output": "NO" }, { "input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110", "output": "NO" }, { "input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000", "output": "NO" }, { "input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110", "output": "YES" }, { "input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000", "output": "NO" }, { "input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101", "output": "YES" }, { "input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101", "output": "YES" }, { "input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000", "output": "NO" }, { "input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000", "output": "YES" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", "output": "YES" }, { "input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111", "output": "YES" }, { "input": "10100101000", "output": "NO" }, { "input": "11110111011101", "output": "NO" }, { "input": "10000000", "output": "YES" }, { "input": "00000001", "output": "YES" }, { "input": "01111111", "output": "YES" }, { "input": "11111110", "output": "YES" } ]
1,691,499,618
2,147,483,647
Python 3
OK
TESTS
44
92
0
c=input() l="0000000" m="1111111" if (l in c) or ( m in c) : print("YES") else: print("NO")
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. Input Specification: The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. Output Specification: Print "YES" if the situation is dangerous. Otherwise, print "NO". Demo Input: ['001001\n', '1000000001\n'] Demo Output: ['NO\n', 'YES\n'] Note: none
```python c=input() l="0000000" m="1111111" if (l in c) or ( m in c) : print("YES") else: print("NO") ```
3.977
520
A
Pangram
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output "YES", if the string is a pangram and "NO" otherwise.
[ "12\ntoosmallword\n", "35\nTheQuickBrownFoxJumpsOverTheLazyDog\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "12\ntoosmallword", "output": "NO" }, { "input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog", "output": "YES" }, { "input": "1\na", "output": "NO" }, { "input": "26\nqwertyuiopasdfghjklzxcvbnm", "output": "YES" }, { "input": "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "YES" }, { "input": "48\nthereisasyetinsufficientdataforameaningfulanswer", "output": "NO" }, { "input": "30\nToBeOrNotToBeThatIsTheQuestion", "output": "NO" }, { "input": "30\njackdawslovemybigsphinxofquarz", "output": "NO" }, { "input": "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY", "output": "YES" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "NO" }, { "input": "26\nMGJYIZDKsbhpVeNFlquRTcWoAx", "output": "YES" }, { "input": "26\nfWMOhAPsbIVtyUEZrGNQXDklCJ", "output": "YES" }, { "input": "26\nngPMVFSThiRCwLEuyOAbKxQzDJ", "output": "YES" }, { "input": "25\nnxYTzLFwzNolAumjgcAboyxAj", "output": "NO" }, { "input": "26\npRWdodGdxUESvcScPGbUoooZsC", "output": "NO" }, { "input": "66\nBovdMlDzTaqKllZILFVfxbLGsRnzmtVVTmqiIDTYrossLEPlmsPrkUYtWEsGHVOnFj", "output": "NO" }, { "input": "100\nmKtsiDRJypUieHIkvJaMFkwaKxcCIbBszZQLIyPpCDCjhNpAnYFngLjRpnKWpKWtGnwoSteeZXuFHWQxxxOpFlNeYTwKocsXuCoa", "output": "YES" }, { "input": "26\nEoqxUbsLjPytUHMiFnvcGWZdRK", "output": "NO" }, { "input": "26\nvCUFRKElZOnjmXGylWQaHDiPst", "output": "NO" }, { "input": "26\nWtrPuaHdXLKJMsnvQfgOiJZBEY", "output": "NO" }, { "input": "26\npGiFluRteQwkaVoPszJyNBChxM", "output": "NO" }, { "input": "26\ncTUpqjPmANrdbzSFhlWIoKxgVY", "output": "NO" }, { "input": "26\nLndjgvAEuICHKxPwqYztosrmBN", "output": "NO" }, { "input": "26\nMdaXJrCipnOZLykfqHWEStevbU", "output": "NO" }, { "input": "26\nEjDWsVxfKTqGXRnUMOLYcIzPba", "output": "NO" }, { "input": "26\nxKwzRMpunYaqsdfaBgJcVElTHo", "output": "NO" }, { "input": "26\nnRYUQsTwCPLZkgshfEXvBdoiMa", "output": "NO" }, { "input": "26\nHNCQPfJutyAlDGsvRxZWMEbIdO", "output": "NO" }, { "input": "26\nDaHJIpvKznQcmUyWsTGObXRFDe", "output": "NO" }, { "input": "26\nkqvAnFAiRhzlJbtyuWedXSPcOG", "output": "NO" }, { "input": "26\nhlrvgdwsIOyjcmUZXtAKEqoBpF", "output": "NO" }, { "input": "26\njLfXXiMhBTcAwQVReGnpKzdsYu", "output": "NO" }, { "input": "26\nlNMcVuwItjxRBGAekjhyDsQOzf", "output": "NO" }, { "input": "26\nRkSwbNoYldUGtAZvpFMcxhIJFE", "output": "NO" }, { "input": "26\nDqspXZJTuONYieKgaHLMBwfVSC", "output": "NO" }, { "input": "26\necOyUkqNljFHRVXtIpWabGMLDz", "output": "NO" }, { "input": "26\nEKAvqZhBnPmVCDRlgWJfOusxYI", "output": "NO" }, { "input": "26\naLbgqeYchKdMrsZxIPFvTOWNjA", "output": "NO" }, { "input": "26\nxfpBLsndiqtacOCHGmeWUjRkYz", "output": "NO" }, { "input": "26\nXsbRKtqleZPNIVCdfUhyagAomJ", "output": "NO" }, { "input": "26\nAmVtbrwquEthZcjKPLiyDgSoNF", "output": "NO" }, { "input": "26\nOhvXDcwqAUmSEPRZGnjFLiKtNB", "output": "NO" }, { "input": "26\nEKWJqCFLRmstxVBdYuinpbhaOg", "output": "NO" }, { "input": "26\nmnbvcxxlkjhgfdsapoiuytrewq", "output": "NO" }, { "input": "26\naAbcdefghijklmnopqrstuvwxy", "output": "NO" }, { "input": "30\nABCDEFGHTYRIOPLabcdefghtyriopl", "output": "NO" }, { "input": "25\nabcdefghijklmnopqrstuvwxy", "output": "NO" }, { "input": "26\nabcdefhijklmnopqrstVxyzABC", "output": "NO" }, { "input": "25\nqwertyuiopasdfghjklxcvbnm", "output": "NO" }, { "input": "34\nTheQuickBrownFoxJumpsOverTheLayDog", "output": "NO" }, { "input": "26\nabcdefghigklmnopqrstuvwxyz", "output": "NO" }, { "input": "26\nabcdefghijklmnopqrstuvwxyA", "output": "NO" }, { "input": "50\nqazwsxedcrfvtgbyhnujmikolQWERTYUIOASDFGHJKLZXCVBNM", "output": "NO" }, { "input": "35\nTheQuickBrownFoxJumpsOverTheLasyDog", "output": "NO" }, { "input": "25\nbcdefghijklmnopqrstuvwxyz", "output": "NO" }, { "input": "38\nAbCdEfGhIjKlMnOpQrStVwXyZzzzzzzaaaaaaa", "output": "NO" }, { "input": "26\nabcdefghiklmnopqrstvxyzABC", "output": "NO" }, { "input": "26\nabcdefghijklmnopqrstuvwxzZ", "output": "NO" }, { "input": "50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY", "output": "NO" } ]
1,694,463,720
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
921,600
import string lower = list(string.ascii_lowercase) n=int(input()) st=int() flag=True if len(st)<26: flag=False print("NO") if flag: for alpha in lower: if alpha not in st: print("No") flag=False break if flag: print("YES")
Title: Pangram Time Limit: None seconds Memory Limit: None megabytes Problem Description: A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters. Output Specification: Output "YES", if the string is a pangram and "NO" otherwise. Demo Input: ['12\ntoosmallword\n', '35\nTheQuickBrownFoxJumpsOverTheLazyDog\n'] Demo Output: ['NO\n', 'YES\n'] Note: none
```python import string lower = list(string.ascii_lowercase) n=int(input()) st=int() flag=True if len(st)<26: flag=False print("NO") if flag: for alpha in lower: if alpha not in st: print("No") flag=False break if flag: print("YES") ```
-1
877
D
Olya and Energy Drinks
PROGRAMMING
2,100
[ "data structures", "dfs and similar", "graphs", "shortest paths" ]
null
null
Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks. Formally, her room can be represented as a field of *n*<=×<=*m* cells, each cell of which is empty or littered with cans. Olya drank a lot of energy drink, so now she can run *k* meters per second. Each second she chooses one of the four directions (up, down, left or right) and runs from 1 to *k* meters in this direction. Of course, she can only run through empty cells. Now Olya needs to get from cell (*x*1,<=*y*1) to cell (*x*2,<=*y*2). How many seconds will it take her if she moves optimally? It's guaranteed that cells (*x*1,<=*y*1) and (*x*2,<=*y*2) are empty. These cells can coincide.
The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the sizes of the room and Olya's speed. Then *n* lines follow containing *m* characters each, the *i*-th of them contains on *j*-th position "#", if the cell (*i*,<=*j*) is littered with cans, and "." otherwise. The last line contains four integers *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1,<=*x*2<=≤<=*n*, 1<=≤<=*y*1,<=*y*2<=≤<=*m*) — the coordinates of the first and the last cells.
Print a single integer — the minimum time it will take Olya to get from (*x*1,<=*y*1) to (*x*2,<=*y*2). If it's impossible to get from (*x*1,<=*y*1) to (*x*2,<=*y*2), print -1.
[ "3 4 4\n....\n###.\n....\n1 1 3 1\n", "3 4 1\n....\n###.\n....\n1 1 3 1\n", "2 2 1\n.#\n#.\n1 1 2 2\n" ]
[ "3", "8", "-1" ]
In the first sample Olya should run 3 meters to the right in the first second, 2 meters down in the second second and 3 meters to the left in the third second. In second sample Olya should run to the right for 3 seconds, then down for 2 seconds and then to the left for 3 seconds. Olya does not recommend drinking energy drinks and generally believes that this is bad.
2,000
[ { "input": "3 4 4\n....\n###.\n....\n1 1 3 1", "output": "3" }, { "input": "3 4 1\n....\n###.\n....\n1 1 3 1", "output": "8" }, { "input": "2 2 1\n.#\n#.\n1 1 2 2", "output": "-1" }, { "input": "10 10 1\n##########\n#.........\n#.#######.\n#.#.....#.\n#.#.###.#.\n#.#.#.#.#.\n#.#.#.#.#.\n#.#.#...#.\n#.#.#####.\n#.#.......\n6 6 10 2", "output": "48" }, { "input": "10 10 3\n##########\n##########\n##########\n##########\n##########\n##########\n##########\n#########.\n#########.\n####..###.\n10 6 10 5", "output": "1" }, { "input": "10 10 3\n...##..#..\n#.#..#...#\n..#.##.#..\n##..#..#.#\n..#...##..\n.#.#.#....\n#......#..\n.#.####.##\n......#...\n.#.##...##\n4 6 8 1", "output": "7" }, { "input": "10 10 1000\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n7 6 1 3", "output": "2" }, { "input": "10 10 1000\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n.....#....\n3 9 5 1", "output": "2" }, { "input": "10 10 10\n...#......\n##.#.#####\n...#...###\n.#####.###\n...#...###\n##.#.#####\n...#...###\n.#####.###\n.......###\n##########\n1 1 1 10", "output": "17" }, { "input": "2 5 5\n#####\n##.##\n2 3 2 3", "output": "0" }, { "input": "4 4 4\n...#\n.#.#\n....\n##..\n1 1 3 4", "output": "2" }, { "input": "6 6 100\n....##\n.##.##\n.##.##\n......\n###.##\n###.##\n1 1 4 6", "output": "2" } ]
1,611,099,155
3,755
PyPy 3
WRONG_ANSWER
TESTS
4
670
62,156,800
import sys from collections import deque input=sys.stdin.readline n,m,k=map(int,input().split()) grid=[] grid1=[] grid2=[] leftyes=[] rightyes=[] upyes=[] downyes=[] for i in range(n): grid.append(input()) grid1.append([-1]*m) grid2.append([0]*m) leftyes.append([0]*m) rightyes.append([0]*m) downyes.append([0]*m) upyes.append([0]*m) for i in range(n): count=0 for j in range(m): if grid[i][j]=='.': count+=1 else: count=0 if count>k: leftyes[i][j]=1 rightyes[i][j-k]=1 for i in range(m): count=0 for j in range(n): if grid[j][i]=='.': count+=1 else: count=0 if count>k: upyes[j][i]=1 downyes[j-k][i]=1 x1,y1,x2,y2=map(int,input().split()) que=deque([(x1-1,y1-1,0)]) grid1[x1-1][y1-1]=0 while que: x,y,step=que.popleft() if grid2[x][y]: continue grid2[x][y]=1 if not(x<n-1 and grid1[x+1][y]!=-1): curr=x-1 count=0 while count<k and curr>=0 and grid[curr][y]=='.' and grid1[curr][y]==-1: que.append((curr,y,step+1)) grid1[curr][y]=step+1 curr-=1 count+=1 else: if upyes[x][y]: que.append((x-k,y,step+1)) grid1[x-k][y]=step+1 if not(x>0 and grid1[x-1][y]!=-1): curr=x+1 count=0 while count<k and curr<=n-1 and grid[curr][y]=='.' and grid1[curr][y]==-1: que.append((curr,y,step+1)) grid1[curr][y]=step+1 curr+=1 count+=1 else: if downyes[x][y]: que.append((x+k,y,step+1)) grid1[x+k][y]=step+1 if not(y<m-1 and grid1[x][y+1]!=-1): curr=y-1 count=0 while count<k and curr>=0 and grid[x][curr]=='.' and grid1[x][curr]==-1: que.append((x,curr,step+1)) grid1[x][curr]=step+1 curr-=1 count+=1 else: if leftyes[x][y]: que.append((x,y-k,step+1)) grid1[x][y-k]=step+1 if not(y>0 and grid1[x][y-1]!=-1): curr=y+1 count=0 while count<k and curr<=m-1 and grid[x][curr]=='.' and grid1[x][curr]==-1: que.append((x,curr,step+1)) grid1[x][curr]=step+1 curr+=1 count+=1 else: if rightyes[x][y]: que.append((x,y+k,step+1)) grid1[x][y+k]=step+1 print(grid1[x2-1][y2-1])
Title: Olya and Energy Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks. Formally, her room can be represented as a field of *n*<=×<=*m* cells, each cell of which is empty or littered with cans. Olya drank a lot of energy drink, so now she can run *k* meters per second. Each second she chooses one of the four directions (up, down, left or right) and runs from 1 to *k* meters in this direction. Of course, she can only run through empty cells. Now Olya needs to get from cell (*x*1,<=*y*1) to cell (*x*2,<=*y*2). How many seconds will it take her if she moves optimally? It's guaranteed that cells (*x*1,<=*y*1) and (*x*2,<=*y*2) are empty. These cells can coincide. Input Specification: The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the sizes of the room and Olya's speed. Then *n* lines follow containing *m* characters each, the *i*-th of them contains on *j*-th position "#", if the cell (*i*,<=*j*) is littered with cans, and "." otherwise. The last line contains four integers *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1,<=*x*2<=≤<=*n*, 1<=≤<=*y*1,<=*y*2<=≤<=*m*) — the coordinates of the first and the last cells. Output Specification: Print a single integer — the minimum time it will take Olya to get from (*x*1,<=*y*1) to (*x*2,<=*y*2). If it's impossible to get from (*x*1,<=*y*1) to (*x*2,<=*y*2), print -1. Demo Input: ['3 4 4\n....\n###.\n....\n1 1 3 1\n', '3 4 1\n....\n###.\n....\n1 1 3 1\n', '2 2 1\n.#\n#.\n1 1 2 2\n'] Demo Output: ['3', '8', '-1'] Note: In the first sample Olya should run 3 meters to the right in the first second, 2 meters down in the second second and 3 meters to the left in the third second. In second sample Olya should run to the right for 3 seconds, then down for 2 seconds and then to the left for 3 seconds. Olya does not recommend drinking energy drinks and generally believes that this is bad.
```python import sys from collections import deque input=sys.stdin.readline n,m,k=map(int,input().split()) grid=[] grid1=[] grid2=[] leftyes=[] rightyes=[] upyes=[] downyes=[] for i in range(n): grid.append(input()) grid1.append([-1]*m) grid2.append([0]*m) leftyes.append([0]*m) rightyes.append([0]*m) downyes.append([0]*m) upyes.append([0]*m) for i in range(n): count=0 for j in range(m): if grid[i][j]=='.': count+=1 else: count=0 if count>k: leftyes[i][j]=1 rightyes[i][j-k]=1 for i in range(m): count=0 for j in range(n): if grid[j][i]=='.': count+=1 else: count=0 if count>k: upyes[j][i]=1 downyes[j-k][i]=1 x1,y1,x2,y2=map(int,input().split()) que=deque([(x1-1,y1-1,0)]) grid1[x1-1][y1-1]=0 while que: x,y,step=que.popleft() if grid2[x][y]: continue grid2[x][y]=1 if not(x<n-1 and grid1[x+1][y]!=-1): curr=x-1 count=0 while count<k and curr>=0 and grid[curr][y]=='.' and grid1[curr][y]==-1: que.append((curr,y,step+1)) grid1[curr][y]=step+1 curr-=1 count+=1 else: if upyes[x][y]: que.append((x-k,y,step+1)) grid1[x-k][y]=step+1 if not(x>0 and grid1[x-1][y]!=-1): curr=x+1 count=0 while count<k and curr<=n-1 and grid[curr][y]=='.' and grid1[curr][y]==-1: que.append((curr,y,step+1)) grid1[curr][y]=step+1 curr+=1 count+=1 else: if downyes[x][y]: que.append((x+k,y,step+1)) grid1[x+k][y]=step+1 if not(y<m-1 and grid1[x][y+1]!=-1): curr=y-1 count=0 while count<k and curr>=0 and grid[x][curr]=='.' and grid1[x][curr]==-1: que.append((x,curr,step+1)) grid1[x][curr]=step+1 curr-=1 count+=1 else: if leftyes[x][y]: que.append((x,y-k,step+1)) grid1[x][y-k]=step+1 if not(y>0 and grid1[x][y-1]!=-1): curr=y+1 count=0 while count<k and curr<=m-1 and grid[x][curr]=='.' and grid1[x][curr]==-1: que.append((x,curr,step+1)) grid1[x][curr]=step+1 curr+=1 count+=1 else: if rightyes[x][y]: que.append((x,y+k,step+1)) grid1[x][y+k]=step+1 print(grid1[x2-1][y2-1]) ```
0
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions.
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "output": "5" }, { "input": "2 6", "output": "6" }, { "input": "2 7", "output": "7" }, { "input": "2 14", "output": "14" }, { "input": "2 15", "output": "15" }, { "input": "1 4", "output": "2" }, { "input": "2 16", "output": "16" }, { "input": "3 5", "output": "7" }, { "input": "3 6", "output": "9" }, { "input": "3 10", "output": "15" }, { "input": "3 14", "output": "21" }, { "input": "3 15", "output": "22" }, { "input": "3 16", "output": "24" }, { "input": "5 7", "output": "17" }, { "input": "16 16", "output": "128" }, { "input": "15 16", "output": "120" }, { "input": "2 3", "output": "3" }, { "input": "15 15", "output": "112" }, { "input": "14 16", "output": "112" }, { "input": "11 13", "output": "71" }, { "input": "5 16", "output": "40" }, { "input": "8 15", "output": "60" }, { "input": "2 2", "output": "2" }, { "input": "3 4", "output": "6" }, { "input": "4 4", "output": "8" }, { "input": "1 1", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "14 15", "output": "105" } ]
1,620,487,229
2,147,483,647
Python 3
OK
TESTS
35
124
6,758,400
length, width = map(int, input().split()) print(length * width // 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 length, width = map(int, input().split()) print(length * width // 2) ```
3.956411
386
A
Second-Price Auction
PROGRAMMING
800
[ "implementation" ]
null
null
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction). Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different.
The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder.
The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.
[ "2\n5 7\n", "3\n10 2 8\n", "6\n3 8 2 9 4 14\n" ]
[ "2 5\n", "1 8\n", "6 9\n" ]
none
500
[ { "input": "2\n5 7", "output": "2 5" }, { "input": "3\n10 2 8", "output": "1 8" }, { "input": "6\n3 8 2 9 4 14", "output": "6 9" }, { "input": "4\n4707 7586 4221 5842", "output": "2 5842" }, { "input": "5\n3304 4227 4869 6937 6002", "output": "4 6002" }, { "input": "6\n5083 3289 7708 5362 9031 7458", "output": "5 7708" }, { "input": "7\n9038 6222 3392 1706 3778 1807 2657", "output": "1 6222" }, { "input": "8\n7062 2194 4481 3864 7470 1814 8091 733", "output": "7 7470" }, { "input": "9\n2678 5659 9199 2628 7906 7496 4524 2663 3408", "output": "3 7906" }, { "input": "2\n3458 1504", "output": "1 1504" }, { "input": "50\n9237 3904 407 9052 6657 9229 9752 3888 7732 2512 4614 1055 2355 7108 6506 6849 2529 8862 159 8630 7906 7941 960 8470 333 8659 54 9475 3163 5625 6393 6814 2656 3388 169 7918 4881 8468 9983 6281 6340 280 5108 2996 101 7617 3313 8172 326 1991", "output": "39 9752" }, { "input": "100\n2515 3324 7975 6171 4240 1217 4829 5203 8603 6900 3031 4699 4732 6070 4221 3228 6497 7359 9130 4346 4619 1109 3945 5442 3271 16 9711 2045 6410 2301 3406 8125 6003 1892 1260 9661 3940 6692 4708 7027 4930 6925 1979 5361 4263 3144 867 8639 6230 5562 9714 3676 4231 3347 4733 4920 4881 3431 1059 7313 8912 3038 9308 72 9583 7009 3034 7425 2398 6141 3245 2495 2933 6710 8289 9806 1226 8393 7349 6462 1618 9613 3546 6012 2964 9995 1578 210 2123 4874 1252 8625 348 8020 803 7244 9080 5088 706 2602", "output": "86 9806" }, { "input": "2\n2 1", "output": "1 1" }, { "input": "2\n1 2", "output": "2 1" }, { "input": "3\n10 20 30", "output": "3 20" }, { "input": "3\n10 30 20", "output": "2 20" }, { "input": "3\n20 10 30", "output": "3 20" }, { "input": "3\n20 30 10", "output": "2 20" }, { "input": "3\n30 10 20", "output": "1 20" }, { "input": "3\n30 20 10", "output": "1 20" }, { "input": "2\n1 10000", "output": "2 1" }, { "input": "2\n10000 999", "output": "1 999" }, { "input": "3\n3 4 1", "output": "2 3" }, { "input": "6\n1 2 24 6 5 7", "output": "3 7" } ]
1,672,973,728
2,147,483,647
Python 3
OK
TESTS
42
46
0
n, p = int(input()), sorted((int(p), i + 1) for i, p in enumerate(input().split())) res = p[-1][1], p[-2][0] print(*res)
Title: Second-Price Auction Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction). Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different. Input Specification: The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. Output Specification: The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. Demo Input: ['2\n5 7\n', '3\n10 2 8\n', '6\n3 8 2 9 4 14\n'] Demo Output: ['2 5\n', '1 8\n', '6 9\n'] Note: none
```python n, p = int(input()), sorted((int(p), i + 1) for i, p in enumerate(input().split())) res = p[-1][1], p[-2][0] print(*res) ```
3
598
D
Igor In the Museum
PROGRAMMING
1,700
[ "dfs and similar", "graphs", "shortest paths" ]
null
null
Igor is in the museum and he wants to see as many pictures as possible. Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture. At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that share a side with the current one. For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will examine every picture he can see.
First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process. Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that all border cells are impassable, so Igor can't go out from the museum. Each of the last *k* lines contains two integers *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) — the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns — from left to right. It is guaranteed that all starting positions are empty cells.
Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position.
[ "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n", "4 4 1\n****\n*..*\n*.**\n****\n3 2\n" ]
[ "6\n4\n10\n", "8\n" ]
none
0
[ { "input": "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3", "output": "6\n4\n10" }, { "input": "4 4 1\n****\n*..*\n*.**\n****\n3 2", "output": "8" }, { "input": "3 3 1\n***\n*.*\n***\n2 2", "output": "4" }, { "input": "5 5 10\n*****\n*...*\n*..**\n*.***\n*****\n2 4\n4 2\n2 2\n2 3\n2 2\n2 2\n2 4\n3 2\n2 2\n2 2", "output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12" }, { "input": "10 3 10\n***\n*.*\n*.*\n***\n***\n*.*\n*.*\n*.*\n*.*\n***\n2 2\n2 2\n2 2\n2 2\n8 2\n2 2\n2 2\n7 2\n8 2\n6 2", "output": "6\n6\n6\n6\n10\n6\n6\n10\n10\n10" }, { "input": "3 10 10\n**********\n***.*.*..*\n**********\n2 6\n2 6\n2 9\n2 9\n2 4\n2 9\n2 6\n2 6\n2 4\n2 6", "output": "4\n4\n6\n6\n4\n6\n4\n4\n4\n4" }, { "input": "10 10 50\n**********\n*......***\n***..**..*\n***....***\n**..***..*\n**..**.*.*\n*****..***\n*.***..***\n*..****.**\n**********\n5 9\n5 9\n7 7\n6 4\n6 7\n8 7\n6 7\n9 2\n3 9\n9 2\n4 7\n4 6\n2 7\n9 2\n7 7\n5 8\n8 7\n8 6\n7 7\n5 9\n8 7\n3 8\n3 8\n5 9\n9 8\n9 3\n8 7\n5 9\n9 2\n9 8\n9 3\n3 8\n9 2\n8 6\n2 4\n6 9\n6 3\n9 8\n3 9\n9 8\n4 5\n8 6\n3 8\n5 9\n8 7\n5 8\n6 9\n8 2\n3 9\n3 9", "output": "8\n8\n10\n28\n10\n10\n10\n8\n6\n8\n28\n28\n28\n8\n10\n8\n10\n10\n10\n8\n10\n6\n6\n8\n4\n8\n10\n8\n8\n4\n8\n6\n8\n10\n28\n8\n28\n4\n6\n4\n28\n10\n6\n8\n10\n8\n8\n8\n6\n6" }, { "input": "5 5 21\n*****\n*.***\n*****\n*****\n*****\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2", "output": "4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4" } ]
1,682,706,344
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
14
982
18,534,400
ent1, ent2, ent3 = map(int, input().split()) campo = [list(input().strip()) for _ in range(ent1)] matriz = [[0]*ent2 for _ in range(ent1)] passouX = [[False]*ent2 for _ in range(ent1)] passouY = [[False]*ent2 for _ in range(ent1)] def buscaProfundidadeAtualiza(a, b, c, d): # verifica se o ponto já foi visitado ou se o ponto é um asterisco if passouY[a][b] or campo[a][b] == '*': return # seta o ponto atual como visitado passouY[a][b] = True # seta o número de asteriscos encontrado no ponto (c, d) ao ponto atual (a, b) matriz[a][b] = matriz[c][d] # busca em profundidade nos pontos vizinhos não passouX for nx, ny in [(a-1, b), (a, b-1), (a+1, b), (a, b+1)]: if nx >= 0 and nx < ent1 and ny >= 0 and ny < ent2: buscaProfundidadeAtualiza(nx, ny, c, d) def buscaProfundidadeContagemAsteriscos(a, b): # se o ponto já foi visitado, retorna 0 if passouX[a][b]: return 0 # se o ponto é um asterisco, retorna 1 if campo[a][b] == '*': return 1 # seta o ponto atual como visitado passouX[a][b] = True # busca em profundidade nos pontos vizinhos não passouX e soma o número de asteriscos encontrados numerosAsteriscos = 0 for nx, ny in [(a-1, b), (a, b-1), (a+1, b), (a, b+1)]: if nx >= 0 and nx < ent1 and ny >= 0 and ny < ent2: numerosAsteriscos += buscaProfundidadeContagemAsteriscos(nx, ny) # Guarda o número de asteriscos encontrados no ponto atuals matriz[a][b] = numerosAsteriscos return numerosAsteriscos for i in range(ent1): for c in range(ent2): if not passouX[i][c] and campo[i][c] == '.': buscaProfundidadeContagemAsteriscos(i, c) buscaProfundidadeAtualiza(i, c, i, c) res = [] for i in range(ent3): linha, coluna = map(int, input().split()) linha, coluna = linha-1, coluna-1 res.append(matriz[linha][coluna]) for i in res: print(i)
Title: Igor In the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Igor is in the museum and he wants to see as many pictures as possible. Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture. At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that share a side with the current one. For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will examine every picture he can see. Input Specification: First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process. Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that all border cells are impassable, so Igor can't go out from the museum. Each of the last *k* lines contains two integers *x* and *y* (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*) — the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns — from left to right. It is guaranteed that all starting positions are empty cells. Output Specification: Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position. Demo Input: ['5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n', '4 4 1\n****\n*..*\n*.**\n****\n3 2\n'] Demo Output: ['6\n4\n10\n', '8\n'] Note: none
```python ent1, ent2, ent3 = map(int, input().split()) campo = [list(input().strip()) for _ in range(ent1)] matriz = [[0]*ent2 for _ in range(ent1)] passouX = [[False]*ent2 for _ in range(ent1)] passouY = [[False]*ent2 for _ in range(ent1)] def buscaProfundidadeAtualiza(a, b, c, d): # verifica se o ponto já foi visitado ou se o ponto é um asterisco if passouY[a][b] or campo[a][b] == '*': return # seta o ponto atual como visitado passouY[a][b] = True # seta o número de asteriscos encontrado no ponto (c, d) ao ponto atual (a, b) matriz[a][b] = matriz[c][d] # busca em profundidade nos pontos vizinhos não passouX for nx, ny in [(a-1, b), (a, b-1), (a+1, b), (a, b+1)]: if nx >= 0 and nx < ent1 and ny >= 0 and ny < ent2: buscaProfundidadeAtualiza(nx, ny, c, d) def buscaProfundidadeContagemAsteriscos(a, b): # se o ponto já foi visitado, retorna 0 if passouX[a][b]: return 0 # se o ponto é um asterisco, retorna 1 if campo[a][b] == '*': return 1 # seta o ponto atual como visitado passouX[a][b] = True # busca em profundidade nos pontos vizinhos não passouX e soma o número de asteriscos encontrados numerosAsteriscos = 0 for nx, ny in [(a-1, b), (a, b-1), (a+1, b), (a, b+1)]: if nx >= 0 and nx < ent1 and ny >= 0 and ny < ent2: numerosAsteriscos += buscaProfundidadeContagemAsteriscos(nx, ny) # Guarda o número de asteriscos encontrados no ponto atuals matriz[a][b] = numerosAsteriscos return numerosAsteriscos for i in range(ent1): for c in range(ent2): if not passouX[i][c] and campo[i][c] == '.': buscaProfundidadeContagemAsteriscos(i, c) buscaProfundidadeAtualiza(i, c, i, c) res = [] for i in range(ent3): linha, coluna = map(int, input().split()) linha, coluna = linha-1, coluna-1 res.append(matriz[linha][coluna]) for i in res: print(i) ```
-1
373
A
Collecting Beats is Fun
PROGRAMMING
900
[ "implementation" ]
null
null
Cucumber boy is fan of Kyubeat, a famous music game. Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel. Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with his one hand. Cucumber boy is trying to press all panels in perfect timing, that is he wants to press each panel exactly in its preffered time. If he cannot press the panels with his two hands in perfect timing, his challenge to press all the panels in perfect timing will fail. You are given one scene of Kyubeat's panel from the music Cucumber boy is trying. Tell him is he able to press all the panels in perfect timing.
The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand. Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If period was written on the panel, he doesn't have to press that panel.
Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes).
[ "1\n.135\n1247\n3468\n5789\n", "5\n..1.\n1111\n..1.\n..1.\n", "1\n....\n12.1\n.2..\n.2..\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands.
500
[ { "input": "1\n.135\n1247\n3468\n5789", "output": "YES" }, { "input": "5\n..1.\n1111\n..1.\n..1.", "output": "YES" }, { "input": "1\n....\n12.1\n.2..\n.2..", "output": "NO" }, { "input": "1\n6981\n.527\n4163\n2345", "output": "YES" }, { "input": "5\n9999\n9999\n9999\n9999", "output": "NO" }, { "input": "2\n4444\n3333\n2222\n1111", "output": "YES" }, { "input": "3\n2123\n1232\n2321\n3213", "output": "NO" }, { "input": "2\n1...\n.1..\n..1.\n...1", "output": "YES" }, { "input": "2\n1.1.\n.1.1\n2.2.\n.222", "output": "NO" }, { "input": "1\n1..2\n.3.4\n567.\n.89.", "output": "YES" }, { "input": "1\n1122\n3344\n5588\n6699", "output": "YES" }, { "input": "4\n1111\n1221\n1221\n1111", "output": "NO" }, { "input": "5\n3141\n5926\n5358\n9793", "output": "YES" }, { "input": "5\n5454\n4343\n3232\n2121", "output": "YES" }, { "input": "5\n1222\n2221\n2221\n1122", "output": "NO" }, { "input": "1\n....\n5..5\n6..6\n7..7", "output": "YES" }, { "input": "1\n9875\n8643\n7421\n531.", "output": "YES" }, { "input": "1\n..1.\n..1.\n..1.\n..1.", "output": "NO" }, { "input": "4\n4.4.\n4.4.\n4444\n..4.", "output": "NO" }, { "input": "5\n4.4.\n4.4.\n4444\n..4.", "output": "YES" }, { "input": "3\n1.1.\n.1.1\n1.1.\n.1.1", "output": "NO" }, { "input": "2\n1131\n4412\n2569\n3478", "output": "YES" }, { "input": "2\n8888\n8888\n8888\n8888", "output": "NO" } ]
1,535,000,883
2,147,483,647
Python 3
OK
TESTS
27
109
0
# Made By Mostafa_Khaled bot = True k=int(input())*2 s=''.join(input() for _ in range(4)) if max(s.count(c) for c in '0123456789')>k: print ('NO') else: print('YES') # Made By Mostafa_Khaled
Title: Collecting Beats is Fun Time Limit: None seconds Memory Limit: None megabytes Problem Description: Cucumber boy is fan of Kyubeat, a famous music game. Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel. Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with his one hand. Cucumber boy is trying to press all panels in perfect timing, that is he wants to press each panel exactly in its preffered time. If he cannot press the panels with his two hands in perfect timing, his challenge to press all the panels in perfect timing will fail. You are given one scene of Kyubeat's panel from the music Cucumber boy is trying. Tell him is he able to press all the panels in perfect timing. Input Specification: The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand. Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If period was written on the panel, he doesn't have to press that panel. Output Specification: Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes). Demo Input: ['1\n.135\n1247\n3468\n5789\n', '5\n..1.\n1111\n..1.\n..1.\n', '1\n....\n12.1\n.2..\n.2..\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands.
```python # Made By Mostafa_Khaled bot = True k=int(input())*2 s=''.join(input() for _ in range(4)) if max(s.count(c) for c in '0123456789')>k: print ('NO') else: print('YES') # Made By Mostafa_Khaled ```
3
0
none
none
none
0
[ "none" ]
null
null
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between $-100$ and $100$.
Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower).
[ "0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1\n", "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1\n", "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples:
0
[ { "input": "0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1", "output": "YES" }, { "input": "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1", "output": "NO" }, { "input": "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7", "output": "YES" }, { "input": "0 0 6 0 6 6 0 6\n8 4 4 8 8 12 12 8", "output": "YES" }, { "input": "2 2 4 2 4 4 2 4\n0 3 3 6 6 3 3 0", "output": "YES" }, { "input": "-5 -5 5 -5 5 5 -5 5\n-5 7 0 2 5 7 0 12", "output": "YES" }, { "input": "-5 -5 5 -5 5 5 -5 5\n-5 12 0 7 5 12 0 17", "output": "NO" }, { "input": "-5 -5 5 -5 5 5 -5 5\n6 0 0 6 -6 0 0 -6", "output": "YES" }, { "input": "-100 -100 100 -100 100 100 -100 100\n-100 0 0 -100 100 0 0 100", "output": "YES" }, { "input": "92 1 92 98 -5 98 -5 1\n44 60 56 48 44 36 32 48", "output": "YES" }, { "input": "-12 -54 -12 33 -99 33 -99 -54\n-77 -40 -86 -31 -77 -22 -68 -31", "output": "YES" }, { "input": "3 45 19 45 19 61 3 61\n-29 45 -13 29 3 45 -13 61", "output": "YES" }, { "input": "79 -19 79 15 45 15 45 -19\n-1 24 -29 52 -1 80 27 52", "output": "NO" }, { "input": "75 -57 75 -21 39 -21 39 -57\n10 -42 -32 0 10 42 52 0", "output": "NO" }, { "input": "-11 53 9 53 9 73 -11 73\n-10 9 -43 42 -10 75 23 42", "output": "YES" }, { "input": "-10 -36 -10 27 -73 27 -73 -36\n44 -28 71 -55 44 -82 17 -55", "output": "NO" }, { "input": "-63 -15 6 -15 6 54 -63 54\n15 -13 -8 10 15 33 38 10", "output": "YES" }, { "input": "47 15 51 15 51 19 47 19\n19 0 -27 46 19 92 65 46", "output": "NO" }, { "input": "87 -5 87 79 3 79 3 -5\n36 36 78 -6 36 -48 -6 -6", "output": "YES" }, { "input": "-4 56 10 56 10 70 -4 70\n-11 47 -35 71 -11 95 13 71", "output": "YES" }, { "input": "-41 6 -41 8 -43 8 -43 6\n-7 27 43 -23 -7 -73 -57 -23", "output": "NO" }, { "input": "44 -58 44 7 -21 7 -21 -58\n22 19 47 -6 22 -31 -3 -6", "output": "YES" }, { "input": "-37 -63 49 -63 49 23 -37 23\n-52 68 -21 37 -52 6 -83 37", "output": "YES" }, { "input": "93 20 93 55 58 55 58 20\n61 -17 39 5 61 27 83 5", "output": "YES" }, { "input": "-7 4 -7 58 -61 58 -61 4\n-28 45 -17 34 -28 23 -39 34", "output": "YES" }, { "input": "24 -79 87 -79 87 -16 24 -16\n-59 21 -85 47 -59 73 -33 47", "output": "NO" }, { "input": "-68 -15 6 -15 6 59 -68 59\n48 -18 57 -27 48 -36 39 -27", "output": "NO" }, { "input": "25 1 25 91 -65 91 -65 1\n24 3 15 12 24 21 33 12", "output": "YES" }, { "input": "55 24 73 24 73 42 55 42\n49 17 10 56 49 95 88 56", "output": "YES" }, { "input": "69 -65 69 -28 32 -28 32 -65\n-1 50 43 6 -1 -38 -45 6", "output": "NO" }, { "input": "86 -26 86 18 42 18 42 -26\n3 -22 -40 21 3 64 46 21", "output": "YES" }, { "input": "52 -47 52 -30 35 -30 35 -47\n49 -22 64 -37 49 -52 34 -37", "output": "YES" }, { "input": "27 -59 27 9 -41 9 -41 -59\n-10 -17 2 -29 -10 -41 -22 -29", "output": "YES" }, { "input": "-90 2 0 2 0 92 -90 92\n-66 31 -86 51 -66 71 -46 51", "output": "YES" }, { "input": "-93 -86 -85 -86 -85 -78 -93 -78\n-13 61 0 48 -13 35 -26 48", "output": "NO" }, { "input": "-3 -45 85 -45 85 43 -3 43\n-22 0 -66 44 -22 88 22 44", "output": "YES" }, { "input": "-27 -73 72 -73 72 26 -27 26\n58 11 100 -31 58 -73 16 -31", "output": "YES" }, { "input": "-40 -31 8 -31 8 17 -40 17\n0 18 -35 53 0 88 35 53", "output": "NO" }, { "input": "-15 -63 -15 7 -85 7 -85 -63\n-35 -40 -33 -42 -35 -44 -37 -42", "output": "YES" }, { "input": "-100 -100 -100 100 100 100 100 -100\n-100 0 0 100 100 0 0 -100", "output": "YES" }, { "input": "67 33 67 67 33 67 33 33\n43 11 9 45 43 79 77 45", "output": "YES" }, { "input": "14 8 9 8 9 3 14 3\n-2 -13 14 3 30 -13 14 -29", "output": "YES" }, { "input": "4 3 7 3 7 6 4 6\n7 29 20 16 7 3 -6 16", "output": "YES" }, { "input": "14 30 3 30 3 19 14 19\n19 -13 11 -5 19 3 27 -5", "output": "NO" }, { "input": "-54 3 -50 3 -50 -1 -54 -1\n3 -50 -6 -41 -15 -50 -6 -59", "output": "NO" }, { "input": "3 8 3 -10 21 -10 21 8\n-9 2 -21 -10 -9 -22 3 -10", "output": "YES" }, { "input": "-35 3 -21 3 -21 -11 -35 -11\n-8 -10 3 -21 -8 -32 -19 -21", "output": "NO" }, { "input": "-5 -23 -5 -31 3 -31 3 -23\n-7 -23 -2 -28 3 -23 -2 -18", "output": "YES" }, { "input": "3 20 10 20 10 13 3 13\n3 20 21 38 39 20 21 2", "output": "YES" }, { "input": "25 3 16 3 16 12 25 12\n21 -2 16 -7 11 -2 16 3", "output": "YES" }, { "input": "-1 18 -1 3 14 3 14 18\n14 3 19 8 14 13 9 8", "output": "YES" }, { "input": "-44 -17 -64 -17 -64 3 -44 3\n-56 15 -44 27 -32 15 -44 3", "output": "YES" }, { "input": "17 3 2 3 2 18 17 18\n22 23 2 3 -18 23 2 43", "output": "YES" }, { "input": "3 -22 3 -36 -11 -36 -11 -22\n11 -44 19 -36 11 -28 3 -36", "output": "YES" }, { "input": "3 45 3 48 0 48 0 45\n13 38 4 47 13 56 22 47", "output": "NO" }, { "input": "3 -10 2 -10 2 -9 3 -9\n38 -10 20 -28 2 -10 20 8", "output": "YES" }, { "input": "-66 3 -47 3 -47 22 -66 22\n-52 -2 -45 5 -52 12 -59 5", "output": "YES" }, { "input": "3 37 -1 37 -1 41 3 41\n6 31 9 34 6 37 3 34", "output": "NO" }, { "input": "13 1 15 1 15 3 13 3\n13 19 21 11 13 3 5 11", "output": "YES" }, { "input": "20 8 3 8 3 -9 20 -9\n2 -11 3 -10 2 -9 1 -10", "output": "NO" }, { "input": "3 41 3 21 -17 21 -17 41\n26 12 10 28 26 44 42 28", "output": "NO" }, { "input": "11 11 11 3 3 3 3 11\n-12 26 -27 11 -12 -4 3 11", "output": "YES" }, { "input": "-29 3 -29 12 -38 12 -38 3\n-35 9 -29 15 -23 9 -29 3", "output": "YES" }, { "input": "3 -32 1 -32 1 -30 3 -30\n4 -32 -16 -52 -36 -32 -16 -12", "output": "YES" }, { "input": "-16 -10 -16 9 3 9 3 -10\n-8 -1 2 9 12 -1 2 -11", "output": "YES" }, { "input": "3 -42 -5 -42 -5 -34 3 -34\n-8 -54 -19 -43 -8 -32 3 -43", "output": "YES" }, { "input": "-47 3 -37 3 -37 -7 -47 -7\n-37 3 -33 -1 -37 -5 -41 -1", "output": "YES" }, { "input": "10 3 12 3 12 5 10 5\n12 4 20 12 12 20 4 12", "output": "YES" }, { "input": "3 -41 -9 -41 -9 -53 3 -53\n18 -16 38 -36 18 -56 -2 -36", "output": "YES" }, { "input": "3 40 2 40 2 41 3 41\n22 39 13 48 4 39 13 30", "output": "NO" }, { "input": "21 26 21 44 3 44 3 26\n-20 38 -32 26 -20 14 -8 26", "output": "NO" }, { "input": "0 7 3 7 3 10 0 10\n3 9 -17 29 -37 9 -17 -11", "output": "YES" }, { "input": "3 21 3 18 6 18 6 21\n-27 18 -11 2 5 18 -11 34", "output": "YES" }, { "input": "-29 13 -39 13 -39 3 -29 3\n-36 -4 -50 -18 -36 -32 -22 -18", "output": "NO" }, { "input": "3 -26 -2 -26 -2 -21 3 -21\n-5 -37 -16 -26 -5 -15 6 -26", "output": "YES" }, { "input": "3 9 -1 9 -1 13 3 13\n-9 17 -1 9 -9 1 -17 9", "output": "YES" }, { "input": "48 8 43 8 43 3 48 3\n31 -4 43 8 55 -4 43 -16", "output": "YES" }, { "input": "-3 1 3 1 3 -5 -3 -5\n20 -22 3 -5 20 12 37 -5", "output": "YES" }, { "input": "14 3 14 -16 -5 -16 -5 3\n14 2 15 1 14 0 13 1", "output": "YES" }, { "input": "-10 12 -10 -1 3 -1 3 12\n1 10 -2 7 -5 10 -2 13", "output": "YES" }, { "input": "39 21 21 21 21 3 39 3\n27 3 47 -17 27 -37 7 -17", "output": "YES" }, { "input": "3 1 3 17 -13 17 -13 1\n17 20 10 27 3 20 10 13", "output": "NO" }, { "input": "15 -18 3 -18 3 -6 15 -6\n29 -1 16 -14 3 -1 16 12", "output": "YES" }, { "input": "41 -6 41 3 32 3 32 -6\n33 3 35 5 33 7 31 5", "output": "YES" }, { "input": "7 35 3 35 3 39 7 39\n23 15 3 35 23 55 43 35", "output": "YES" }, { "input": "19 19 35 19 35 3 19 3\n25 -9 16 -18 7 -9 16 0", "output": "NO" }, { "input": "-20 3 -20 9 -26 9 -26 3\n-19 4 -21 2 -19 0 -17 2", "output": "YES" }, { "input": "13 3 22 3 22 -6 13 -6\n26 3 22 -1 18 3 22 7", "output": "YES" }, { "input": "-4 -8 -4 -15 3 -15 3 -8\n-10 5 -27 -12 -10 -29 7 -12", "output": "YES" }, { "input": "3 15 7 15 7 19 3 19\n-12 30 -23 19 -12 8 -1 19", "output": "NO" }, { "input": "-12 3 5 3 5 -14 -12 -14\n-14 22 5 3 24 22 5 41", "output": "YES" }, { "input": "-37 3 -17 3 -17 -17 -37 -17\n-9 -41 9 -23 -9 -5 -27 -23", "output": "YES" }, { "input": "3 57 3 45 -9 45 -9 57\n8 50 21 37 8 24 -5 37", "output": "YES" }, { "input": "42 3 42 -6 33 -6 33 3\n42 4 41 3 40 4 41 5", "output": "YES" }, { "input": "3 59 3 45 -11 45 -11 59\n-2 50 -8 44 -2 38 4 44", "output": "YES" }, { "input": "-51 3 -39 3 -39 15 -51 15\n-39 14 -53 0 -39 -14 -25 0", "output": "YES" }, { "input": "-7 -15 -7 3 11 3 11 -15\n15 -1 22 -8 15 -15 8 -8", "output": "YES" }, { "input": "3 -39 14 -39 14 -50 3 -50\n17 -39 5 -27 -7 -39 5 -51", "output": "YES" }, { "input": "91 -27 91 29 35 29 35 -27\n59 39 95 3 59 -33 23 3", "output": "YES" }, { "input": "-81 -60 -31 -60 -31 -10 -81 -10\n-58 -68 -95 -31 -58 6 -21 -31", "output": "YES" }, { "input": "78 -59 78 -2 21 -2 21 -59\n48 1 86 -37 48 -75 10 -37", "output": "YES" }, { "input": "-38 -26 32 -26 32 44 -38 44\n2 -27 -44 19 2 65 48 19", "output": "YES" }, { "input": "73 -54 73 -4 23 -4 23 -54\n47 1 77 -29 47 -59 17 -29", "output": "YES" }, { "input": "-6 -25 46 -25 46 27 -6 27\n21 -43 -21 -1 21 41 63 -1", "output": "YES" }, { "input": "-17 -91 -17 -27 -81 -27 -81 -91\n-48 -21 -12 -57 -48 -93 -84 -57", "output": "YES" }, { "input": "-7 16 43 16 43 66 -7 66\n18 -7 -27 38 18 83 63 38", "output": "YES" }, { "input": "-46 11 16 11 16 73 -46 73\n-18 -8 -67 41 -18 90 31 41", "output": "YES" }, { "input": "-33 -64 25 -64 25 -6 -33 -6\n-5 -74 -51 -28 -5 18 41 -28", "output": "YES" }, { "input": "99 -100 100 -100 100 -99 99 -99\n99 -99 100 -98 99 -97 98 -98", "output": "YES" }, { "input": "-100 -100 -100 -99 -99 -99 -99 -100\n-10 -10 -9 -9 -10 -8 -11 -9", "output": "NO" }, { "input": "-4 3 -3 3 -3 4 -4 4\n0 -4 4 0 0 4 -4 0", "output": "NO" }, { "input": "0 0 10 0 10 10 0 10\n11 9 13 7 15 9 13 11", "output": "NO" }, { "input": "1 1 1 6 6 6 6 1\n5 8 8 11 11 8 8 5", "output": "NO" }, { "input": "99 99 99 100 100 100 100 99\n-100 0 0 100 100 0 0 -100", "output": "NO" }, { "input": "0 0 0 2 2 2 2 0\n5 1 9 5 5 9 1 5", "output": "NO" }, { "input": "3 2 3 3 4 3 4 2\n0 4 4 0 0 -4 -4 0", "output": "NO" }, { "input": "0 0 2 0 2 2 0 2\n4 1 7 4 4 7 1 4", "output": "NO" }, { "input": "3 6 3 8 5 8 5 6\n2 9 4 11 6 9 4 7", "output": "YES" }, { "input": "0 0 10 0 10 10 0 10\n-1 5 5 -1 11 5 5 11", "output": "YES" }, { "input": "0 0 1 0 1 1 0 1\n3 0 6 3 3 6 0 3", "output": "NO" }, { "input": "3 7 4 7 4 6 3 6\n0 0 10 10 20 0 10 -10", "output": "NO" }, { "input": "0 0 0 1 1 1 1 0\n0 3 3 6 6 3 3 0", "output": "NO" }, { "input": "0 0 0 4 4 4 4 0\n3 6 7 10 11 6 7 2", "output": "NO" }, { "input": "0 0 0 1 1 1 1 0\n0 10 10 0 20 10 10 20", "output": "NO" } ]
1,529,175,746
8,846
Python 3
WRONG_ANSWER
PRETESTS
7
77
0
def area(x1,y1,x2,y2,x3,y3): return abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2) def check(A,x,y,x1,y1,x2,y2,x3,y3,x4,y4): A1 = area(x, y, x1, y1, x2, y2) A2 = area(x, y, x2, y2, x3, y3) A3 = area(x, y, x3, y3, x4, y4) A4 = area(x, y, x1, y1, x4, y4) return (A == A1 + A2 + A3 + A4) x1,y1,x2,y2,x3,y3,x4,y4=map(int,input().split()) xi1,yi1,xi2,yi2,xi3,yi3,xi4,yi4=map(int,input().split()) A = area(x1, y1, x2, y2, x3, y3) + area(x1, y1, x4, y4, x3, y3) Ai = area(xi1, yi1, xi2, yi2, xi3, yi3) + area(xi1, yi1, xi4, yi4, xi3, yi3) # print(A,) if check(A,xi1,yi1,x1,y1,x2,y2,x3,y3,x4,y4) or check(A,xi2,yi2,x1,y1,x2,y2,x3,y3,x4,y4) or check(A,xi3,yi3,x1,y1,x2,y2,x3,y3,x4,y4) or check(A,xi4,yi4,x1,y1,x2,y2,x3,y3,x4,y4): print('YES') elif check(Ai,x1,y1,xi1,yi1,xi2,yi2,xi3,yi3,xi4,yi4) or check(Ai,x2,y2,xi1,yi1,xi2,yi2,xi3,yi3,xi4,yi4) or check(Ai,x3,y3,xi1,yi1,xi2,yi2,xi3,yi3,xi4,yi4) or check(Ai,x4,y4,xi1,yi1,xi2,yi2,xi3,yi3,xi4,yi4): print('YES') else: print('NO')
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input Specification: The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between $-100$ and $100$. Output Specification: Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Demo Input: ['0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1\n', '0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1\n', '6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples:
```python def area(x1,y1,x2,y2,x3,y3): return abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2) def check(A,x,y,x1,y1,x2,y2,x3,y3,x4,y4): A1 = area(x, y, x1, y1, x2, y2) A2 = area(x, y, x2, y2, x3, y3) A3 = area(x, y, x3, y3, x4, y4) A4 = area(x, y, x1, y1, x4, y4) return (A == A1 + A2 + A3 + A4) x1,y1,x2,y2,x3,y3,x4,y4=map(int,input().split()) xi1,yi1,xi2,yi2,xi3,yi3,xi4,yi4=map(int,input().split()) A = area(x1, y1, x2, y2, x3, y3) + area(x1, y1, x4, y4, x3, y3) Ai = area(xi1, yi1, xi2, yi2, xi3, yi3) + area(xi1, yi1, xi4, yi4, xi3, yi3) # print(A,) if check(A,xi1,yi1,x1,y1,x2,y2,x3,y3,x4,y4) or check(A,xi2,yi2,x1,y1,x2,y2,x3,y3,x4,y4) or check(A,xi3,yi3,x1,y1,x2,y2,x3,y3,x4,y4) or check(A,xi4,yi4,x1,y1,x2,y2,x3,y3,x4,y4): print('YES') elif check(Ai,x1,y1,xi1,yi1,xi2,yi2,xi3,yi3,xi4,yi4) or check(Ai,x2,y2,xi1,yi1,xi2,yi2,xi3,yi3,xi4,yi4) or check(Ai,x3,y3,xi1,yi1,xi2,yi2,xi3,yi3,xi4,yi4) or check(Ai,x4,y4,xi1,yi1,xi2,yi2,xi3,yi3,xi4,yi4): print('YES') else: print('NO') ```
0
743
A
Vladik and flights
PROGRAMMING
1,200
[ "constructive algorithms", "greedy", "implementation" ]
null
null
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad. Vladik knows *n* airports. All the airports are located on a straight line. Each airport has unique id from 1 to *n*, Vladik's house is situated next to the airport with id *a*, and the place of the olympiad is situated next to the airport with id *b*. It is possible that Vladik's house and the place of the olympiad are located near the same airport. To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport *a* and finish it at the airport *b*. Each airport belongs to one of two companies. The cost of flight from the airport *i* to the airport *j* is zero if both airports belong to the same company, and |*i*<=-<=*j*| if they belong to different companies. Print the minimum cost Vladik has to pay to get to the olympiad.
The first line contains three integers *n*, *a*, and *b* (1<=≤<=*n*<=≤<=105, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach. The second line contains a string with length *n*, which consists only of characters 0 and 1. If the *i*-th character in this string is 0, then *i*-th airport belongs to first company, otherwise it belongs to the second.
Print single integer — the minimum cost Vladik has to pay to get to the olympiad.
[ "4 1 4\n1010\n", "5 5 2\n10110\n" ]
[ "1", "0" ]
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1. In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
500
[ { "input": "4 1 4\n1010", "output": "1" }, { "input": "5 5 2\n10110", "output": "0" }, { "input": "10 9 5\n1011111001", "output": "1" }, { "input": "7 3 7\n1110111", "output": "0" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "10 3 3\n1001011011", "output": "0" }, { "input": "1 1 1\n0", "output": "0" }, { "input": "10 5 8\n1000001110", "output": "1" }, { "input": "10 1 10\n0000011111", "output": "1" }, { "input": "4 1 4\n0011", "output": "1" }, { "input": "10 3 7\n0000011111", "output": "1" }, { "input": "5 1 5\n11010", "output": "1" }, { "input": "6 1 6\n111000", "output": "1" }, { "input": "2 1 2\n01", "output": "1" }, { "input": "10 10 1\n0000011111", "output": "1" }, { "input": "6 1 6\n000111", "output": "1" }, { "input": "10 2 10\n0000011111", "output": "1" }, { "input": "8 1 8\n11110000", "output": "1" }, { "input": "6 1 5\n100000", "output": "1" }, { "input": "16 4 12\n0000000011111111", "output": "1" }, { "input": "6 1 5\n111000", "output": "1" }, { "input": "8 2 7\n11110000", "output": "1" }, { "input": "6 2 5\n111000", "output": "1" }, { "input": "9 9 1\n111000000", "output": "1" }, { "input": "2 2 1\n01", "output": "1" }, { "input": "5 2 5\n00001", "output": "1" }, { "input": "5 1 5\n10000", "output": "1" }, { "input": "6 1 6\n011111", "output": "1" }, { "input": "5 5 1\n11110", "output": "1" }, { "input": "2 1 2\n10", "output": "1" }, { "input": "4 2 4\n0001", "output": "1" }, { "input": "10 1 10\n1111100000", "output": "1" }, { "input": "8 4 5\n00001111", "output": "1" }, { "input": "4 4 1\n0111", "output": "1" }, { "input": "8 1 8\n00101001", "output": "1" } ]
1,621,609,755
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
46
0
n,m,k=map(int,input().split()) p=input() if p[m-1] == p[k-1]: print(0) else: if p[m-1]=='0' and p[k-1]=='1': print(8) p=p[m-1:k] for i in p: if i=='1': l=p.index(i)+1 break b=l-1 p=list(p) p.reverse() for j in p: if j == '0': c=p.index(j)+1 break v=abs(1-c) print(min(b,v)) elif p[m-1]=='1' and p[k-1]=='0': p=p[m-1:k] for i in p: if i=='0': l=p.index(i)+1 break b=l-1 p=list(p) p.reverse() for j in p: if j == '1': c=p.index(j)+1 break v=abs(1-c) print(min(b,v)) else: pass
Title: Vladik and flights Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad. Vladik knows *n* airports. All the airports are located on a straight line. Each airport has unique id from 1 to *n*, Vladik's house is situated next to the airport with id *a*, and the place of the olympiad is situated next to the airport with id *b*. It is possible that Vladik's house and the place of the olympiad are located near the same airport. To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport *a* and finish it at the airport *b*. Each airport belongs to one of two companies. The cost of flight from the airport *i* to the airport *j* is zero if both airports belong to the same company, and |*i*<=-<=*j*| if they belong to different companies. Print the minimum cost Vladik has to pay to get to the olympiad. Input Specification: The first line contains three integers *n*, *a*, and *b* (1<=≤<=*n*<=≤<=105, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach. The second line contains a string with length *n*, which consists only of characters 0 and 1. If the *i*-th character in this string is 0, then *i*-th airport belongs to first company, otherwise it belongs to the second. Output Specification: Print single integer — the minimum cost Vladik has to pay to get to the olympiad. Demo Input: ['4 1 4\n1010\n', '5 5 2\n10110\n'] Demo Output: ['1', '0'] Note: In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1. In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.
```python n,m,k=map(int,input().split()) p=input() if p[m-1] == p[k-1]: print(0) else: if p[m-1]=='0' and p[k-1]=='1': print(8) p=p[m-1:k] for i in p: if i=='1': l=p.index(i)+1 break b=l-1 p=list(p) p.reverse() for j in p: if j == '0': c=p.index(j)+1 break v=abs(1-c) print(min(b,v)) elif p[m-1]=='1' and p[k-1]=='0': p=p[m-1:k] for i in p: if i=='0': l=p.index(i)+1 break b=l-1 p=list(p) p.reverse() for j in p: if j == '1': c=p.index(j)+1 break v=abs(1-c) print(min(b,v)) else: pass ```
-1
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,689,105,995
2,147,483,647
PyPy 3-64
OK
TESTS
31
218
0
wire_count = int(input()) wires = [x for x in map(int, input().split())] wires.insert(0,0) for _ in range(int(input())): wire, bird = map(int, input().split()) left_remaining_birds = (0 + bird) - 1 right_remaining_birds = wires[wire] - bird if wire == len(wires)-1: wires[wire] = 0 wires[wire - 1] += left_remaining_birds else: wires[wire - 1] += left_remaining_birds wires[wire] = 0 wires[wire + 1] += right_remaining_birds res = "\n".join(map(str, wires[1:])) print(res) # 5 # 58 51 45 27 48 # 5 # 4 9 # 5 15 # 4 5 # 5 8 # 1 43
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 wire_count = int(input()) wires = [x for x in map(int, input().split())] wires.insert(0,0) for _ in range(int(input())): wire, bird = map(int, input().split()) left_remaining_birds = (0 + bird) - 1 right_remaining_birds = wires[wire] - bird if wire == len(wires)-1: wires[wire] = 0 wires[wire - 1] += left_remaining_birds else: wires[wire - 1] += left_remaining_birds wires[wire] = 0 wires[wire + 1] += right_remaining_birds res = "\n".join(map(str, wires[1:])) print(res) # 5 # 58 51 45 27 48 # 5 # 4 9 # 5 15 # 4 5 # 5 8 # 1 43 ```
3
960
B
Minimize the error
PROGRAMMING
1,500
[ "data structures", "greedy", "sortings" ]
null
null
You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1. Output the minimum possible value of error after *k*1 operations on array *A* and *k*2 operations on array *B* have been performed.
The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively. Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — array *A*. Third line contains *n* space separated integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=106<=≤<=*b**i*<=≤<=106)— array *B*.
Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*.
[ "2 0 0\n1 2\n2 3\n", "2 1 0\n1 2\n2 2\n", "2 5 7\n3 4\n14 4\n" ]
[ "2", "0", "1" ]
In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E* = (1 - 2)<sup class="upper-index">2</sup> + (2 - 3)<sup class="upper-index">2</sup> = 2. In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we increment the first element of *A* by 1. Now, *A* = [2, 2]. The error is now *E* = (2 - 2)<sup class="upper-index">2</sup> + (2 - 2)<sup class="upper-index">2</sup> = 0. This is the minimum possible error obtainable. In the third sample case, we can increase the first element of *A* to 8, using the all of the 5 moves available to us. Also, the first element of *B* can be reduced to 8 using the 6 of the 7 available moves. Now *A* = [8, 4] and *B* = [8, 4]. The error is now *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 4)<sup class="upper-index">2</sup> = 0, but we are still left with 1 move for array *B*. Increasing the second element of *B* to 5 using the left move, we get *B* = [8, 5] and *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 5)<sup class="upper-index">2</sup> = 1.
1,000
[ { "input": "2 0 0\n1 2\n2 3", "output": "2" }, { "input": "2 1 0\n1 2\n2 2", "output": "0" }, { "input": "2 5 7\n3 4\n14 4", "output": "1" }, { "input": "2 0 1\n1 2\n2 2", "output": "0" }, { "input": "2 1 1\n0 0\n1 1", "output": "0" }, { "input": "5 5 5\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "3 4 5\n1 2 3\n3 2 1", "output": "1" }, { "input": "3 1000 0\n1 2 3\n-1000 -1000 -1000", "output": "1341346" }, { "input": "10 300 517\n-6 -2 6 5 -3 8 9 -10 8 6\n5 -9 -2 6 1 4 6 -2 5 -3", "output": "1" }, { "input": "10 819 133\n87 22 30 89 82 -97 -52 25 76 -22\n-20 95 21 25 2 -3 45 -7 -98 -56", "output": "0" }, { "input": "10 10 580\n302 -553 -281 -299 -270 -890 -989 -749 -418 486\n735 330 6 725 -984 209 -855 -786 -502 967", "output": "2983082" }, { "input": "10 403 187\n9691 -3200 3016 3540 -9475 8840 -4705 7940 6293 -2631\n-2288 9129 4067 696 -6754 9869 -5747 701 3344 -3426", "output": "361744892" }, { "input": "10 561 439\n76639 67839 10670 -23 -18393 65114 46538 67596 86615 90480\n50690 620 -33631 -75857 75634 91321 -81662 -93668 -98557 -43621", "output": "116776723778" }, { "input": "10 765 62\n-929885 -995154 254071 -370672 -435272 584846 -301610 -234118 -82557 743536\n-36327 439149 -977780 -821019 -585558 953598 -151943 140715 -311253 -383103", "output": "6216649853365" }, { "input": "22 334 246\n-462653 -618002 4973 -348485 366658 192390 274752 200590 138367 779540 -661269 642587 113645 -110388 -604418 -491231 -933401 -219332 -603140 836439 167007 210226\n357638 -646669 -558432 -434313 -285851 -119233 323088 -512237 -729293 215256 39316 -984201 -209814 715016 -271932 796550 988227 -89577 67202 462973 -942079 -823339", "output": "15389604923763" }, { "input": "1 1000 0\n1000000\n-1000000", "output": "3996001000000" }, { "input": "1 1000 0\n1000000\n1000000", "output": "0" }, { "input": "1 0 1000\n-1000000\n1000000", "output": "3996001000000" }, { "input": "1 0 1000\n1000000\n1000000", "output": "0" }, { "input": "1 5 7\n1\n2", "output": "1" }, { "input": "2 1 3\n2 2\n2 2", "output": "0" }, { "input": "3 3 0\n1 1 1\n1 1 1", "output": "1" }, { "input": "1 0 6\n0\n0", "output": "0" }, { "input": "2 1 1\n2 2\n0 0", "output": "2" }, { "input": "3 1 4\n0 0 0\n1 5 6", "output": "19" }, { "input": "1 1 2\n0\n8", "output": "25" }, { "input": "2 2 0\n3 3\n3 3", "output": "0" } ]
1,603,129,105
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
109
307,200
# -*- coding: utf-8 -*- """ Created on Mon Oct 19 22:22:28 2020 @author: Dark Soul """ [n,k1,k2]=list(map(int,input().split())) a=list(map(int,input().split())) b=list(map(int,input().split())) diff=[0]*n for i in range(n): diff[i]=abs(a[i]-b[i]) diff.sort(reverse=True) bodla=k1+k2 while(k1): for i in range(n): if diff[i]>0: diff[i]-=1 k1-=1 if k1==0: break if max(diff)==0: if k1%2: k1=1 else: k1=0 break while(k2): for i in range(n): if diff[i]>0: diff[i]-=1 k2-=1 if k2==0: break if max(diff)==0: if k2%2: k2=1 else: k2=0 break diff.sort() if (k1+k2)%2: diff[0]+=1 ans=0 for i in diff: ans+=i*i print(ans)
Title: Minimize the error Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1. Output the minimum possible value of error after *k*1 operations on array *A* and *k*2 operations on array *B* have been performed. Input Specification: The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively. Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — array *A*. Third line contains *n* space separated integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=106<=≤<=*b**i*<=≤<=106)— array *B*. Output Specification: Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. Demo Input: ['2 0 0\n1 2\n2 3\n', '2 1 0\n1 2\n2 2\n', '2 5 7\n3 4\n14 4\n'] Demo Output: ['2', '0', '1'] Note: In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E* = (1 - 2)<sup class="upper-index">2</sup> + (2 - 3)<sup class="upper-index">2</sup> = 2. In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we increment the first element of *A* by 1. Now, *A* = [2, 2]. The error is now *E* = (2 - 2)<sup class="upper-index">2</sup> + (2 - 2)<sup class="upper-index">2</sup> = 0. This is the minimum possible error obtainable. In the third sample case, we can increase the first element of *A* to 8, using the all of the 5 moves available to us. Also, the first element of *B* can be reduced to 8 using the 6 of the 7 available moves. Now *A* = [8, 4] and *B* = [8, 4]. The error is now *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 4)<sup class="upper-index">2</sup> = 0, but we are still left with 1 move for array *B*. Increasing the second element of *B* to 5 using the left move, we get *B* = [8, 5] and *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 5)<sup class="upper-index">2</sup> = 1.
```python # -*- coding: utf-8 -*- """ Created on Mon Oct 19 22:22:28 2020 @author: Dark Soul """ [n,k1,k2]=list(map(int,input().split())) a=list(map(int,input().split())) b=list(map(int,input().split())) diff=[0]*n for i in range(n): diff[i]=abs(a[i]-b[i]) diff.sort(reverse=True) bodla=k1+k2 while(k1): for i in range(n): if diff[i]>0: diff[i]-=1 k1-=1 if k1==0: break if max(diff)==0: if k1%2: k1=1 else: k1=0 break while(k2): for i in range(n): if diff[i]>0: diff[i]-=1 k2-=1 if k2==0: break if max(diff)==0: if k2%2: k2=1 else: k2=0 break diff.sort() if (k1+k2)%2: diff[0]+=1 ans=0 for i in diff: ans+=i*i print(ans) ```
0
102
B
Sum of Digits
PROGRAMMING
1,000
[ "implementation" ]
B. Sum of Digits
2
265
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
[ "0\n", "10\n", "991\n" ]
[ "0\n", "1\n", "3\n" ]
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
1,000
[ { "input": "0", "output": "0" }, { "input": "10", "output": "1" }, { "input": "991", "output": "3" }, { "input": "99", "output": "2" }, { "input": "100", "output": "1" }, { "input": "123456789", "output": "2" }, { "input": "32", "output": "1" }, { "input": "86", "output": "2" }, { "input": "2", "output": "0" }, { "input": "8", "output": "0" }, { "input": "34", "output": "1" }, { "input": "13", "output": "1" }, { "input": "28", "output": "2" }, { "input": "23", "output": "1" }, { "input": "57", "output": "2" }, { "input": "29", "output": "2" }, { "input": "353869285", "output": "3" }, { "input": "549548646", "output": "2" }, { "input": "858893424", "output": "2" }, { "input": "644818852", "output": "3" }, { "input": "360322525", "output": "3" }, { "input": "122937520", "output": "2" }, { "input": "288403032", "output": "2" }, { "input": "677257481", "output": "3" }, { "input": "58059561", "output": "3" }, { "input": "211288847", "output": "2" }, { "input": "339900034079539584", "output": "2" }, { "input": "784084029310269952", "output": "3" }, { "input": "774730557264864000", "output": "3" }, { "input": "478233807148352256", "output": "3" }, { "input": "165646874056812544", "output": "3" }, { "input": "477533739511673792", "output": "3" }, { "input": "660119944377002240", "output": "3" }, { "input": "448375218506078080", "output": "3" }, { "input": "77213334785795616", "output": "3" }, { "input": "165767221702271872", "output": "3" }, { "input": "1", "output": "0" }, { "input": "5", "output": "0" }, { "input": "8", "output": "0" }, { "input": "156161456146164104103460452045416165146141414651641564105461465156445621465146514562146145465165145145614561465145614561", "output": "3" }, { "input": "9", "output": "0" } ]
1,600,456,268
2,147,483,647
PyPy 3
OK
TESTS
51
748
8,806,400
s=input() def summer(s): mst=list(s) sm=0 for i in range(len(mst)): sm=sm+int(mst[i]) return str(sm) cn=0 while(int(s)>9): s=summer(s) cn=cn+1 print(cn)
Title: Sum of Digits Time Limit: 2 seconds Memory Limit: 265 megabytes Problem Description: Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit? Input Specification: The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. Output Specification: Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Demo Input: ['0\n', '10\n', '991\n'] Demo Output: ['0\n', '1\n', '3\n'] Note: In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
```python s=input() def summer(s): mst=list(s) sm=0 for i in range(len(mst)): sm=sm+int(mst[i]) return str(sm) cn=0 while(int(s)>9): s=summer(s) cn=cn+1 print(cn) ```
3.797154
996
B
World Cup
PROGRAMMING
1,300
[ "binary search", "math" ]
null
null
Allen wants to enter a fan zone that occupies a round square and has $n$ entrances. There already is a queue of $a_i$ people in front of the $i$-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute. Allen uses the following strategy to enter the fan zone: - Initially he stands in the end of the queue in front of the first entrance. - Each minute, if he is not allowed into the fan zone during the minute (meaning he is not the first in the queue), he leaves the current queue and stands in the end of the queue of the next entrance (or the first entrance if he leaves the last entrance). Determine the entrance through which Allen will finally enter the fan zone.
The first line contains a single integer $n$ ($2 \le n \le 10^5$) — the number of entrances. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) — the number of people in queues. These numbers do not include Allen.
Print a single integer — the number of entrance that Allen will use.
[ "4\n2 3 2 0\n", "2\n10 10\n", "6\n5 2 6 5 7 4\n" ]
[ "3\n", "1\n", "6\n" ]
In the first example the number of people (not including Allen) changes as follows: $[\textbf{2}, 3, 2, 0] \to [1, \textbf{2}, 1, 0] \to [0, 1, \textbf{0}, 0]$. The number in bold is the queue Alles stands in. We see that he will enter the fan zone through the third entrance. In the second example the number of people (not including Allen) changes as follows: $[\textbf{10}, 10] \to [9, \textbf{9}] \to [\textbf{8}, 8] \to [7, \textbf{7}] \to [\textbf{6}, 6] \to \\ [5, \textbf{5}] \to [\textbf{4}, 4] \to [3, \textbf{3}] \to [\textbf{2}, 2] \to [1, \textbf{1}] \to [\textbf{0}, 0]$. In the third example the number of people (not including Allen) changes as follows: $[\textbf{5}, 2, 6, 5, 7, 4] \to [4, \textbf{1}, 5, 4, 6, 3] \to [3, 0, \textbf{4}, 3, 5, 2] \to \\ [2, 0, 3, \textbf{2}, 4, 1] \to [1, 0, 2, 1, \textbf{3}, 0] \to [0, 0, 1, 0, 2, \textbf{0}]$.
1,000
[ { "input": "4\n2 3 2 0", "output": "3" }, { "input": "2\n10 10", "output": "1" }, { "input": "6\n5 2 6 5 7 4", "output": "6" }, { "input": "2\n483544186 940350702", "output": "1" }, { "input": "10\n3 3 3 5 6 9 3 1 7 3", "output": "7" }, { "input": "10\n0 8 45 88 48 68 28 55 17 24", "output": "1" }, { "input": "100\n8 8 9 10 6 8 2 4 2 2 10 6 6 10 10 2 3 5 1 2 10 4 2 0 9 4 9 3 0 6 3 2 3 10 10 6 4 6 4 4 2 5 1 4 1 1 9 8 9 5 3 5 5 4 5 5 6 5 3 3 7 2 0 10 9 7 7 3 5 1 0 9 6 3 1 3 4 4 3 6 3 2 1 4 10 2 3 4 4 3 6 7 6 2 1 7 0 6 8 10", "output": "7" }, { "input": "10\n5 6 7 8 9 10 11 12 13 14", "output": "1" }, { "input": "10\n15 14 13 12 11 10 9 8 7 6", "output": "9" }, { "input": "2\n1000000000 1000000000", "output": "1" }, { "input": "3\n3 3 1", "output": "3" }, { "input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1" }, { "input": "3\n15 8 9", "output": "2" }, { "input": "3\n5 5 5", "output": "3" }, { "input": "3\n41 5 6", "output": "2" }, { "input": "2\n999999999 1000000000", "output": "1" }, { "input": "2\n0 1", "output": "1" }, { "input": "3\n3 2 3", "output": "1" }, { "input": "3\n8 5 8", "output": "2" }, { "input": "4\n5 2 3 4", "output": "2" }, { "input": "2\n0 0", "output": "1" }, { "input": "2\n3 3", "output": "2" }, { "input": "4\n9 2 4 7", "output": "2" }, { "input": "30\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "11" }, { "input": "4\n11 10 12 12", "output": "1" }, { "input": "2\n1 0", "output": "2" }, { "input": "6\n7 2 6 5 7 9", "output": "2" }, { "input": "3\n1000000000 1000000000 1000000000", "output": "2" }, { "input": "2\n999999999 999999699", "output": "2" }, { "input": "5\n5 5 5 5 5", "output": "1" }, { "input": "2\n1 1", "output": "2" } ]
1,694,235,989
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
36
93
13,619,200
# -*- coding:utf-8 -*- # author : utoppia # description : solutions for codeforces # updated at : 2023-09-08 22:05:41 # ----------------------------------------------------- # File Name : $%file%$ # Language : Python # ---------------------------------------------------- def read_int(): return int(input()) def read_list(): return list(map(int, input().split())) def main(): solve() def solve(): n = read_int() a = read_list() max_time, ans = 10**9, -1 for i, t in enumerate(a): # i + n * p >= t p = (t - i) // n + (0 if (t - i) % n == 0 else 1) if i + n * p < max_time: max_time = i + n * p ans = i print(ans + 1) if __name__ == "__main__": main()
Title: World Cup Time Limit: None seconds Memory Limit: None megabytes Problem Description: Allen wants to enter a fan zone that occupies a round square and has $n$ entrances. There already is a queue of $a_i$ people in front of the $i$-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute. Allen uses the following strategy to enter the fan zone: - Initially he stands in the end of the queue in front of the first entrance. - Each minute, if he is not allowed into the fan zone during the minute (meaning he is not the first in the queue), he leaves the current queue and stands in the end of the queue of the next entrance (or the first entrance if he leaves the last entrance). Determine the entrance through which Allen will finally enter the fan zone. Input Specification: The first line contains a single integer $n$ ($2 \le n \le 10^5$) — the number of entrances. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) — the number of people in queues. These numbers do not include Allen. Output Specification: Print a single integer — the number of entrance that Allen will use. Demo Input: ['4\n2 3 2 0\n', '2\n10 10\n', '6\n5 2 6 5 7 4\n'] Demo Output: ['3\n', '1\n', '6\n'] Note: In the first example the number of people (not including Allen) changes as follows: $[\textbf{2}, 3, 2, 0] \to [1, \textbf{2}, 1, 0] \to [0, 1, \textbf{0}, 0]$. The number in bold is the queue Alles stands in. We see that he will enter the fan zone through the third entrance. In the second example the number of people (not including Allen) changes as follows: $[\textbf{10}, 10] \to [9, \textbf{9}] \to [\textbf{8}, 8] \to [7, \textbf{7}] \to [\textbf{6}, 6] \to \\ [5, \textbf{5}] \to [\textbf{4}, 4] \to [3, \textbf{3}] \to [\textbf{2}, 2] \to [1, \textbf{1}] \to [\textbf{0}, 0]$. In the third example the number of people (not including Allen) changes as follows: $[\textbf{5}, 2, 6, 5, 7, 4] \to [4, \textbf{1}, 5, 4, 6, 3] \to [3, 0, \textbf{4}, 3, 5, 2] \to \\ [2, 0, 3, \textbf{2}, 4, 1] \to [1, 0, 2, 1, \textbf{3}, 0] \to [0, 0, 1, 0, 2, \textbf{0}]$.
```python # -*- coding:utf-8 -*- # author : utoppia # description : solutions for codeforces # updated at : 2023-09-08 22:05:41 # ----------------------------------------------------- # File Name : $%file%$ # Language : Python # ---------------------------------------------------- def read_int(): return int(input()) def read_list(): return list(map(int, input().split())) def main(): solve() def solve(): n = read_int() a = read_list() max_time, ans = 10**9, -1 for i, t in enumerate(a): # i + n * p >= t p = (t - i) // n + (0 if (t - i) % n == 0 else 1) if i + n * p < max_time: max_time = i + n * p ans = i print(ans + 1) if __name__ == "__main__": main() ```
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,609,304,043
2,147,483,647
Python 3
OK
TESTS
30
218
0
s = input() lst = [a for a in s] lower = upper = 0 for i in lst: if i.islower(): lower+=1 else: upper+=1 if upper>lower: print(s.upper()) else: print(s.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python s = input() lst = [a for a in s] lower = upper = 0 for i in lst: if i.islower(): lower+=1 else: upper+=1 if upper>lower: print(s.upper()) else: print(s.lower()) ```
3.9455
376
A
Lever
PROGRAMMING
900
[ "implementation", "math" ]
null
null
You have a description of a lever as string *s*. We'll represent the string length as record |*s*|, then the lever looks as a horizontal bar with weights of length |*s*|<=-<=1 with exactly one pivot. We will assume that the bar is a segment on the *Ox* axis between points 0 and |*s*|<=-<=1. The decoding of the lever description is given below. - If the *i*-th character of the string equals "^", that means that at coordinate *i* there is the pivot under the bar. - If the *i*-th character of the string equals "=", that means that at coordinate *i* there is nothing lying on the bar. - If the *i*-th character of the string equals digit *c* (1-9), that means that at coordinate *i* there is a weight of mass *c* on the bar. Your task is, given the lever description, print if it will be in balance or not. Assume that the bar doesn't weight anything. Assume that the bar initially is in balance then all weights are simultaneously put on it. After that the bar either tilts to the left, or tilts to the right, or is in balance.
The first line contains the lever description as a non-empty string *s* (3<=≤<=|*s*|<=≤<=106), consisting of digits (1-9) and characters "^" and "=". It is guaranteed that the line contains exactly one character "^". It is guaranteed that the pivot of the lever isn't located in any end of the lever bar. To solve the problem you may need 64-bit integer numbers. Please, do not forget to use them in your programs.
Print "left" if the given lever tilts to the left, "right" if it tilts to the right and "balance", if it is in balance.
[ "=^==\n", "9===^==1\n", "2==^7==\n", "41^52==\n" ]
[ "balance\n", "left\n", "right\n", "balance\n" ]
As you solve the problem, you may find the following link useful to better understand how a lever functions: http://en.wikipedia.org/wiki/Lever. The pictures to the examples:
500
[ { "input": "=^==", "output": "balance" }, { "input": "9===^==1", "output": "left" }, { "input": "2==^7==", "output": "right" }, { "input": "41^52==", "output": "balance" }, { "input": "=^2=4=1===1=", "output": "right" }, { "input": "9=6===5==3=9=1=1^7=1==", "output": "left" }, { "input": "85=61=36=^93===4==44==35==94===39===15===", "output": "right" }, { "input": "==88=^95==83=45===8====73===7==7====1=29====29=8=85=", "output": "right" }, { "input": "==41^52==", "output": "balance" }, { "input": "2===================^2", "output": "left" }, { "input": "9^=============1", "output": "right" }, { "input": "4=========^=55", "output": "left" }, { "input": "123^321", "output": "balance" }, { "input": "7^1=2", "output": "balance" }, { "input": "589==^==958", "output": "right" } ]
1,606,478,984
2,147,483,647
PyPy 3
OK
TESTS
60
233
7,270,400
s=input().split('^') ans1=0 ans2=0 lefto=s[0] righto=s[1] for j in range(0,len(lefto)): if(lefto[j]=='='): continue else: ans1+=int(lefto[j])*(len(lefto)-j) for j in range(0,len(righto)): if(righto[j]=='='): continue else: ans2+=int(righto[j])*(j+1) if(ans1==ans2 and ans1==0): print("balance") elif(ans1>ans2): print("left") elif(ans2>ans1): print("right") else: print("balance")
Title: Lever Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a description of a lever as string *s*. We'll represent the string length as record |*s*|, then the lever looks as a horizontal bar with weights of length |*s*|<=-<=1 with exactly one pivot. We will assume that the bar is a segment on the *Ox* axis between points 0 and |*s*|<=-<=1. The decoding of the lever description is given below. - If the *i*-th character of the string equals "^", that means that at coordinate *i* there is the pivot under the bar. - If the *i*-th character of the string equals "=", that means that at coordinate *i* there is nothing lying on the bar. - If the *i*-th character of the string equals digit *c* (1-9), that means that at coordinate *i* there is a weight of mass *c* on the bar. Your task is, given the lever description, print if it will be in balance or not. Assume that the bar doesn't weight anything. Assume that the bar initially is in balance then all weights are simultaneously put on it. After that the bar either tilts to the left, or tilts to the right, or is in balance. Input Specification: The first line contains the lever description as a non-empty string *s* (3<=≤<=|*s*|<=≤<=106), consisting of digits (1-9) and characters "^" and "=". It is guaranteed that the line contains exactly one character "^". It is guaranteed that the pivot of the lever isn't located in any end of the lever bar. To solve the problem you may need 64-bit integer numbers. Please, do not forget to use them in your programs. Output Specification: Print "left" if the given lever tilts to the left, "right" if it tilts to the right and "balance", if it is in balance. Demo Input: ['=^==\n', '9===^==1\n', '2==^7==\n', '41^52==\n'] Demo Output: ['balance\n', 'left\n', 'right\n', 'balance\n'] Note: As you solve the problem, you may find the following link useful to better understand how a lever functions: http://en.wikipedia.org/wiki/Lever. The pictures to the examples:
```python s=input().split('^') ans1=0 ans2=0 lefto=s[0] righto=s[1] for j in range(0,len(lefto)): if(lefto[j]=='='): continue else: ans1+=int(lefto[j])*(len(lefto)-j) for j in range(0,len(righto)): if(righto[j]=='='): continue else: ans2+=int(righto[j])*(j+1) if(ans1==ans2 and ans1==0): print("balance") elif(ans1>ans2): print("left") elif(ans2>ans1): print("right") else: print("balance") ```
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,606,914,545
2,147,483,647
PyPy 3
OK
TESTS
45
155
0
l=int(input()) p=int(input()) q=int(input()) ans=round(((l*p)/(p+q)),8) print(ans)
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()) ans=round(((l*p)/(p+q)),8) print(ans) ```
3
202
A
LLPS
PROGRAMMING
800
[ "binary search", "bitmasks", "brute force", "greedy", "implementation", "strings" ]
null
null
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*s**p*2... *s**p**k* (1 <=≤<= *p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k* <=≤<= |*s*|) a subsequence of string *s* = *s*1*s*2... *s*|*s*|, where |*s*| is the length of string *s*. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba". String *x* = *x*1*x*2... *x*|*x*| is lexicographically larger than string *y* = *y*1*y*2... *y*|*y*| if either |*x*| &gt; |*y*| and *x*1<==<=*y*1, *x*2<==<=*y*2, ...,<=*x*|*y*|<==<=*y*|*y*|, or there exists such number *r* (*r*<=&lt;<=|*x*|, *r*<=&lt;<=|*y*|) that *x*1<==<=*y*1, *x*2<==<=*y*2, ..., *x**r*<==<=*y**r* and *x**r*<=<=+<=<=1<=&gt;<=*y**r*<=<=+<=<=1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post". String *s* = *s*1*s*2... *s*|*s*| is a palindrome if it matches string *rev*(*s*) = *s*|*s*|*s*|*s*|<=-<=1... *s*1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z".
The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10.
Print the lexicographically largest palindromic subsequence of string *s*.
[ "radar\n", "bowwowwow\n", "codeforces\n", "mississipp\n" ]
[ "rr\n", "wwwww\n", "s\n", "ssss\n" ]
Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".
500
[ { "input": "radar", "output": "rr" }, { "input": "bowwowwow", "output": "wwwww" }, { "input": "codeforces", "output": "s" }, { "input": "mississipp", "output": "ssss" }, { "input": "tourist", "output": "u" }, { "input": "romka", "output": "r" }, { "input": "helloworld", "output": "w" }, { "input": "zzzzzzzazz", "output": "zzzzzzzzz" }, { "input": "testcase", "output": "tt" }, { "input": "hahahahaha", "output": "hhhhh" }, { "input": "abbbbbbbbb", "output": "bbbbbbbbb" }, { "input": "zaz", "output": "zz" }, { "input": "aza", "output": "z" }, { "input": "dcbaedcba", "output": "e" }, { "input": "abcdeabcd", "output": "e" }, { "input": "edcbabcde", "output": "ee" }, { "input": "aaaaaaaaab", "output": "b" }, { "input": "testzzzzzz", "output": "zzzzzz" }, { "input": "zzzzzzwait", "output": "zzzzzz" }, { "input": "rrrrrqponm", "output": "rrrrr" }, { "input": "zzyzyy", "output": "zzz" }, { "input": "aababb", "output": "bbb" }, { "input": "zanzibar", "output": "zz" }, { "input": "hhgfedcbaa", "output": "hh" }, { "input": "aabcdefghh", "output": "hh" }, { "input": "aruaru", "output": "uu" }, { "input": "uraura", "output": "uu" }, { "input": "aru", "output": "u" }, { "input": "aburvabur", "output": "v" }, { "input": "ura", "output": "u" }, { "input": "eurottat", "output": "u" }, { "input": "referee", "output": "rr" }, { "input": "joking", "output": "o" }, { "input": "seriously", "output": "y" }, { "input": "sets", "output": "t" }, { "input": "test", "output": "tt" }, { "input": "klmgameklm", "output": "mmm" }, { "input": "dfkjafdkdd", "output": "kk" }, { "input": "zzzzzzzzzz", "output": "zzzzzzzzzz" }, { "input": "aaaaaaaaaa", "output": "aaaaaaaaaa" }, { "input": "buzz", "output": "zz" }, { "input": "b", "output": "b" }, { "input": "y", "output": "y" }, { "input": "yy", "output": "yy" }, { "input": "zz", "output": "zz" }, { "input": "bb", "output": "bb" }, { "input": "aa", "output": "aa" }, { "input": "a", "output": "a" }, { "input": "z", "output": "z" }, { "input": "zz", "output": "zz" }, { "input": "zzazazzzaz", "output": "zzzzzzz" }, { "input": "hellhellhe", "output": "llll" }, { "input": "hellohello", "output": "oo" }, { "input": "refer", "output": "rr" } ]
1,679,519,000
2,147,483,647
Python 3
OK
TESTS
54
92
0
from math import sqrt def generate_subsequences(s, memo=[]): if len(s) == 1: memo.append(s) return [s] else: first_letter = s[0] smaller_subs = generate_subsequences(s[1:]).copy() for subs in smaller_subs: memo.append(first_letter + subs) memo.append(first_letter) return memo def llps(s): s_subseq = generate_subsequences(s) max_subseq = '' for s in s_subseq: if s > max_subseq and s == s[::-1]: max_subseq = s return max_subseq def main(): s = input() print(llps(s)) if __name__ == '__main__': main()
Title: LLPS Time Limit: None seconds Memory Limit: None megabytes Problem Description: This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*s**p*2... *s**p**k* (1 <=≤<= *p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k* <=≤<= |*s*|) a subsequence of string *s* = *s*1*s*2... *s*|*s*|, where |*s*| is the length of string *s*. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba". String *x* = *x*1*x*2... *x*|*x*| is lexicographically larger than string *y* = *y*1*y*2... *y*|*y*| if either |*x*| &gt; |*y*| and *x*1<==<=*y*1, *x*2<==<=*y*2, ...,<=*x*|*y*|<==<=*y*|*y*|, or there exists such number *r* (*r*<=&lt;<=|*x*|, *r*<=&lt;<=|*y*|) that *x*1<==<=*y*1, *x*2<==<=*y*2, ..., *x**r*<==<=*y**r* and *x**r*<=<=+<=<=1<=&gt;<=*y**r*<=<=+<=<=1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post". String *s* = *s*1*s*2... *s*|*s*| is a palindrome if it matches string *rev*(*s*) = *s*|*s*|*s*|*s*|<=-<=1... *s*1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z". Input Specification: The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. Output Specification: Print the lexicographically largest palindromic subsequence of string *s*. Demo Input: ['radar\n', 'bowwowwow\n', 'codeforces\n', 'mississipp\n'] Demo Output: ['rr\n', 'wwwww\n', 's\n', 'ssss\n'] Note: Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".
```python from math import sqrt def generate_subsequences(s, memo=[]): if len(s) == 1: memo.append(s) return [s] else: first_letter = s[0] smaller_subs = generate_subsequences(s[1:]).copy() for subs in smaller_subs: memo.append(first_letter + subs) memo.append(first_letter) return memo def llps(s): s_subseq = generate_subsequences(s) max_subseq = '' for s in s_subseq: if s > max_subseq and s == s[::-1]: max_subseq = s return max_subseq def main(): s = input() print(llps(s)) if __name__ == '__main__': main() ```
3
495
B
Modular Equations
PROGRAMMING
1,600
[ "math", "number theory" ]
null
null
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which *a* and *b* are two non-negative integers and *x* is a variable. We call a positive integer *x* for which a solution of our equation. Hamed didn't pay much attention to the class since he was watching a movie. He only managed to understand the definitions of these equations. Now he wants to write his math exercises but since he has no idea how to do that, he asked you for help. He has told you all he knows about Modular Equations and asked you to write a program which given two numbers *a* and *b* determines how many answers the Modular Equation has.
In the only line of the input two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=109) are given.
If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation .
[ "21 5\n", "9435152 272\n", "10 10\n" ]
[ "2\n", "282\n", "infinity\n" ]
In the first sample the answers of the Modular Equation are 8 and 16 since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6f5ff39ebd209bf990adaf91f4b82f9687097224.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "21 5", "output": "2" }, { "input": "9435152 272", "output": "282" }, { "input": "10 10", "output": "infinity" }, { "input": "0 1000000000", "output": "0" }, { "input": "11 2", "output": "2" }, { "input": "1 0", "output": "1" }, { "input": "0 0", "output": "infinity" }, { "input": "121 0", "output": "3" }, { "input": "772930485 686893955", "output": "0" }, { "input": "257424 24", "output": "127" }, { "input": "295138437 589952171", "output": "0" }, { "input": "223093836 966", "output": "399" }, { "input": "233758336 10665466", "output": "13" }, { "input": "223092887 17", "output": "500" }, { "input": "223094728 1858", "output": "371" }, { "input": "223092899 29", "output": "495" }, { "input": "997920 0", "output": "240" }, { "input": "887043 3", "output": "213" }, { "input": "124 24", "output": "3" }, { "input": "982901 101", "output": "193" }, { "input": "357987 35", "output": "45" }, { "input": "954374 1030", "output": "32" }, { "input": "49106 46", "output": "15" }, { "input": "325508499 119510657", "output": "1" }, { "input": "89768760 885778845", "output": "0" }, { "input": "944387968 700818251", "output": "0" }, { "input": "12 3", "output": "1" }, { "input": "1000000000 1", "output": "19" }, { "input": "923456789 3", "output": "14" }, { "input": "1000000000 6", "output": "6" }, { "input": "1000000000 333333300", "output": "2" }, { "input": "5 2", "output": "1" }, { "input": "1 10", "output": "0" }, { "input": "15 3", "output": "3" }, { "input": "2 0", "output": "2" }, { "input": "77 75", "output": "0" }, { "input": "1000000000 1000000000", "output": "infinity" } ]
1,674,413,677
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
3
592
77,414,400
a=input().split() a=list(map(int,a)) b=a[0]-a[1] l=[0 for c in range(b)] cont=0 for c in range(int(b**(1/2))): k=b%(c+1) if k!=0: continue elif (c+1)>a[1]: cont+=2 elif b/(c+1)>a[1]: cont+=1 if b==0: print('infinity') else: print(cont)
Title: Modular Equations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which *a* and *b* are two non-negative integers and *x* is a variable. We call a positive integer *x* for which a solution of our equation. Hamed didn't pay much attention to the class since he was watching a movie. He only managed to understand the definitions of these equations. Now he wants to write his math exercises but since he has no idea how to do that, he asked you for help. He has told you all he knows about Modular Equations and asked you to write a program which given two numbers *a* and *b* determines how many answers the Modular Equation has. Input Specification: In the only line of the input two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=109) are given. Output Specification: If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation . Demo Input: ['21 5\n', '9435152 272\n', '10 10\n'] Demo Output: ['2\n', '282\n', 'infinity\n'] Note: In the first sample the answers of the Modular Equation are 8 and 16 since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6f5ff39ebd209bf990adaf91f4b82f9687097224.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python a=input().split() a=list(map(int,a)) b=a[0]-a[1] l=[0 for c in range(b)] cont=0 for c in range(int(b**(1/2))): k=b%(c+1) if k!=0: continue elif (c+1)>a[1]: cont+=2 elif b/(c+1)>a[1]: cont+=1 if b==0: print('infinity') else: print(cont) ```
-1
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,695,659,208
2,147,483,647
Python 3
OK
TESTS
48
46
0
x1,x2,x3=map(int,input().split()) list1=[x1,x2,x3] list1.sort() dis=(list1[1]-list1[0])+(list1[2]-list1[1]) print(dis)
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()) list1=[x1,x2,x3] list1.sort() dis=(list1[1]-list1[0])+(list1[2]-list1[1]) print(dis) ```
3
2
A
Winner
PROGRAMMING
1,500
[ "hashing", "implementation" ]
A. Winner
1
64
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Print the name of the winner.
[ "3\nmike 3\nandrew 5\nmike 2\n", "3\nandrew 3\nandrew 2\nmike 5\n" ]
[ "andrew\n", "andrew\n" ]
none
0
[ { "input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew" }, { "input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew" }, { "input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "output": "kaxqybeultn" }, { "input": "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734", "output": "ksjuuerbnlklcfdjeyq" }, { "input": "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879", "output": "fcgslzkicjrpbqaifgweyzreajjfdo" }, { "input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735", "output": "aawtvezfntstrcpgbzjbf" }, { "input": "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158", "output": "ivhgbxiv" } ]
1,510,958,690
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
154
102,400
from collections import Counter def main(): n = int(input().strip()) i = 0 scores = Counter() max_score = 0 max_score_guy = None while i < n: name, score = input().strip().split(' ') score = int(score) scores[name] += score if max_score < scores[name]: max_score_guy = name max_score = scores[name] i += 1 print(max_score_guy) if __name__ == '__main__': main()
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. Input Specification: The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. Output Specification: Print the name of the winner. Demo Input: ['3\nmike 3\nandrew 5\nmike 2\n', '3\nandrew 3\nandrew 2\nmike 5\n'] Demo Output: ['andrew\n', 'andrew\n'] Note: none
```python from collections import Counter def main(): n = int(input().strip()) i = 0 scores = Counter() max_score = 0 max_score_guy = None while i < n: name, score = input().strip().split(' ') score = int(score) scores[name] += score if max_score < scores[name]: max_score_guy = name max_score = scores[name] i += 1 print(max_score_guy) if __name__ == '__main__': main() ```
0
722
C
Destroying Array
PROGRAMMING
1,600
[ "data structures", "dsu" ]
null
null
You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defining the order elements of the array are destroyed. After each element is destroyed you have to find out the segment of the array, such that it contains no destroyed elements and the sum of its elements is maximum possible. The sum of elements in the empty segment is considered to be 0.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). The third line contains a permutation of integers from 1 to *n* — the order used to destroy elements.
Print *n* lines. The *i*-th line should contain a single integer — the maximum possible sum of elements on the segment containing no destroyed elements, after first *i* operations are performed.
[ "4\n1 3 2 5\n3 4 1 2\n", "5\n1 2 3 4 5\n4 2 3 5 1\n", "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n" ]
[ "5\n4\n3\n0\n", "6\n5\n5\n1\n0\n", "18\n16\n11\n8\n8\n6\n6\n0\n" ]
Consider the first sample: 1. Third element is destroyed. Array is now 1 3  *  5. Segment with maximum sum 5 consists of one integer 5. 1. Fourth element is destroyed. Array is now 1 3  *   * . Segment with maximum sum 4 consists of two integers 1 3. 1. First element is destroyed. Array is now  *  3  *   * . Segment with maximum sum 3 consists of one integer 3. 1. Last element is destroyed. At this moment there are no valid nonempty segments left in this array, so the answer is equal to 0.
1,000
[ { "input": "4\n1 3 2 5\n3 4 1 2", "output": "5\n4\n3\n0" }, { "input": "5\n1 2 3 4 5\n4 2 3 5 1", "output": "6\n5\n5\n1\n0" }, { "input": "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6", "output": "18\n16\n11\n8\n8\n6\n6\n0" }, { "input": "10\n3 3 3 5 6 9 3 1 7 3\n3 4 6 7 5 1 10 9 2 8", "output": "34\n29\n14\n11\n11\n11\n8\n3\n1\n0" }, { "input": "17\n12 9 17 5 0 6 5 1 3 1 17 17 2 14 5 1 17\n3 7 5 8 12 9 15 13 11 14 6 16 17 1 10 2 4", "output": "94\n78\n78\n77\n39\n39\n21\n21\n21\n21\n21\n21\n21\n9\n9\n5\n0" }, { "input": "17\n1 6 9 2 10 5 15 16 17 14 17 3 9 8 12 0 2\n9 13 15 14 16 17 11 10 12 4 6 5 7 8 2 3 1", "output": "65\n64\n64\n64\n64\n64\n64\n64\n64\n46\n31\n31\n16\n16\n9\n1\n0" }, { "input": "17\n10 10 3 9 8 0 10 13 11 8 11 1 6 9 2 10 5\n9 4 13 2 6 15 11 5 16 10 7 3 14 1 12 8 17", "output": "63\n52\n31\n31\n26\n23\n23\n23\n23\n23\n13\n13\n13\n13\n13\n5\n0" }, { "input": "10\n10 4 9 0 7 5 10 3 10 9\n5 2 8 1 3 9 6 10 4 7", "output": "37\n37\n19\n19\n19\n15\n10\n10\n10\n0" }, { "input": "10\n3 10 9 2 6 8 4 4 1 9\n5 8 6 7 9 10 2 1 3 4", "output": "26\n24\n24\n24\n24\n24\n11\n11\n2\n0" }, { "input": "1\n1\n1", "output": "0" }, { "input": "7\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n1 2 3 4 5 6 7", "output": "6000000000\n5000000000\n4000000000\n3000000000\n2000000000\n1000000000\n0" } ]
1,555,193,125
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
12
1,000
1,228,800
h=int(input()) list1=[*map(int,input().split())] destroy=[*map(int,input().split())] for i in range(h): for j in range(h): list1[destroy[j] - 1] = -1 sums=[] x=0 y=0 for k in range(h): while list1[x]!=-1 : y+=list1[x] x+=1 if x==h: break sums.append(y) y=0 x+=1 if x>=h: break print(max(sums)) if max(sums)==0: exit(0) sums=[]
Title: Destroying Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defining the order elements of the array are destroyed. After each element is destroyed you have to find out the segment of the array, such that it contains no destroyed elements and the sum of its elements is maximum possible. The sum of elements in the empty segment is considered to be 0. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). The third line contains a permutation of integers from 1 to *n* — the order used to destroy elements. Output Specification: Print *n* lines. The *i*-th line should contain a single integer — the maximum possible sum of elements on the segment containing no destroyed elements, after first *i* operations are performed. Demo Input: ['4\n1 3 2 5\n3 4 1 2\n', '5\n1 2 3 4 5\n4 2 3 5 1\n', '8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n'] Demo Output: ['5\n4\n3\n0\n', '6\n5\n5\n1\n0\n', '18\n16\n11\n8\n8\n6\n6\n0\n'] Note: Consider the first sample: 1. Third element is destroyed. Array is now 1 3  *  5. Segment with maximum sum 5 consists of one integer 5. 1. Fourth element is destroyed. Array is now 1 3  *   * . Segment with maximum sum 4 consists of two integers 1 3. 1. First element is destroyed. Array is now  *  3  *   * . Segment with maximum sum 3 consists of one integer 3. 1. Last element is destroyed. At this moment there are no valid nonempty segments left in this array, so the answer is equal to 0.
```python h=int(input()) list1=[*map(int,input().split())] destroy=[*map(int,input().split())] for i in range(h): for j in range(h): list1[destroy[j] - 1] = -1 sums=[] x=0 y=0 for k in range(h): while list1[x]!=-1 : y+=list1[x] x+=1 if x==h: break sums.append(y) y=0 x+=1 if x>=h: break print(max(sums)) if max(sums)==0: exit(0) sums=[] ```
0
199
A
Hexadecimal's theorem
PROGRAMMING
900
[ "brute force", "constructive algorithms", "implementation", "number theory" ]
null
null
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1. So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ... If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible.
The input contains of a single integer *n* (0<=≤<=*n*<=&lt;<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number.
Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them.
[ "3\n", "13\n" ]
[ "1 1 1\n", "2 3 8\n" ]
none
500
[ { "input": "3", "output": "1 1 1" }, { "input": "13", "output": "2 3 8" }, { "input": "0", "output": "0 0 0" }, { "input": "1", "output": "1 0 0" }, { "input": "2", "output": "1 1 0" }, { "input": "1597", "output": "233 377 987" }, { "input": "0", "output": "0 0 0" }, { "input": "1", "output": "1 0 0" }, { "input": "1", "output": "1 0 0" }, { "input": "2", "output": "1 1 0" }, { "input": "3", "output": "1 1 1" }, { "input": "5", "output": "1 1 3" }, { "input": "8", "output": "1 2 5" }, { "input": "13", "output": "2 3 8" }, { "input": "21", "output": "3 5 13" }, { "input": "34", "output": "5 8 21" }, { "input": "55", "output": "8 13 34" }, { "input": "89", "output": "13 21 55" }, { "input": "144", "output": "21 34 89" }, { "input": "233", "output": "34 55 144" }, { "input": "377", "output": "55 89 233" }, { "input": "610", "output": "89 144 377" }, { "input": "987", "output": "144 233 610" }, { "input": "1597", "output": "233 377 987" }, { "input": "2584", "output": "377 610 1597" }, { "input": "4181", "output": "610 987 2584" }, { "input": "6765", "output": "987 1597 4181" }, { "input": "10946", "output": "1597 2584 6765" }, { "input": "17711", "output": "2584 4181 10946" }, { "input": "28657", "output": "4181 6765 17711" }, { "input": "46368", "output": "6765 10946 28657" }, { "input": "75025", "output": "10946 17711 46368" }, { "input": "121393", "output": "17711 28657 75025" }, { "input": "196418", "output": "28657 46368 121393" }, { "input": "317811", "output": "46368 75025 196418" }, { "input": "514229", "output": "75025 121393 317811" }, { "input": "832040", "output": "121393 196418 514229" }, { "input": "1346269", "output": "196418 317811 832040" }, { "input": "2178309", "output": "317811 514229 1346269" }, { "input": "3524578", "output": "514229 832040 2178309" }, { "input": "5702887", "output": "832040 1346269 3524578" }, { "input": "9227465", "output": "1346269 2178309 5702887" }, { "input": "14930352", "output": "2178309 3524578 9227465" }, { "input": "24157817", "output": "3524578 5702887 14930352" }, { "input": "39088169", "output": "5702887 9227465 24157817" }, { "input": "63245986", "output": "9227465 14930352 39088169" }, { "input": "102334155", "output": "14930352 24157817 63245986" }, { "input": "165580141", "output": "24157817 39088169 102334155" }, { "input": "267914296", "output": "39088169 63245986 165580141" }, { "input": "433494437", "output": "63245986 102334155 267914296" }, { "input": "701408733", "output": "102334155 165580141 433494437" }, { "input": "701408733", "output": "102334155 165580141 433494437" }, { "input": "102334155", "output": "14930352 24157817 63245986" }, { "input": "63245986", "output": "9227465 14930352 39088169" } ]
1,612,366,595
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
38
2,000
2,355,200
import math def fibonacci(n): if math.sqrt(5*n*n+4)%1==0 or math.sqrt(5*n*n-4)%1==0: return True return False n = int(input()) if n==0: print(0,0,0) elif n==1: print(1,0,0) elif n==2: print(1,1,0) else: for i in range(n-1,-1,-1): if fibonacci(i): k=i break for i in range(k-1,-1,-1): if fibonacci(i): j=i break for i in range(j-1,-1,-1): if fibonacci(i) and (i+j+k)==n: l=i break print(k,j,l)
Title: Hexadecimal's theorem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1. So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ... If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible. Input Specification: The input contains of a single integer *n* (0<=≤<=*n*<=&lt;<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number. Output Specification: Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them. Demo Input: ['3\n', '13\n'] Demo Output: ['1 1 1\n', '2 3 8\n'] Note: none
```python import math def fibonacci(n): if math.sqrt(5*n*n+4)%1==0 or math.sqrt(5*n*n-4)%1==0: return True return False n = int(input()) if n==0: print(0,0,0) elif n==1: print(1,0,0) elif n==2: print(1,1,0) else: for i in range(n-1,-1,-1): if fibonacci(i): k=i break for i in range(k-1,-1,-1): if fibonacci(i): j=i break for i in range(j-1,-1,-1): if fibonacci(i) and (i+j+k)==n: l=i break print(k,j,l) ```
0
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,533,647,216
2,456
Python 3
OK
TESTS
18
124
0
n,m,s,k=list(map(int,input().split())) for mnoj in range(1,10001): if s*mnoj>=m: pl=mnoj break amount=pl*n add=amount%k if add==0: print(amount//k) else: add=k-add amount+=add print(amount//k)
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 n,m,s,k=list(map(int,input().split())) for mnoj in range(1,10001): if s*mnoj>=m: pl=mnoj break amount=pl*n add=amount%k if add==0: print(amount//k) else: add=k-add amount+=add print(amount//k) ```
3
469
A
I Wanna Be the Guy
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other?
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100). The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*.
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
[ "4\n3 1 2 3\n2 2 4\n", "4\n3 1 2 3\n2 2 3\n" ]
[ "I become the guy.\n", "Oh, my keyboard!\n" ]
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both. In the second sample, no one can pass level 4.
500
[ { "input": "4\n3 1 2 3\n2 2 4", "output": "I become the guy." }, { "input": "4\n3 1 2 3\n2 2 3", "output": "Oh, my keyboard!" }, { "input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6", "output": "Oh, my keyboard!" }, { "input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8", "output": "I become the guy." }, { "input": "10\n9 6 1 8 3 9 7 5 10 4\n7 1 3 2 7 6 9 5", "output": "I become the guy." }, { "input": "100\n75 83 69 73 30 76 37 48 14 41 42 21 35 15 50 61 86 85 46 3 31 13 78 10 2 44 80 95 56 82 38 75 77 4 99 9 84 53 12 11 36 74 39 72 43 89 57 28 54 1 51 66 27 22 93 59 68 88 91 29 7 20 63 8 52 23 64 58 100 79 65 49 96 71 33 45\n83 50 89 73 34 28 99 67 77 44 19 60 68 42 8 27 94 85 14 39 17 78 24 21 29 63 92 32 86 22 71 81 31 82 65 48 80 59 98 3 70 55 37 12 15 72 47 9 11 33 16 7 91 74 13 64 38 84 6 61 93 90 45 69 1 54 52 100 57 10 35 49 53 75 76 43 62 5 4 18 36 96 79 23", "output": "Oh, my keyboard!" }, { "input": "1\n1 1\n1 1", "output": "I become the guy." }, { "input": "1\n0\n1 1", "output": "I become the guy." }, { "input": "1\n1 1\n0", "output": "I become the guy." }, { "input": "1\n0\n0", "output": "Oh, my keyboard!" }, { "input": "100\n0\n0", "output": "Oh, my keyboard!" }, { "input": "100\n44 71 70 55 49 43 16 53 7 95 58 56 38 76 67 94 20 73 29 90 25 30 8 84 5 14 77 52 99 91 66 24 39 37 22 44 78 12 63 59 32 51 15 82 34\n56 17 10 96 80 69 13 81 31 57 4 48 68 89 50 45 3 33 36 2 72 100 64 87 21 75 54 74 92 65 23 40 97 61 18 28 98 93 35 83 9 79 46 27 41 62 88 6 47 60 86 26 42 85 19 1 11", "output": "I become the guy." }, { "input": "100\n78 63 59 39 11 58 4 2 80 69 22 95 90 26 65 16 30 100 66 99 67 79 54 12 23 28 45 56 70 74 60 82 73 91 68 43 92 75 51 21 17 97 86 44 62 47 85 78 72 64 50 81 71 5 57 13 31 76 87 9 49 96 25 42 19 35 88 53 7 83 38 27 29 41 89 93 10 84 18\n78 1 16 53 72 99 9 36 59 49 75 77 94 79 35 4 92 42 82 83 76 97 20 68 55 47 65 50 14 30 13 67 98 8 7 40 64 32 87 10 33 90 93 18 26 71 17 46 24 28 89 58 37 91 39 34 25 48 84 31 96 95 80 88 3 51 62 52 85 61 12 15 27 6 45 38 2 22 60", "output": "I become the guy." }, { "input": "2\n2 2 1\n0", "output": "I become the guy." }, { "input": "2\n1 2\n2 1 2", "output": "I become the guy." }, { "input": "80\n57 40 1 47 36 69 24 76 5 72 26 4 29 62 6 60 3 70 8 64 18 37 16 14 13 21 25 7 66 68 44 74 61 39 38 33 15 63 34 65 10 23 56 51 80 58 49 75 71 12 50 57 2 30 54 27 17 52\n61 22 67 15 28 41 26 1 80 44 3 38 18 37 79 57 11 7 65 34 9 36 40 5 48 29 64 31 51 63 27 4 50 13 24 32 58 23 19 46 8 73 39 2 21 56 77 53 59 78 43 12 55 45 30 74 33 68 42 47 17 54", "output": "Oh, my keyboard!" }, { "input": "100\n78 87 96 18 73 32 38 44 29 64 40 70 47 91 60 69 24 1 5 34 92 94 99 22 83 65 14 68 15 20 74 31 39 100 42 4 97 46 25 6 8 56 79 9 71 35 54 19 59 93 58 62 10 85 57 45 33 7 86 81 30 98 26 61 84 41 23 28 88 36 66 51 80 53 37 63 43 95 75\n76 81 53 15 26 37 31 62 24 87 41 39 75 86 46 76 34 4 51 5 45 65 67 48 68 23 71 27 94 47 16 17 9 96 84 89 88 100 18 52 69 42 6 92 7 64 49 12 98 28 21 99 25 55 44 40 82 19 36 30 77 90 14 43 50 3 13 95 78 35 20 54 58 11 2 1 33", "output": "Oh, my keyboard!" }, { "input": "100\n77 55 26 98 13 91 78 60 23 76 12 11 36 62 84 80 18 1 68 92 81 67 19 4 2 10 17 77 96 63 15 69 46 97 82 42 83 59 50 72 14 40 89 9 52 29 56 31 74 39 45 85 22 99 44 65 95 6 90 38 54 32 49 34 3 70 75 33 94 53 21 71 5 66 73 41 100 24\n69 76 93 5 24 57 59 6 81 4 30 12 44 15 67 45 73 3 16 8 47 95 20 64 68 85 54 17 90 86 66 58 13 37 42 51 35 32 1 28 43 80 7 14 48 19 62 55 2 91 25 49 27 26 38 79 89 99 22 60 75 53 88 82 34 21 87 71 72 61", "output": "I become the guy." }, { "input": "100\n74 96 32 63 12 69 72 99 15 22 1 41 79 77 71 31 20 28 75 73 85 37 38 59 42 100 86 89 55 87 68 4 24 57 52 8 92 27 56 98 95 58 34 9 45 14 11 36 66 76 61 19 25 23 78 49 90 26 80 43 70 13 65 10 5 74 81 21 44 60 97 3 47 93 6\n64 68 21 27 16 91 23 22 33 12 71 88 90 50 62 43 28 29 57 59 5 74 10 95 35 1 67 93 36 32 86 40 6 64 78 46 89 15 84 53 18 30 17 85 2 3 47 92 25 48 76 51 20 82 52 83 99 63 80 11 94 54 39 7 58", "output": "I become the guy." }, { "input": "100\n75 11 98 44 47 88 94 23 78 59 70 2 43 39 34 63 71 19 42 61 30 74 14 77 97 53 92 60 67 36 37 13 6 86 62 46 41 3 25 93 7 12 27 48 55 49 31 35 51 10 57 54 95 82 28 90 73 26 17 50 81 56 20 87 40 85 72 64 99 29 91 5 80 18 24 52\n72 93 59 5 88 47 9 58 48 1 43 50 100 87 61 91 45 98 99 56 25 84 53 73 78 54 63 38 37 2 77 95 89 85 4 90 10 33 12 22 74 32 34 70 71 52 96 57 15 66 31 27 75 8 21 39 62 44 67 94 81 68 14 19 36 28 11 79 16 65 46 83 76", "output": "Oh, my keyboard!" }, { "input": "3\n1 2\n2 2 3", "output": "Oh, my keyboard!" }, { "input": "4\n1 2\n3 1 3 4", "output": "I become the guy." }, { "input": "6\n2 1 2\n3 4 5 6", "output": "Oh, my keyboard!" } ]
1,699,966,644
444
Python 3
WRONG_ANSWER
TESTS
1
30
0
n = int(input()) Lx = [int(i) for i in input().split(" ")] Ly = [int(i) for i in input().split(" ")] for i in range(1,n+1): if not (i in Lx or Ly): print("Oh, my keyboard!") exit() print("I become the guy.")
Title: I Wanna Be the Guy Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other? Input Specification: The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100). The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*. Output Specification: If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). Demo Input: ['4\n3 1 2 3\n2 2 4\n', '4\n3 1 2 3\n2 2 3\n'] Demo Output: ['I become the guy.\n', 'Oh, my keyboard!\n'] Note: In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both. In the second sample, no one can pass level 4.
```python n = int(input()) Lx = [int(i) for i in input().split(" ")] Ly = [int(i) for i in input().split(" ")] for i in range(1,n+1): if not (i in Lx or Ly): print("Oh, my keyboard!") exit() print("I become the guy.") ```
0
53
A
Autocomplete
PROGRAMMING
1,100
[ "implementation" ]
A. Autocomplete
2
256
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of *n* last visited by the user pages and the inputted part *s* are known. Your task is to complete *s* to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix *s*.
The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only.
If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*. The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '&lt;' operator in the modern programming languages.
[ "next\n2\nnextpermutation\nnextelement\n", "find\n4\nfind\nfindfirstof\nfindit\nfand\n", "find\n4\nfondfind\nfondfirstof\nfondit\nfand\n" ]
[ "nextelement\n", "find\n", "find\n" ]
none
500
[ { "input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement" }, { "input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find" }, { "input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find" }, { "input": "kudljmxcse\n4\nkudljmxcse\nszjebdoad\nchz\na", "output": "kudljmxcse" }, { "input": "ntqwpa\n5\nvvepyowvn\nntqwpakay\nhh\nygiafasda\nntqwpadm", "output": "ntqwpadm" }, { "input": "aflb\n6\nsaej\nujxsiijg\npp\nhgoprw\ncp\nnt", "output": "aflb" }, { "input": "dzwzyj\n7\nwvixktp\ndzwzyjuhn\ndzwzyjqrbd\ndzwzyji\ndzwzyjyfys\ndzwzyjrcb\nxptb", "output": "dzwzyji" }, { "input": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg\n1\nwjhsbxrrhadgtnybsugdtprncwerwezxuaxnqfpnosbispmnymnaqssdkjeynrnn", "output": "wmblbphwdjjskzmlsyiznluiudelhlvcpyrooajvbwudnnstdhesauyxjugdwhrrwg" }, { "input": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzu\n1\nhzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb", "output": "hzkqvwliymwjbejfpnydrbwskhyrtrlsdinfrgwmnbdpwytcnjeoowxrfgfuaffzayjylvzubwjlvhhsfurqb" }, { "input": "msjnqudojxtzvpc\n2\nvlxclsvqbucmbrkwwtoxek\nmsjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld", "output": "msjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld" } ]
1,609,329,785
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
216
0
s = input().strip() N = int(input()) ans = s found = -1 for i in range(N): j = input().strip() if j.startswith(s): print(j) if found==-1: ans = j found=1 if ans > j: ans = j print(ans)
Title: Autocomplete Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list consisting of *n* last visited by the user pages and the inputted part *s* are known. Your task is to complete *s* to make it an address of one of the pages from the list. You have to find the lexicographically smallest address having a prefix *s*. Input Specification: The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase Latin letters only. Output Specification: If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*. The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '&lt;' operator in the modern programming languages. Demo Input: ['next\n2\nnextpermutation\nnextelement\n', 'find\n4\nfind\nfindfirstof\nfindit\nfand\n', 'find\n4\nfondfind\nfondfirstof\nfondit\nfand\n'] Demo Output: ['nextelement\n', 'find\n', 'find\n'] Note: none
```python s = input().strip() N = int(input()) ans = s found = -1 for i in range(N): j = input().strip() if j.startswith(s): print(j) if found==-1: ans = j found=1 if ans > j: ans = j print(ans) ```
0
37
A
Towers
PROGRAMMING
1,000
[ "sortings" ]
A. Towers
2
256
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.
The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
[ "3\n1 2 3\n", "4\n6 5 6 7\n" ]
[ "1 3\n", "2 3\n" ]
none
500
[ { "input": "3\n1 2 3", "output": "1 3" }, { "input": "4\n6 5 6 7", "output": "2 3" }, { "input": "4\n3 2 1 1", "output": "2 3" }, { "input": "4\n1 2 3 3", "output": "2 3" }, { "input": "3\n20 22 36", "output": "1 3" }, { "input": "25\n47 30 94 41 45 20 96 51 110 129 24 116 9 47 32 82 105 114 116 75 154 151 70 42 162", "output": "2 23" }, { "input": "45\n802 664 442 318 318 827 417 878 711 291 231 414 807 553 657 392 279 202 386 606 465 655 658 112 887 15 25 502 95 44 679 775 942 609 209 871 31 234 4 231 150 110 22 823 193", "output": "2 43" }, { "input": "63\n93 180 116 7 8 179 268 279 136 94 221 153 264 190 278 19 19 63 153 26 158 225 25 49 89 218 111 149 255 225 197 122 243 80 3 224 107 178 202 17 53 92 69 42 228 24 81 205 95 8 265 82 228 156 127 241 172 159 106 60 67 155 111", "output": "2 57" }, { "input": "83\n246 535 994 33 390 927 321 97 223 922 812 705 79 80 977 457 476 636 511 137 6 360 815 319 717 674 368 551 714 628 278 713 761 553 184 414 623 753 428 214 581 115 439 61 677 216 772 592 187 603 658 310 439 559 870 376 109 321 189 337 277 26 70 734 796 907 979 693 570 227 345 650 737 633 701 914 134 403 972 940 371 6 642", "output": "2 80" }, { "input": "105\n246 57 12 204 165 123 246 68 191 310 3 152 386 333 374 257 158 104 333 50 80 290 8 340 101 76 221 316 388 289 138 359 316 26 93 290 105 178 81 195 41 196 218 180 244 292 187 97 315 323 174 119 248 239 92 312 31 2 101 180 307 170 338 314 163 281 217 31 142 238 280 190 190 156 70 74 329 113 151 8 141 313 366 40 253 116 168 124 135 230 294 266 353 389 371 359 195 200 183 237 93 102 315 118 188", "output": "2 92" }, { "input": "123\n112 277 170 247 252 115 157 293 256 143 196 90 12 164 164 42 8 223 167 109 175 232 239 111 148 51 9 254 93 32 268 162 231 91 47 162 161 191 195 145 247 292 129 199 230 94 144 217 18 205 176 20 143 198 121 243 211 262 230 277 195 255 108 290 220 275 158 2 286 200 60 267 278 207 123 150 123 116 131 13 12 226 33 244 30 275 263 45 158 192 254 149 242 176 62 224 221 288 250 160 155 225 132 143 276 293 218 145 197 175 33 129 79 206 210 192 222 262 190 52 274 243 233", "output": "3 101" }, { "input": "5\n5 5 5 5 5", "output": "5 1" }, { "input": "3\n1000 1000 1000", "output": "3 1" }, { "input": "1\n1000", "output": "1 1" }, { "input": "1\n1", "output": "1 1" }, { "input": "5\n1 1000 1000 1000 1000", "output": "4 2" }, { "input": "5\n1000 1000 1000 8 7", "output": "3 3" } ]
1,667,411,267
2,147,483,647
Python 3
OK
TESTS
61
92
0
a = int(input()) b = [int(i) for i in input().split()] c = set(b) d = list(c) maxi = 0 for i in range(len(d)): cur = b.count(d[i]) if cur > maxi: maxi = cur print(maxi, len(c))
Title: Towers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible. Input Specification: The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. Output Specification: In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. Demo Input: ['3\n1 2 3\n', '4\n6 5 6 7\n'] Demo Output: ['1 3\n', '2 3\n'] Note: none
```python a = int(input()) b = [int(i) for i in input().split()] c = set(b) d = list(c) maxi = 0 for i in range(len(d)): cur = b.count(d[i]) if cur > maxi: maxi = cur print(maxi, len(c)) ```
3.977
931
A
Friends Meeting
PROGRAMMING
800
[ "brute force", "greedy", "implementation", "math" ]
null
null
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend. The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend. It is guaranteed that *a*<=≠<=*b*.
Print the minimum possible total tiredness if the friends meet in the same point.
[ "3\n4\n", "101\n99\n", "5\n10\n" ]
[ "1\n", "2\n", "9\n" ]
In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9.
500
[ { "input": "3\n4", "output": "1" }, { "input": "101\n99", "output": "2" }, { "input": "5\n10", "output": "9" }, { "input": "1\n2", "output": "1" }, { "input": "1\n1000", "output": "250000" }, { "input": "999\n1000", "output": "1" }, { "input": "1000\n999", "output": "1" }, { "input": "1000\n1", "output": "250000" }, { "input": "2\n1", "output": "1" }, { "input": "2\n999", "output": "249001" }, { "input": "2\n998", "output": "248502" }, { "input": "999\n2", "output": "249001" }, { "input": "998\n2", "output": "248502" }, { "input": "2\n1000", "output": "249500" }, { "input": "1000\n2", "output": "249500" }, { "input": "1\n999", "output": "249500" }, { "input": "999\n1", "output": "249500" }, { "input": "188\n762", "output": "82656" }, { "input": "596\n777", "output": "8281" }, { "input": "773\n70", "output": "123904" }, { "input": "825\n729", "output": "2352" }, { "input": "944\n348", "output": "89102" }, { "input": "352\n445", "output": "2209" }, { "input": "529\n656", "output": "4096" }, { "input": "19\n315", "output": "22052" }, { "input": "138\n370", "output": "13572" }, { "input": "546\n593", "output": "576" }, { "input": "285\n242", "output": "484" }, { "input": "773\n901", "output": "4160" }, { "input": "892\n520", "output": "34782" }, { "input": "864\n179", "output": "117649" }, { "input": "479\n470", "output": "25" }, { "input": "967\n487", "output": "57840" }, { "input": "648\n106", "output": "73712" }, { "input": "58\n765", "output": "125316" }, { "input": "235\n56", "output": "8100" }, { "input": "285\n153", "output": "4422" }, { "input": "943\n13", "output": "216690" }, { "input": "675\n541", "output": "4556" }, { "input": "4\n912", "output": "206570" } ]
1,571,477,638
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
0
x=int(input()) y=int(input()) a=abs(x-y) b=a//2 if a%2==0: c=b*(b+1) else : c=(b*(b+1)//2)+((m+1)*(m+2)//2) print(c)
Title: Friends Meeting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1<=+<=2<=+<=3<==<=6. The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point. Input Specification: The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend. The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend. It is guaranteed that *a*<=≠<=*b*. Output Specification: Print the minimum possible total tiredness if the friends meet in the same point. Demo Input: ['3\n4\n', '101\n99\n', '5\n10\n'] Demo Output: ['1\n', '2\n', '9\n'] Note: In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2. In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9.
```python x=int(input()) y=int(input()) a=abs(x-y) b=a//2 if a%2==0: c=b*(b+1) else : c=(b*(b+1)//2)+((m+1)*(m+2)//2) print(c) ```
-1
722
B
Verse Pattern
PROGRAMMING
1,200
[ "implementation", "strings" ]
null
null
You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters. We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels: 'a', 'e', 'i', 'o', 'u' and 'y'. Each word of the text that contains at least one vowel can be divided into syllables. Each character should be a part of exactly one syllable. For example, the word "mamma" can be divided into syllables as "ma" and "mma", "mam" and "ma", and "mamm" and "a". Words that consist of only consonants should be ignored. The verse patterns for the given text is a sequence of *n* integers *p*1,<=*p*2,<=...,<=*p**n*. Text matches the given verse pattern if for each *i* from 1 to *n* one can divide words of the *i*-th line in syllables in such a way that the total number of syllables is equal to *p**i*. You are given the text and the verse pattern. Check, if the given text matches the given verse pattern.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the text. The second line contains integers *p*1,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=100) — the verse pattern. Next *n* lines contain the text itself. Text consists of lowercase English letters and spaces. It's guaranteed that all lines are non-empty, each line starts and ends with a letter and words are separated by exactly one space. The length of each line doesn't exceed 100 characters.
If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).
[ "3\n2 2 3\nintel\ncode\nch allenge\n", "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz\n", "4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample, one can split words into syllables in the following way: Since the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3 syllables in the third one.
500
[ { "input": "3\n2 2 3\nintel\ncode\nch allenge", "output": "YES" }, { "input": "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz", "output": "NO" }, { "input": "4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles", "output": "YES" }, { "input": "5\n2 2 1 1 1\nfdbie\naaj\ni\ni n\nshi", "output": "YES" }, { "input": "5\n2 11 10 7 9\nhy of\nyur pjyacbatdoylojayu\nemd ibweioiimyxya\nyocpyivudobua\nuiraueect impxqhzpty e", "output": "NO" }, { "input": "5\n6 9 7 3 10\nabtbdaa\nom auhz ub iaravozegs\ncieulibsdhj ufki\nadu pnpurt\nh naony i jaysjsjxpwuuc", "output": "NO" }, { "input": "2\n26 35\ngouojxaoobw iu bkaadyo degnjkubeabt kbap thwki dyebailrhnoh ooa\npiaeaebaocptyswuc wezesazipu osebhaonouygasjrciyiqaejtqsioubiuakg umynbsvw xpfqdwxo", "output": "NO" }, { "input": "5\n1 0 0 1 1\ngqex\nw\nh\nzsvu\nqcqd", "output": "NO" }, { "input": "5\n0 0 0 0 0\njtv\nl\nqg\ntp\nfgd", "output": "YES" }, { "input": "10\n0 0 0 0 0 0 0 0 0 0\nj t fr\nn\nnhcgx\np\nmb hmhtz\ndbjc\ncwdxj\nn j whkbt\nzk m cwh\nqr n", "output": "YES" }, { "input": "5\n4 5 1 0 0\noa\nqfohq\ni l\naik\nx", "output": "NO" }, { "input": "10\n2 9 0 3 2 4 1 2 4 2\nxtwl oy\nafgeju fi\nr hy\nddsowagw\nxoredo f\nwufnxy k uh\nod\nlejrinw\nsueecohfjl\nedufg", "output": "NO" }, { "input": "10\n1 1 0 0 0 4 0 4 0 0\na bn\nhnwss f\nd s bn\nbdzxzgsxq\nghh v\neimblv i er\nca kn k\nzm ffc zcb\nn\nz hkhvfkwhg", "output": "NO" }, { "input": "5\n0 10 6 6 0\nfgthrxst\nsohnweymewnnmbobj\nj\nfwwt acdtfvkpv khbxokn\nhndovkkgfhnhqod", "output": "NO" }, { "input": "5\n3 2 2 4 2\ni yu\niu\noa\naiio\nuo", "output": "YES" }, { "input": "5\n11 12 11 4 6\nuuuayoiaoiy\nuaiee iai eieu\nooayaayeuee\noii o\noea uuo", "output": "YES" }, { "input": "3\n2 3 2\nintel\ncode\nch allenge", "output": "NO" }, { "input": "2\n1 2\ncode\na", "output": "NO" }, { "input": "2\n1 1\nbababa\nbababa", "output": "NO" }, { "input": "1\n1\naa", "output": "NO" }, { "input": "1\n1\naaa", "output": "NO" }, { "input": "2\n2 3\naee\nae", "output": "NO" } ]
1,478,891,757
2,147,483,647
Python 3
OK
TESTS
54
62
0
def main(): from sys import stdin, stdout # stdin = open("input.txt", "r") inp = stdin.readlines() n = int(inp[0]) versePattern = iter(map(int, inp[1].split())) ans = True for line in inp[2:]: vowelCnt = 0 for x in line: if x in "aeiouy": vowelCnt += 1 if vowelCnt != next(versePattern): ans = False break stdout.write("YES\n" if ans else "NO\n") if __name__ == '__main__': main()
Title: Verse Pattern Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters. We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels: 'a', 'e', 'i', 'o', 'u' and 'y'. Each word of the text that contains at least one vowel can be divided into syllables. Each character should be a part of exactly one syllable. For example, the word "mamma" can be divided into syllables as "ma" and "mma", "mam" and "ma", and "mamm" and "a". Words that consist of only consonants should be ignored. The verse patterns for the given text is a sequence of *n* integers *p*1,<=*p*2,<=...,<=*p**n*. Text matches the given verse pattern if for each *i* from 1 to *n* one can divide words of the *i*-th line in syllables in such a way that the total number of syllables is equal to *p**i*. You are given the text and the verse pattern. Check, if the given text matches the given verse pattern. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the text. The second line contains integers *p*1,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=100) — the verse pattern. Next *n* lines contain the text itself. Text consists of lowercase English letters and spaces. It's guaranteed that all lines are non-empty, each line starts and ends with a letter and words are separated by exactly one space. The length of each line doesn't exceed 100 characters. Output Specification: If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). Demo Input: ['3\n2 2 3\nintel\ncode\nch allenge\n', '4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz\n', '4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first sample, one can split words into syllables in the following way: Since the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3 syllables in the third one.
```python def main(): from sys import stdin, stdout # stdin = open("input.txt", "r") inp = stdin.readlines() n = int(inp[0]) versePattern = iter(map(int, inp[1].split())) ans = True for line in inp[2:]: vowelCnt = 0 for x in line: if x in "aeiouy": vowelCnt += 1 if vowelCnt != next(versePattern): ans = False break stdout.write("YES\n" if ans else "NO\n") if __name__ == '__main__': main() ```
3
462
A
Appleman and Easy Task
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
[ "3\nxxo\nxox\noxx\n", "4\nxxxo\nxoxo\noxox\nxxxx\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "3\nxxo\nxox\noxx", "output": "YES" }, { "input": "4\nxxxo\nxoxo\noxox\nxxxx", "output": "NO" }, { "input": "1\no", "output": "YES" }, { "input": "2\nox\nxo", "output": "YES" }, { "input": "2\nxx\nxo", "output": "NO" }, { "input": "3\nooo\noxo\nxoo", "output": "NO" }, { "input": "3\nxxx\nxxo\nxxo", "output": "NO" }, { "input": "4\nxooo\nooxo\noxoo\nooox", "output": "YES" }, { "input": "4\noooo\noxxo\nxoxo\noooo", "output": "NO" }, { "input": "5\noxoxo\nxxxxx\noxoxo\nxxxxx\noxoxo", "output": "YES" }, { "input": "5\nxxxox\nxxxxo\nxoxox\noxoxx\nxoxxx", "output": "NO" }, { "input": "10\nxoxooooooo\noxxoxxxxxo\nxxooxoooxo\noooxxoxoxo\noxxxooooxo\noxooooxxxo\noxoxoxxooo\noxoooxooxx\noxxxxxoxxo\noooooooxox", "output": "YES" }, { "input": "10\nxxxxxxxoox\nxooxxooooo\noxoooxxooo\nxoxxxxxxxx\nxxoxooxxox\nooxoxxooox\nooxxxxxooo\nxxxxoxooox\nxoxxooxxxx\noooooxxoxo", "output": "NO" }, { "input": "19\noxoxoxoxooxoooxxoox\nxxxxxxxxoxxoxoooooo\noxoxoxooxxxooxxxooo\nxxoxxxooxooxxxoxxox\noxoxooxxxooooxxoxox\nxxxoooxoxxoxxoxxxoo\noxooxxxoooooxxoooxo\nxxooxooxoxxoxxoxxoo\noxxxxooooxxxooooxxx\nooxooxoxxoxxoxooxoo\nxxxooooxxxooooxoxox\noooxoxooxxoxooxooxx\nxxoooxxxooooxxoooxo\nooxxxooxoxooxooxxxx\nxoxoxxooxoxxxooxoxo\nxoxxoxoxooxooxxxxxx\noooxxxooxxxooxoxoxo\nxoooooxoxooxxxxxxxo\nxooxxoooxxoxoxoxoxx", "output": "NO" }, { "input": "12\nxxooxxoxxxoo\nxxoooxoxoxoo\nooxoxoxxooxx\nooxxooooxoxo\nxxxxxxxxoxxx\noxooooxxxooo\noxxoxoxoooxx\nxxxxxxxooxox\noxoooooxoxxx\nxxooxxoxxoxx\noxxxxxxxooxx\nooxoxooxxooo", "output": "NO" }, { "input": "2\noo\nxx", "output": "NO" } ]
1,562,861,411
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
108
0
n=int(input()) mat = [] mat.append('x'*(n+1)) for i in range(n): mat.append('x'+input()+'x') output = "YES" for i in range(1,n): if output == "NO": break for j in range(n): s=0 if mat[i][j+1] == 'o': s+=1 if mat[i][j-1] == 'o': s+=1 if mat[i+1][j] == 'o': s+=1 if mat[i-1][j] == 'o': s+=1 if s%2: output = "NO" break print(output)
Title: Appleman and Easy Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces. Output Specification: Print "YES" or "NO" (without the quotes) depending on the answer to the problem. Demo Input: ['3\nxxo\nxox\noxx\n', '4\nxxxo\nxoxo\noxox\nxxxx\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python n=int(input()) mat = [] mat.append('x'*(n+1)) for i in range(n): mat.append('x'+input()+'x') output = "YES" for i in range(1,n): if output == "NO": break for j in range(n): s=0 if mat[i][j+1] == 'o': s+=1 if mat[i][j-1] == 'o': s+=1 if mat[i+1][j] == 'o': s+=1 if mat[i-1][j] == 'o': s+=1 if s%2: output = "NO" break print(output) ```
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,443,539,448
2,147,483,647
Python 3
OK
TESTS
32
154
0
n = int(input()) a = list(map(int, input().split())) even = 0 lastE = -1 odd = 0 lastO = -1 for i in range(n): if a[i] % 2: odd += 1 lastO = i else: even += 1 lastE = i if odd == 1: print(lastO + 1) else: print(lastE + 1)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python n = int(input()) a = list(map(int, input().split())) even = 0 lastE = -1 odd = 0 lastO = -1 for i in range(n): if a[i] % 2: odd += 1 lastO = i else: even += 1 lastE = i if odd == 1: print(lastO + 1) else: print(lastE + 1) ```
3.9615
626
C
Block Towers
PROGRAMMING
1,600
[ "brute force", "greedy", "math", "number theory" ]
null
null
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. *n* of the students use pieces made of two blocks and *m* of the students use pieces made of three blocks. The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
The first line of the input contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1<=000<=000, *n*<=+<=*m*<=&gt;<=0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Print a single integer, denoting the minimum possible height of the tallest tower.
[ "1 3\n", "3 2\n", "5 0\n" ]
[ "9\n", "8\n", "10\n" ]
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks. In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
1,000
[ { "input": "1 3", "output": "9" }, { "input": "3 2", "output": "8" }, { "input": "5 0", "output": "10" }, { "input": "4 2", "output": "9" }, { "input": "0 1000000", "output": "3000000" }, { "input": "1000000 1", "output": "2000000" }, { "input": "1083 724", "output": "2710" }, { "input": "1184 868", "output": "3078" }, { "input": "1285 877", "output": "3243" }, { "input": "820189 548173", "output": "2052543" }, { "input": "968867 651952", "output": "2431228" }, { "input": "817544 553980", "output": "2057286" }, { "input": "813242 543613", "output": "2035282" }, { "input": "961920 647392", "output": "2413968" }, { "input": "825496 807050", "output": "2448819" }, { "input": "974174 827926", "output": "2703150" }, { "input": "969872 899794", "output": "2804499" }, { "input": "818549 720669", "output": "2308827" }, { "input": "967227 894524", "output": "2792626" }, { "input": "185253 152723", "output": "506964" }, { "input": "195173 150801", "output": "518961" }, { "input": "129439 98443", "output": "341823" }, { "input": "163706 157895", "output": "482402" }, { "input": "197973 140806", "output": "508168" }, { "input": "1000000 1000000", "output": "3000000" }, { "input": "1000000 999999", "output": "2999998" }, { "input": "999999 1000000", "output": "3000000" }, { "input": "500000 500100", "output": "1500300" }, { "input": "500000 166000", "output": "1000000" }, { "input": "500000 499000", "output": "1498500" }, { "input": "500000 167000", "output": "1000500" }, { "input": "1 1000000", "output": "3000000" }, { "input": "2 999123", "output": "2997369" }, { "input": "10 988723", "output": "2966169" }, { "input": "234 298374", "output": "895122" }, { "input": "2365 981235", "output": "2943705" }, { "input": "12345 981732", "output": "2945196" }, { "input": "108752 129872", "output": "389616" }, { "input": "984327 24352", "output": "1968654" }, { "input": "928375 1253", "output": "1856750" }, { "input": "918273 219", "output": "1836546" }, { "input": "987521 53", "output": "1975042" }, { "input": "123456 1", "output": "246912" }, { "input": "789123 0", "output": "1578246" }, { "input": "143568 628524", "output": "1885572" }, { "input": "175983 870607", "output": "2611821" }, { "input": "6 4", "output": "15" }, { "input": "6 3", "output": "14" }, { "input": "7 3", "output": "15" }, { "input": "5 4", "output": "14" }, { "input": "5 3", "output": "12" }, { "input": "8 5", "output": "20" }, { "input": "1 0", "output": "2" }, { "input": "19170 15725", "output": "52342" }, { "input": "3000 2000", "output": "7500" }, { "input": "7 4", "output": "16" }, { "input": "50 30", "output": "120" }, { "input": "300 200", "output": "750" }, { "input": "9 4", "output": "20" }, { "input": "4 3", "output": "10" }, { "input": "1 1", "output": "3" }, { "input": "8 6", "output": "21" }, { "input": "10 6", "output": "24" }, { "input": "65 56", "output": "182" }, { "input": "13 10", "output": "34" }, { "input": "14 42", "output": "126" }, { "input": "651 420", "output": "1606" }, { "input": "8 9", "output": "27" }, { "input": "15 10", "output": "38" }, { "input": "999999 888888", "output": "2833330" }, { "input": "192056 131545", "output": "485402" }, { "input": "32 16", "output": "72" }, { "input": "18 12", "output": "45" }, { "input": "1000000 666667", "output": "2500000" }, { "input": "0 1", "output": "3" }, { "input": "9 5", "output": "21" }, { "input": "1515 1415", "output": "4395" }, { "input": "300000 200000", "output": "750000" } ]
1,616,402,976
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
61
0
n, m = input().split() n = int(n) m = int(m) res_n = n * 2 res_m = m * 3 tmp_height = 0 while(tmp_height < min(res_n, res_m)): tmp_height += 6 tmpresn = res_n + 2 tmpresm = res_m + 3 if max(tmpresn, res_m) > max(res_n, tmpresm): res_m = tmpresm else: res_n = tmpresn print(max(res_m, res_n))
Title: Block Towers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. *n* of the students use pieces made of two blocks and *m* of the students use pieces made of three blocks. The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers. Input Specification: The first line of the input contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1<=000<=000, *n*<=+<=*m*<=&gt;<=0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively. Output Specification: Print a single integer, denoting the minimum possible height of the tallest tower. Demo Input: ['1 3\n', '3 2\n', '5 0\n'] Demo Output: ['9\n', '8\n', '10\n'] Note: In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks. In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.
```python n, m = input().split() n = int(n) m = int(m) res_n = n * 2 res_m = m * 3 tmp_height = 0 while(tmp_height < min(res_n, res_m)): tmp_height += 6 tmpresn = res_n + 2 tmpresm = res_m + 3 if max(tmpresn, res_m) > max(res_n, tmpresm): res_m = tmpresm else: res_n = tmpresn print(max(res_m, res_n)) ```
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,637,610,170
2,147,483,647
Python 3
OK
TESTS
40
62
0
s=input() count=0 for i in s: if count==0 and i=='h': count+=1 elif count==1 and i=='e': count+=1 elif count==2 and i=='l': count+=1 elif count==3 and i=='l': count+=1 elif count==4 and i=='o': count+=1 if count==5: print('YES') else: print('NO')
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python s=input() count=0 for i in s: if count==0 and i=='h': count+=1 elif count==1 and i=='e': count+=1 elif count==2 and i=='l': count+=1 elif count==3 and i=='l': count+=1 elif count==4 and i=='o': count+=1 if count==5: print('YES') else: print('NO') ```
3.969
937
A
Olympiad
PROGRAMMING
800
[ "implementation", "sortings" ]
null
null
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: - At least one participant should get a diploma. - None of those with score equal to zero should get awarded. - When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants. The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores. It's guaranteed that at least one participant has non-zero score.
Print a single integer — the desired number of ways.
[ "4\n1 3 3 2\n", "3\n1 1 1\n", "4\n42 0 0 42\n" ]
[ "3\n", "1\n", "1\n" ]
There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
500
[ { "input": "4\n1 3 3 2", "output": "3" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "4\n42 0 0 42", "output": "1" }, { "input": "10\n1 0 1 0 1 0 0 0 0 1", "output": "1" }, { "input": "10\n572 471 540 163 50 30 561 510 43 200", "output": "10" }, { "input": "100\n122 575 426 445 172 81 247 429 97 202 175 325 382 384 417 356 132 502 328 537 57 339 518 211 479 306 140 168 268 16 140 263 593 249 391 310 555 468 231 180 157 18 334 328 276 155 21 280 322 545 111 267 467 274 291 304 235 34 365 180 21 95 501 552 325 331 302 353 296 22 289 399 7 466 32 302 568 333 75 192 284 10 94 128 154 512 9 480 243 521 551 492 420 197 207 125 367 117 438 600", "output": "94" }, { "input": "100\n600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600", "output": "1" }, { "input": "78\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12", "output": "13" }, { "input": "34\n220 387 408 343 184 447 197 307 337 414 251 319 426 322 347 242 208 412 188 185 241 235 216 259 331 372 322 284 444 384 214 297 389 391", "output": "33" }, { "input": "100\n1 2 1 0 3 0 2 0 0 1 2 0 1 3 0 3 3 1 3 0 0 2 1 2 2 1 3 3 3 3 3 2 0 0 2 1 2 3 2 3 0 1 1 3 3 2 0 3 1 0 2 2 2 1 2 3 2 1 0 3 0 2 0 3 0 2 1 0 3 1 0 2 2 1 3 1 3 0 2 3 3 1 1 3 1 3 0 3 2 0 2 3 3 0 2 0 2 0 1 3", "output": "3" }, { "input": "100\n572 471 540 163 50 30 561 510 43 200 213 387 500 424 113 487 357 333 294 337 435 202 447 494 485 465 161 344 470 559 104 356 393 207 224 213 511 514 60 386 149 216 392 229 429 173 165 401 395 150 127 579 344 390 529 296 225 425 318 79 465 447 177 110 367 212 459 270 41 500 277 567 125 436 178 9 214 342 203 112 144 24 79 155 495 556 40 549 463 281 241 316 2 246 1 396 510 293 332 55", "output": "93" }, { "input": "99\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12 2 3 9 3 7 13 7 13 0 11 8 12 2 5 9 4 0 6 6 2 13", "output": "13" }, { "input": "99\n1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 0 0 0 1 1 0 0 0 0 0 1", "output": "1" }, { "input": "99\n21 74 25 44 71 80 46 28 96 1 74 24 81 83 16 55 31 1 27 36 56 38 17 10 78 5 39 67 67 15 39 62 92 48 90 9 54 67 30 79 56 17 33 27 75 54 20 79 21 44 10 66 66 73 90 3 34 33 64 79 20 94 0 51 24 30 1 52 95 21 88 98 6 65 31 1 67 32 74 91 83 9 93 27 53 11 8 79 42 20 50 91 19 96 6 24 66 16 37", "output": "61" }, { "input": "2\n0 1", "output": "1" }, { "input": "2\n0 600", "output": "1" }, { "input": "4\n1 1 1 2", "output": "2" }, { "input": "4\n0 0 1 2", "output": "2" }, { "input": "1\n5", "output": "1" }, { "input": "2\n0 5", "output": "1" }, { "input": "5\n1 0 0 1 2", "output": "2" } ]
1,580,704,040
2,147,483,647
Python 3
OK
TESTS
21
109
0
n=int(input()) l=list(map(int, input().split())) l2=[] for x in l: if x not in l2 and x!=0: l2.append(x) print(len(l2))
Title: Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: - At least one participant should get a diploma. - None of those with score equal to zero should get awarded. - When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants. The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores. It's guaranteed that at least one participant has non-zero score. Output Specification: Print a single integer — the desired number of ways. Demo Input: ['4\n1 3 3 2\n', '3\n1 1 1\n', '4\n42 0 0 42\n'] Demo Output: ['3\n', '1\n', '1\n'] Note: There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
```python n=int(input()) l=list(map(int, input().split())) l2=[] for x in l: if x not in l2 and x!=0: l2.append(x) print(len(l2)) ```
3
797
A
k-Factorization
PROGRAMMING
1,100
[ "implementation", "math", "number theory" ]
null
null
Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*.
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20).
If it's impossible to find the representation of *n* as a product of *k* numbers, print -1. Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them.
[ "100000 2\n", "100000 20\n", "1024 5\n" ]
[ "2 50000 \n", "-1\n", "2 64 2 2 2 \n" ]
none
0
[ { "input": "100000 2", "output": "2 50000 " }, { "input": "100000 20", "output": "-1" }, { "input": "1024 5", "output": "2 64 2 2 2 " }, { "input": "100000 10", "output": "2 2 2 2 2 5 5 5 5 5 " }, { "input": "99999 3", "output": "3 813 41 " }, { "input": "99999 4", "output": "3 3 41 271 " }, { "input": "99999 5", "output": "-1" }, { "input": "1024 10", "output": "2 2 2 2 2 2 2 2 2 2 " }, { "input": "1024 11", "output": "-1" }, { "input": "2048 11", "output": "2 2 2 2 2 2 2 2 2 2 2 " }, { "input": "2 1", "output": "2 " }, { "input": "2 2", "output": "-1" }, { "input": "2 3", "output": "-1" }, { "input": "2 4", "output": "-1" }, { "input": "2 5", "output": "-1" }, { "input": "2 1", "output": "2 " }, { "input": "3 1", "output": "3 " }, { "input": "3 2", "output": "-1" }, { "input": "349 2", "output": "-1" }, { "input": "8 1", "output": "8 " }, { "input": "66049 2", "output": "257 257 " }, { "input": "6557 2", "output": "83 79 " }, { "input": "9 2", "output": "3 3 " }, { "input": "4 2", "output": "2 2 " }, { "input": "2 2", "output": "-1" }, { "input": "4 4", "output": "-1" }, { "input": "12 1", "output": "12 " }, { "input": "17 1", "output": "17 " }, { "input": "8 2", "output": "2 4 " }, { "input": "14 2", "output": "7 2 " }, { "input": "99991 1", "output": "99991 " }, { "input": "30 2", "output": "3 10 " }, { "input": "97 1", "output": "97 " }, { "input": "92 2", "output": "2 46 " }, { "input": "4 1", "output": "4 " }, { "input": "4 3", "output": "-1" }, { "input": "30 4", "output": "-1" }, { "input": "2 6", "output": "-1" }, { "input": "3 1", "output": "3 " }, { "input": "3 2", "output": "-1" }, { "input": "3 3", "output": "-1" }, { "input": "3 4", "output": "-1" }, { "input": "3 5", "output": "-1" }, { "input": "3 6", "output": "-1" }, { "input": "4 1", "output": "4 " }, { "input": "4 2", "output": "2 2 " }, { "input": "4 3", "output": "-1" }, { "input": "4 4", "output": "-1" }, { "input": "4 5", "output": "-1" }, { "input": "4 6", "output": "-1" }, { "input": "5 1", "output": "5 " }, { "input": "5 2", "output": "-1" }, { "input": "5 3", "output": "-1" }, { "input": "5 4", "output": "-1" }, { "input": "5 5", "output": "-1" }, { "input": "5 6", "output": "-1" }, { "input": "6 1", "output": "6 " }, { "input": "6 2", "output": "3 2 " }, { "input": "6 3", "output": "-1" }, { "input": "6 4", "output": "-1" }, { "input": "6 5", "output": "-1" }, { "input": "6 6", "output": "-1" }, { "input": "7 1", "output": "7 " }, { "input": "7 2", "output": "-1" }, { "input": "7 3", "output": "-1" }, { "input": "7 4", "output": "-1" }, { "input": "7 5", "output": "-1" }, { "input": "7 6", "output": "-1" }, { "input": "8 1", "output": "8 " }, { "input": "8 2", "output": "2 4 " }, { "input": "8 3", "output": "2 2 2 " }, { "input": "8 4", "output": "-1" }, { "input": "8 5", "output": "-1" }, { "input": "8 6", "output": "-1" }, { "input": "9 1", "output": "9 " }, { "input": "9 2", "output": "3 3 " }, { "input": "9 3", "output": "-1" }, { "input": "9 4", "output": "-1" }, { "input": "9 5", "output": "-1" }, { "input": "9 6", "output": "-1" }, { "input": "10 1", "output": "10 " }, { "input": "10 2", "output": "5 2 " }, { "input": "10 3", "output": "-1" }, { "input": "10 4", "output": "-1" }, { "input": "10 5", "output": "-1" }, { "input": "10 6", "output": "-1" }, { "input": "11 1", "output": "11 " }, { "input": "11 2", "output": "-1" }, { "input": "11 3", "output": "-1" }, { "input": "11 4", "output": "-1" }, { "input": "11 5", "output": "-1" }, { "input": "11 6", "output": "-1" }, { "input": "12 1", "output": "12 " }, { "input": "12 2", "output": "2 6 " }, { "input": "12 3", "output": "2 2 3 " }, { "input": "12 4", "output": "-1" }, { "input": "12 5", "output": "-1" }, { "input": "12 6", "output": "-1" }, { "input": "13 1", "output": "13 " }, { "input": "13 2", "output": "-1" }, { "input": "13 3", "output": "-1" }, { "input": "13 4", "output": "-1" }, { "input": "13 5", "output": "-1" }, { "input": "13 6", "output": "-1" }, { "input": "14 1", "output": "14 " }, { "input": "14 2", "output": "7 2 " }, { "input": "14 3", "output": "-1" }, { "input": "14 4", "output": "-1" }, { "input": "14 5", "output": "-1" }, { "input": "14 6", "output": "-1" }, { "input": "15 1", "output": "15 " }, { "input": "15 2", "output": "5 3 " }, { "input": "15 3", "output": "-1" }, { "input": "15 4", "output": "-1" }, { "input": "15 5", "output": "-1" }, { "input": "15 6", "output": "-1" }, { "input": "16 1", "output": "16 " }, { "input": "16 2", "output": "2 8 " }, { "input": "16 3", "output": "2 4 2 " }, { "input": "16 4", "output": "2 2 2 2 " }, { "input": "16 5", "output": "-1" }, { "input": "16 6", "output": "-1" }, { "input": "17 1", "output": "17 " }, { "input": "17 2", "output": "-1" }, { "input": "17 3", "output": "-1" }, { "input": "17 4", "output": "-1" }, { "input": "17 5", "output": "-1" }, { "input": "17 6", "output": "-1" }, { "input": "18 1", "output": "18 " }, { "input": "18 2", "output": "3 6 " }, { "input": "18 3", "output": "3 2 3 " }, { "input": "18 4", "output": "-1" }, { "input": "18 5", "output": "-1" }, { "input": "18 6", "output": "-1" }, { "input": "19 1", "output": "19 " }, { "input": "19 2", "output": "-1" }, { "input": "19 3", "output": "-1" }, { "input": "19 4", "output": "-1" }, { "input": "19 5", "output": "-1" }, { "input": "19 6", "output": "-1" }, { "input": "20 1", "output": "20 " }, { "input": "20 2", "output": "2 10 " }, { "input": "20 3", "output": "2 2 5 " }, { "input": "20 4", "output": "-1" }, { "input": "20 5", "output": "-1" }, { "input": "20 6", "output": "-1" }, { "input": "94249 1", "output": "94249 " }, { "input": "94249 2", "output": "307 307 " }, { "input": "94249 3", "output": "-1" }, { "input": "94249 4", "output": "-1" }, { "input": "94249 5", "output": "-1" }, { "input": "95477 1", "output": "95477 " }, { "input": "95477 2", "output": "311 307 " }, { "input": "95477 3", "output": "-1" }, { "input": "95477 4", "output": "-1" }, { "input": "95477 5", "output": "-1" }, { "input": "35557 1", "output": "35557 " }, { "input": "35557 2", "output": "31 1147 " }, { "input": "35557 3", "output": "31 31 37 " }, { "input": "35557 4", "output": "-1" }, { "input": "35557 5", "output": "-1" }, { "input": "42439 1", "output": "42439 " }, { "input": "42439 2", "output": "37 1147 " }, { "input": "42439 3", "output": "37 31 37 " }, { "input": "42439 4", "output": "-1" }, { "input": "42439 5", "output": "-1" } ]
1,667,299,836
2,147,483,647
PyPy 3-64
OK
TESTS
166
62
1,331,200
def findPrimeFactors(n): ans=[] i=2 while(i<=(n+1)): while(n%i==0): ans.append(i) n=n//i i+=1 return ans n,k=map(int,input().split()) l=findPrimeFactors(n) if(len(l)<k): print(-1) else: ans=1 for i in l[k-1:]: ans*=i print(*l[:k-1],ans)
Title: k-Factorization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*. Input Specification: The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20). Output Specification: If it's impossible to find the representation of *n* as a product of *k* numbers, print -1. Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them. Demo Input: ['100000 2\n', '100000 20\n', '1024 5\n'] Demo Output: ['2 50000 \n', '-1\n', '2 64 2 2 2 \n'] Note: none
```python def findPrimeFactors(n): ans=[] i=2 while(i<=(n+1)): while(n%i==0): ans.append(i) n=n//i i+=1 return ans n,k=map(int,input().split()) l=findPrimeFactors(n) if(len(l)<k): print(-1) else: ans=1 for i in l[k-1:]: ans*=i print(*l[:k-1],ans) ```
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", "output": "1/6" }, { "input": "2 1", "output": "5/6" }, { "input": "2 2", "output": "5/6" }, { "input": "2 3", "output": "2/3" }, { "input": "2 4", "output": "1/2" }, { "input": "2 5", "output": "1/3" }, { "input": "2 6", "output": "1/6" }, { "input": "3 1", "output": "2/3" }, { "input": "3 2", "output": "2/3" }, { "input": "3 3", "output": "2/3" }, { "input": "3 4", "output": "1/2" }, { "input": "3 5", "output": "1/3" }, { "input": "3 6", "output": "1/6" }, { "input": "4 1", "output": "1/2" }, { "input": "4 3", "output": "1/2" }, { "input": "4 4", "output": "1/2" }, { "input": "4 5", "output": "1/3" }, { "input": "4 6", "output": "1/6" }, { "input": "5 1", "output": "1/3" }, { "input": "5 2", "output": "1/3" }, { "input": "5 3", "output": "1/3" }, { "input": "5 4", "output": "1/3" }, { "input": "5 5", "output": "1/3" }, { "input": "5 6", "output": "1/6" }, { "input": "6 1", "output": "1/6" }, { "input": "6 2", "output": "1/6" }, { "input": "6 3", "output": "1/6" }, { "input": "6 4", "output": "1/6" }, { "input": "6 5", "output": "1/6" }, { "input": "6 6", "output": "1/6" } ]
1,587,022,899
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
154
0
y, w = map(int, input().split()) if y%w==0: y = y//w if w%y==0: w = w//y print(w,"/",y)
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. Input Specification: The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. Output Specification: Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». Demo Input: ['4 2\n'] Demo Output: ['1/2\n'] Note: Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
```python y, w = map(int, input().split()) if y%w==0: y = y//w if w%y==0: w = w//y print(w,"/",y) ```
0
227
B
Effective Approach
PROGRAMMING
1,100
[ "implementation" ]
null
null
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
[ "2\n1 2\n1\n1\n", "2\n2 1\n1\n1\n", "3\n3 1 2\n3\n1 2 3\n" ]
[ "1 2\n", "2 1\n", "6 6\n" ]
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
1,000
[ { "input": "2\n1 2\n1\n1", "output": "1 2" }, { "input": "2\n2 1\n1\n1", "output": "2 1" }, { "input": "3\n3 1 2\n3\n1 2 3", "output": "6 6" }, { "input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5", "output": "58 32" }, { "input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4", "output": "9 2" }, { "input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8", "output": "31 68" }, { "input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1", "output": "15 15" }, { "input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2", "output": "27 13" }, { "input": "4\n1 3 2 4\n4\n3 1 2 3", "output": "8 12" }, { "input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2", "output": "15 17" } ]
1,620,457,894
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
14,438,400
n = int(input()) a = list(map(int,input().split())) m = int(input()) b = list(map(int,input().split())) Vasya=0 Petya=0 for i in b: for j in a: Vasya+=1 if i==j: break c=a[::-1] for k in c: Petya+=1 if i==k: break print(str(Vasya)+" "+str(Petya))
Title: Effective Approach Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. Output Specification: Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Demo Input: ['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n'] Demo Output: ['1 2\n', '2 1\n', '6 6\n'] Note: In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
```python n = int(input()) a = list(map(int,input().split())) m = int(input()) b = list(map(int,input().split())) Vasya=0 Petya=0 for i in b: for j in a: Vasya+=1 if i==j: break c=a[::-1] for k in c: Petya+=1 if i==k: break print(str(Vasya)+" "+str(Petya)) ```
0
245
E
Mishap in Club
PROGRAMMING
1,400
[ "greedy", "implementation" ]
null
null
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Print the sought minimum number of people
[ "+-+-+\n", "---" ]
[ "1\n", "3" ]
none
0
[ { "input": "+-+-+", "output": "1" }, { "input": "---", "output": "3" }, { "input": "-", "output": "1" }, { "input": "--", "output": "2" }, { "input": "---", "output": "3" }, { "input": "----", "output": "4" }, { "input": "---+", "output": "3" }, { "input": "--+-", "output": "2" }, { "input": "--++", "output": "2" }, { "input": "-+--", "output": "2" }, { "input": "-++", "output": "2" }, { "input": "-++-", "output": "2" }, { "input": "+", "output": "1" }, { "input": "+-", "output": "1" }, { "input": "+--", "output": "2" }, { "input": "+--+", "output": "2" }, { "input": "++--", "output": "2" }, { "input": "-+++--+-++--+-+--+-+", "output": "3" }, { "input": "++-++--+++++-+++++---+++-++-++-", "output": "12" }, { "input": "----+-+--++---++---++-+-----+--", "output": "11" }, { "input": "-+++---+++++++++++++-++-++++++-++-+-+++-", "output": "22" }, { "input": "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", "output": "300" }, { "input": "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", "output": "300" }, { "input": "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", "output": "298" }, { "input": "++++++++++++++++++++-+++++++++++++++++++++++++++++++++++++++++++++++++++++++-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", "output": "296" }, { "input": "+++++++++++++++++++++++++++++++++++++++++-++++++++-++++++++++++-+++++++++++++++++++++++++++++++++++++++++++++++++++++-+++++++++++++++++++++++++-++++++++++++++++++++++++-++++-+++++++++++++-++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-+++-+++++++++++++++++", "output": "280" }, { "input": "++++-+---+++--++++-++-++++++++-++-++++-++++++-+-+-+++--+-++++++-+++-++-+++-++++-++++-+-+----+++++---++++-+---+++--+++++-+++-+-++++++----+--+++++++++-+--+++-+-+-++++++--+-+-+-+-++--+-+-----++++++-+++-++--+++++++++---+-++++++-++-++++-+--+-++-++++-+-+--++-+--+++-+-++++++++++++-+++-+----++++++++--+-+-++", "output": "100" }, { "input": "+----++-----+----+++--++---+++--+-++++-++---++++++--++++--++-++--++--++----++++---+--+++----++--++--++--+--++++++++--++--+++----+++----++----++-+--+---+--+-++--+--+--+-+--+---++-+-++--+++++-++------+++-++--+--+--+++++++--++-+--+-+--++++-++--+---+-+-++-+-++----+-++++++-+++--+----++-+--++-----+++-++-+", "output": "15" }, { "input": "-+++----+-++--+-+----+--+++++----+---+-++-+---+++--+---++-+-----+----+------+--+----++-++-----+++--+---+-+-----++++------+--+-----++---+---+---+-++------++++--+-+-------------+---+--+-+--------++---+-++---+-----+++--+---+-++-+---+-+---+++--++-----++------+----+---+---+--+-+-++-+---++--------+----++", "output": "103" }, { "input": "----------+-----------------------------------------------------------+-+-------------+--------------------------------------------------------------------------------+--+-----+-+-------------------------------------------+-----------------------------------------------------------------+-----------", "output": "280" } ]
1,614,319,723
2,147,483,647
Python 3
OK
TESTS
30
124
0
#Problem N line = input() enter = 0 leave = 0 for i in line: if i == '+': enter += 1 if leave > 0: leave -= 1 if i == '-': leave += 1 if enter > 0: enter -= 1 print(enter + leave)
Title: Mishap in Club Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. Input Specification: The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. Output Specification: Print the sought minimum number of people Demo Input: ['+-+-+\n', '---'] Demo Output: ['1\n', '3'] Note: none
```python #Problem N line = input() enter = 0 leave = 0 for i in line: if i == '+': enter += 1 if leave > 0: leave -= 1 if i == '-': leave += 1 if enter > 0: enter -= 1 print(enter + leave) ```
3
777
A
Shell Game
PROGRAMMING
1,000
[ "constructive algorithms", "implementation", "math" ]
null
null
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball. Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.). Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly *n* movements were made by the operator and the ball was under shell *x* at the end. Now he wonders, what was the initial position of the ball?
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator. The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements.
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
[ "4\n2\n", "1\n1\n" ]
[ "1\n", "0\n" ]
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements. 1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell. 1. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle. 1. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
500
[ { "input": "4\n2", "output": "1" }, { "input": "1\n1", "output": "0" }, { "input": "2\n2", "output": "0" }, { "input": "3\n1", "output": "1" }, { "input": "3\n2", "output": "0" }, { "input": "3\n0", "output": "2" }, { "input": "2000000000\n0", "output": "1" }, { "input": "2\n0", "output": "1" }, { "input": "2\n1", "output": "2" }, { "input": "4\n0", "output": "2" }, { "input": "4\n1", "output": "0" }, { "input": "5\n0", "output": "0" }, { "input": "5\n1", "output": "2" }, { "input": "5\n2", "output": "1" }, { "input": "6\n0", "output": "0" }, { "input": "6\n1", "output": "1" }, { "input": "6\n2", "output": "2" }, { "input": "7\n0", "output": "1" }, { "input": "7\n1", "output": "0" }, { "input": "7\n2", "output": "2" }, { "input": "100000\n0", "output": "2" }, { "input": "100000\n1", "output": "0" }, { "input": "100000\n2", "output": "1" }, { "input": "99999\n1", "output": "1" }, { "input": "99998\n1", "output": "2" }, { "input": "99997\n1", "output": "0" }, { "input": "99996\n1", "output": "1" }, { "input": "99995\n1", "output": "2" }, { "input": "1999999995\n0", "output": "2" }, { "input": "1999999995\n1", "output": "1" }, { "input": "1999999995\n2", "output": "0" }, { "input": "1999999996\n0", "output": "2" }, { "input": "1999999996\n1", "output": "0" }, { "input": "1999999996\n2", "output": "1" }, { "input": "1999999997\n0", "output": "0" }, { "input": "1999999997\n1", "output": "2" }, { "input": "1999999997\n2", "output": "1" }, { "input": "1999999998\n0", "output": "0" }, { "input": "1999999998\n1", "output": "1" }, { "input": "1999999998\n2", "output": "2" }, { "input": "1999999999\n0", "output": "1" }, { "input": "1999999999\n1", "output": "0" }, { "input": "1999999999\n2", "output": "2" }, { "input": "2000000000\n1", "output": "2" }, { "input": "2000000000\n2", "output": "0" }, { "input": "1234567890\n0", "output": "0" }, { "input": "1234567890\n1", "output": "1" }, { "input": "1234567890\n2", "output": "2" }, { "input": "123456789\n0", "output": "2" }, { "input": "123456789\n1", "output": "1" }, { "input": "123456789\n2", "output": "0" }, { "input": "123456790\n0", "output": "2" }, { "input": "12\n2", "output": "2" }, { "input": "32\n1", "output": "2" }, { "input": "20\n2", "output": "0" }, { "input": "10\n1", "output": "0" }, { "input": "1\n0", "output": "1" }, { "input": "76994383\n1", "output": "0" }, { "input": "25\n2", "output": "2" }, { "input": "1\n2", "output": "2" }, { "input": "12\n0", "output": "0" }, { "input": "150\n2", "output": "2" }, { "input": "15\n0", "output": "2" }, { "input": "21\n2", "output": "0" }, { "input": "18\n2", "output": "2" }, { "input": "8\n2", "output": "0" }, { "input": "10\n0", "output": "2" }, { "input": "16\n0", "output": "2" } ]
1,539,691,568
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
0
n = int(input()) m = int(input()) n = n % 6 a = [] if n == 0: a = [0,1,2] elif n == 1: a = [1,0,2] elif n == 2: a = [1,2,0] elif n == 3: a = [2,1,0] elif n == 4: a = [2,0,1] elif n == 5: a = [0,2,1] for i in [0,1,2]: if a[i] == m: print(i)
Title: Shell Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball. Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.). Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly *n* movements were made by the operator and the ball was under shell *x* at the end. Now he wonders, what was the initial position of the ball? Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator. The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements. Output Specification: Print one integer from 0 to 2 — the index of the shell where the ball was initially placed. Demo Input: ['4\n2\n', '1\n1\n'] Demo Output: ['1\n', '0\n'] Note: In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements. 1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell. 1. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle. 1. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
```python n = int(input()) m = int(input()) n = n % 6 a = [] if n == 0: a = [0,1,2] elif n == 1: a = [1,0,2] elif n == 2: a = [1,2,0] elif n == 3: a = [2,1,0] elif n == 4: a = [2,0,1] elif n == 5: a = [0,2,1] for i in [0,1,2]: if a[i] == m: print(i) ```
0
328
A
IQ Test
PROGRAMMING
1,800
[ "implementation" ]
null
null
Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions. Arithmetic progression is a sequence *a*1, *a*1<=+<=*d*, *a*1<=+<=2*d*, ..., *a*1<=+<=(*n*<=-<=1)*d*, where *a*1 and *d* are any numbers. Geometric progression is a sequence *b*1, *b*2<==<=*b*1*q*, ..., *b**n*<==<=*b**n*<=-<=1*q*, where *b*1<=≠<=0, *q*<=≠<=0, *q*<=≠<=1. Help Petya and write a program to determine if the given sequence is arithmetic or geometric. Also it should found the next number. If the sequence is neither arithmetic nor geometric, print 42 (he thinks it is impossible to find better answer). You should also print 42 if the next element of progression is not integer. So answer is always integer.
The first line contains exactly four integer numbers between 1 and 1000, inclusively.
Print the required number. If the given sequence is arithmetic progression, print the next progression element. Similarly, if the given sequence is geometric progression, print the next progression element. Print 42 if the given sequence is not an arithmetic or geometric progression.
[ "836 624 412 200\n", "1 334 667 1000\n" ]
[ "-12\n", "1333\n" ]
This problem contains very weak pretests!
500
[ { "input": "836 624 412 200", "output": "-12" }, { "input": "1 334 667 1000", "output": "1333" }, { "input": "501 451 400 350", "output": "42" }, { "input": "836 624 412 200", "output": "-12" }, { "input": "1 334 667 1000", "output": "1333" }, { "input": "11 234 457 680", "output": "903" }, { "input": "640 431 222 13", "output": "-196" }, { "input": "1 1 1 1", "output": "1" }, { "input": "1 10 100 1000", "output": "10000" }, { "input": "3 18 108 648", "output": "3888" }, { "input": "512 384 288 216", "output": "162" }, { "input": "891 297 99 33", "output": "11" }, { "input": "64 160 400 1000", "output": "2500" }, { "input": "501 451 400 350", "output": "42" }, { "input": "501 450 400 350", "output": "42" }, { "input": "4 32 48 64", "output": "42" }, { "input": "9 8 7 5", "output": "42" }, { "input": "992 994 998 1000", "output": "42" }, { "input": "2 6 6 8", "output": "42" }, { "input": "2 4 8 8", "output": "42" }, { "input": "2 4 6 14", "output": "42" }, { "input": "2 12 4 14", "output": "42" }, { "input": "2 4 4 2", "output": "42" }, { "input": "1000 100 10 1", "output": "42" }, { "input": "2 9 27 81", "output": "42" }, { "input": "2 4 9 16", "output": "42" }, { "input": "2 4 9 18", "output": "42" }, { "input": "256 64 16 8", "output": "42" }, { "input": "256 385 576 864", "output": "42" }, { "input": "343 147 63 27", "output": "42" }, { "input": "729 648 576 512", "output": "42" }, { "input": "1000 980 960 941", "output": "42" }, { "input": "2 5 10 16", "output": "42" }, { "input": "1 2 3 10", "output": "42" }, { "input": "24 36 54 81", "output": "42" }, { "input": "1 2 4 8", "output": "16" }, { "input": "16 24 36 54", "output": "81" }, { "input": "8 4 2 1", "output": "42" }, { "input": "16 8 4 2", "output": "1" }, { "input": "32 16 8 4", "output": "2" }, { "input": "10 11 12 12", "output": "42" }, { "input": "1 2 10 20", "output": "42" }, { "input": "27 9 3 1", "output": "42" }, { "input": "81 108 144 192", "output": "256" }, { "input": "2 3 4 6", "output": "42" }, { "input": "1000 500 170 40", "output": "42" } ]
1,612,685,584
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
216
2,150,400
def test_geometric(in_list): geometric = True for nr in in_list: if nr == 0: return False else: quotient = in_list[1] / in_list[0] current_nr = in_list[0] for nr in in_list[1:]: if nr / current_nr != quotient: geometric = False else: current_nr = nr if geometric: next = nr * quotient return next else: return 42 if __name__ == "__main__": in_numbers = list(map(int, input().split())) answer_ari = test_arithmetic(in_numbers) answer_geo = test_geometric(in_numbers) if answer_ari != 42: print(answer_ari) else: print(answer_geo)
Title: IQ Test Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions. Arithmetic progression is a sequence *a*1, *a*1<=+<=*d*, *a*1<=+<=2*d*, ..., *a*1<=+<=(*n*<=-<=1)*d*, where *a*1 and *d* are any numbers. Geometric progression is a sequence *b*1, *b*2<==<=*b*1*q*, ..., *b**n*<==<=*b**n*<=-<=1*q*, where *b*1<=≠<=0, *q*<=≠<=0, *q*<=≠<=1. Help Petya and write a program to determine if the given sequence is arithmetic or geometric. Also it should found the next number. If the sequence is neither arithmetic nor geometric, print 42 (he thinks it is impossible to find better answer). You should also print 42 if the next element of progression is not integer. So answer is always integer. Input Specification: The first line contains exactly four integer numbers between 1 and 1000, inclusively. Output Specification: Print the required number. If the given sequence is arithmetic progression, print the next progression element. Similarly, if the given sequence is geometric progression, print the next progression element. Print 42 if the given sequence is not an arithmetic or geometric progression. Demo Input: ['836 624 412 200\n', '1 334 667 1000\n'] Demo Output: ['-12\n', '1333\n'] Note: This problem contains very weak pretests!
```python def test_geometric(in_list): geometric = True for nr in in_list: if nr == 0: return False else: quotient = in_list[1] / in_list[0] current_nr = in_list[0] for nr in in_list[1:]: if nr / current_nr != quotient: geometric = False else: current_nr = nr if geometric: next = nr * quotient return next else: return 42 if __name__ == "__main__": in_numbers = list(map(int, input().split())) answer_ari = test_arithmetic(in_numbers) answer_geo = test_geometric(in_numbers) if answer_ari != 42: print(answer_ari) else: print(answer_geo) ```
-1
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,413,058,492
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
0
n = 0 t = 0 while True: #try: l = input() if len(l) == 0 : break if l[0] == '+': n += 1 elif l[0] == '-': n -= 1 else: t += n*len((l.split(':')[1])) #except: #break print(t)
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 n = 0 t = 0 while True: #try: l = input() if len(l) == 0 : break if l[0] == '+': n += 1 elif l[0] == '-': n -= 1 else: t += n*len((l.split(':')[1])) #except: #break print(t) ```
-1
911
C
Three Garlands
PROGRAMMING
1,400
[ "brute force", "constructive algorithms" ]
null
null
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on. When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th second, then it is lit only during seconds *x*, *x*<=+<=*k**i*, *x*<=+<=2*k**i*, *x*<=+<=3*k**i* and so on. Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers *x*1, *x*2 and *x*3 (not necessarily distinct) so that he will switch on the first garland during *x*1-th second, the second one — during *x*2-th second, and the third one — during *x*3-th second, respectively, and during each second starting from *max*(*x*1,<=*x*2,<=*x*3) at least one garland will be lit. Help Mishka by telling him if it is possible to do this!
The first line contains three integers *k*1, *k*2 and *k*3 (1<=≤<=*k**i*<=≤<=1500) — time intervals of the garlands.
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES. Otherwise, print NO.
[ "2 2 3\n", "4 2 3\n" ]
[ "YES\n", "NO\n" ]
In the first example Mishka can choose *x*<sub class="lower-index">1</sub> = 1, *x*<sub class="lower-index">2</sub> = 2, *x*<sub class="lower-index">3</sub> = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what *x*<sub class="lower-index">3</sub> is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though. In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.
0
[ { "input": "2 2 3", "output": "YES" }, { "input": "4 2 3", "output": "NO" }, { "input": "1499 1498 1500", "output": "NO" }, { "input": "1500 1500 1500", "output": "NO" }, { "input": "100 4 1", "output": "YES" }, { "input": "4 2 4", "output": "YES" }, { "input": "3 3 3", "output": "YES" }, { "input": "2 3 6", "output": "NO" }, { "input": "2 3 3", "output": "NO" }, { "input": "4 4 2", "output": "YES" }, { "input": "1 1 1", "output": "YES" }, { "input": "2 11 2", "output": "YES" }, { "input": "4 4 4", "output": "NO" }, { "input": "4 4 5", "output": "NO" }, { "input": "3 3 2", "output": "NO" }, { "input": "3 6 6", "output": "NO" }, { "input": "2 3 2", "output": "YES" }, { "input": "1 1 3", "output": "YES" }, { "input": "3 3 4", "output": "NO" }, { "input": "2 4 4", "output": "YES" }, { "input": "2 2 2", "output": "YES" }, { "input": "2 10 10", "output": "NO" }, { "input": "3 4 4", "output": "NO" }, { "input": "2 5 5", "output": "NO" }, { "input": "2 4 5", "output": "NO" }, { "input": "228 2 2", "output": "YES" }, { "input": "2 998 1000", "output": "NO" }, { "input": "2 6 6", "output": "NO" }, { "input": "6 4 7", "output": "NO" }, { "input": "2 5 2", "output": "YES" }, { "input": "2 100 100", "output": "NO" }, { "input": "7 7 2", "output": "NO" }, { "input": "3 3 6", "output": "NO" }, { "input": "82 3 82", "output": "NO" }, { "input": "2 3 5", "output": "NO" }, { "input": "1 218 924", "output": "YES" }, { "input": "4 4 123", "output": "NO" }, { "input": "4 4 3", "output": "NO" }, { "input": "3 4 2", "output": "NO" }, { "input": "2 2 5", "output": "YES" }, { "input": "2 10 2", "output": "YES" }, { "input": "5 2 2", "output": "YES" }, { "input": "3 3 9", "output": "NO" }, { "input": "1 5 5", "output": "YES" }, { "input": "2 4 6", "output": "NO" }, { "input": "15 3 3", "output": "NO" }, { "input": "1 5 10", "output": "YES" }, { "input": "2 3 14", "output": "NO" }, { "input": "1265 2 593", "output": "NO" }, { "input": "2 2 567", "output": "YES" }, { "input": "1 6 5", "output": "YES" }, { "input": "2 2 7", "output": "YES" }, { "input": "2 2 1500", "output": "YES" }, { "input": "3 6 9", "output": "NO" }, { "input": "1 46 79", "output": "YES" }, { "input": "4 3 3", "output": "NO" }, { "input": "2 4 8", "output": "NO" }, { "input": "1493 1489 1487", "output": "NO" }, { "input": "1 2 3", "output": "YES" }, { "input": "1 2 5", "output": "YES" }, { "input": "1 2 8", "output": "YES" }, { "input": "3 4 5", "output": "NO" }, { "input": "2 2 4", "output": "YES" }, { "input": "3 2 3", "output": "NO" }, { "input": "7 2 2", "output": "YES" }, { "input": "3 2 2", "output": "YES" }, { "input": "6 7 4", "output": "NO" } ]
1,526,795,808
2,147,483,647
Python 3
OK
TESTS
67
93
0
arr=list(map(int,input().split())) if arr.count(1)>=1 or arr.count(2)>=2 or arr.count(3)>=3 or (arr.count(4)==2 and arr.count(2)==1): print("YES") else: print("NO")
Title: Three Garlands Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on. When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th second, then it is lit only during seconds *x*, *x*<=+<=*k**i*, *x*<=+<=2*k**i*, *x*<=+<=3*k**i* and so on. Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers *x*1, *x*2 and *x*3 (not necessarily distinct) so that he will switch on the first garland during *x*1-th second, the second one — during *x*2-th second, and the third one — during *x*3-th second, respectively, and during each second starting from *max*(*x*1,<=*x*2,<=*x*3) at least one garland will be lit. Help Mishka by telling him if it is possible to do this! Input Specification: The first line contains three integers *k*1, *k*2 and *k*3 (1<=≤<=*k**i*<=≤<=1500) — time intervals of the garlands. Output Specification: If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES. Otherwise, print NO. Demo Input: ['2 2 3\n', '4 2 3\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first example Mishka can choose *x*<sub class="lower-index">1</sub> = 1, *x*<sub class="lower-index">2</sub> = 2, *x*<sub class="lower-index">3</sub> = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what *x*<sub class="lower-index">3</sub> is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though. In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.
```python arr=list(map(int,input().split())) if arr.count(1)>=1 or arr.count(2)>=2 or arr.count(3)>=3 or (arr.count(4)==2 and arr.count(2)==1): print("YES") else: print("NO") ```
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,450,263,293
2,147,483,647
Python 3
OK
TESTS
32
216
0
n=int(input()) inp=input().split() for i in range(n):inp[i]=int(inp[i]) if inp[0]%2+inp[1]%2+inp[2]%2>=2: for i in range(n): if inp[i]%2==0:print (i+1) else: for i in range(n): if inp[i]%2==1:print (i+1)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Specification: Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Demo Input: ['5\n2 4 7 8 10\n', '4\n1 2 1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python n=int(input()) inp=input().split() for i in range(n):inp[i]=int(inp[i]) if inp[0]%2+inp[1]%2+inp[2]%2>=2: for i in range(n): if inp[i]%2==0:print (i+1) else: for i in range(n): if inp[i]%2==1:print (i+1) ```
3.946
798
A
Mike and palindrome
PROGRAMMING
1,000
[ "brute force", "constructive algorithms", "strings" ]
null
null
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15).
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
[ "abccaa\n", "abbcca\n", "abcda\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "abccaa", "output": "YES" }, { "input": "abbcca", "output": "NO" }, { "input": "abcda", "output": "YES" }, { "input": "kyw", "output": "YES" }, { "input": "fccf", "output": "NO" }, { "input": "mnlm", "output": "YES" }, { "input": "gqrk", "output": "NO" }, { "input": "glxlg", "output": "YES" }, { "input": "czhfc", "output": "YES" }, { "input": "broon", "output": "NO" }, { "input": "rmggmr", "output": "NO" }, { "input": "wvxxzw", "output": "YES" }, { "input": "ukvciu", "output": "NO" }, { "input": "vrnwnrv", "output": "YES" }, { "input": "vlkjkav", "output": "YES" }, { "input": "guayhmg", "output": "NO" }, { "input": "lkvhhvkl", "output": "NO" }, { "input": "ffdsslff", "output": "YES" }, { "input": "galjjtyw", "output": "NO" }, { "input": "uosgwgsou", "output": "YES" }, { "input": "qjwmjmljq", "output": "YES" }, { "input": "ustrvrodf", "output": "NO" }, { "input": "a", "output": "YES" }, { "input": "qjfyjjyfjq", "output": "NO" }, { "input": "ysxibbixsq", "output": "YES" }, { "input": "howfslfwmh", "output": "NO" }, { "input": "ekhajrjahke", "output": "YES" }, { "input": "ucnolsloncw", "output": "YES" }, { "input": "jrzsfrrkrtj", "output": "NO" }, { "input": "typayzzyapyt", "output": "NO" }, { "input": "uwdhkzokhdwu", "output": "YES" }, { "input": "xokxpyyuafij", "output": "NO" }, { "input": "eusneioiensue", "output": "YES" }, { "input": "fuxpuajabpxuf", "output": "YES" }, { "input": "guvggtfhlgruy", "output": "NO" }, { "input": "cojhkhxxhkhjoc", "output": "NO" }, { "input": "mhifbmmmmbmihm", "output": "YES" }, { "input": "kxfqqncnebpami", "output": "NO" }, { "input": "scfwrjevejrwfcs", "output": "YES" }, { "input": "thdaonpepdoadht", "output": "YES" }, { "input": "jsfzcbnhsccuqsj", "output": "NO" }, { "input": "nn", "output": "NO" }, { "input": "nm", "output": "YES" }, { "input": "jdj", "output": "YES" }, { "input": "bbcaa", "output": "NO" }, { "input": "abcde", "output": "NO" }, { "input": "abcdf", "output": "NO" }, { "input": "aa", "output": "NO" }, { "input": "abecd", "output": "NO" }, { "input": "abccacb", "output": "NO" }, { "input": "aabc", "output": "NO" }, { "input": "anpqb", "output": "NO" }, { "input": "c", "output": "YES" }, { "input": "abcdefg", "output": "NO" }, { "input": "aanbb", "output": "NO" }, { "input": "aabbb", "output": "NO" }, { "input": "aaabbab", "output": "NO" }, { "input": "ab", "output": "YES" }, { "input": "aabbc", "output": "NO" }, { "input": "ecabd", "output": "NO" }, { "input": "abcdrty", "output": "NO" }, { "input": "abcdmnp", "output": "NO" }, { "input": "bbbbbb", "output": "NO" }, { "input": "abcxuio", "output": "NO" }, { "input": "abcdabcde", "output": "NO" }, { "input": "abcxpoi", "output": "NO" }, { "input": "aba", "output": "YES" }, { "input": "aacbb", "output": "NO" }, { "input": "abcedca", "output": "NO" }, { "input": "abcdd", "output": "NO" }, { "input": "abbcs", "output": "NO" }, { "input": "aaabccc", "output": "NO" }, { "input": "paxkxbq", "output": "NO" }, { "input": "z", "output": "YES" }, { "input": "b", "output": "YES" }, { "input": "abcdefghi", "output": "NO" }, { "input": "abcqr", "output": "NO" }, { "input": "abcdc", "output": "NO" }, { "input": "abcb", "output": "NO" }, { "input": "aabcd", "output": "NO" }, { "input": "abbba", "output": "YES" }, { "input": "aaabbb", "output": "NO" }, { "input": "bb", "output": "NO" }, { "input": "aaacbbb", "output": "NO" }, { "input": "abbzcca", "output": "NO" }, { "input": "abxab", "output": "NO" }, { "input": "bbb", "output": "YES" }, { "input": "abcrtyu", "output": "NO" }, { "input": "cbacb", "output": "NO" }, { "input": "acbb", "output": "NO" }, { "input": "ww", "output": "NO" }, { "input": "aaaaaa", "output": "NO" }, { "input": "jizzz", "output": "NO" }, { "input": "aaakcba", "output": "NO" }, { "input": "acbak", "output": "NO" }, { "input": "bddeffd", "output": "NO" }, { "input": "aaa", "output": "YES" }, { "input": "afghqwe", "output": "NO" }, { "input": "abcdfga", "output": "NO" } ]
1,671,961,121
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
7
62
0
def check_palindrome(mytxt): n = len(mytxt) count =0 for i in range(len(mytxt)//2): if mytxt[i] != mytxt[n-1]: count = count+1 n = n-1 return count mytxt = input() a = check_palindrome(mytxt) if a==1: print("YES") else: print("NO")
Title: Mike and palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not. Input Specification: The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15). Output Specification: Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. Demo Input: ['abccaa\n', 'abbcca\n', 'abcda\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: none
```python def check_palindrome(mytxt): n = len(mytxt) count =0 for i in range(len(mytxt)//2): if mytxt[i] != mytxt[n-1]: count = count+1 n = n-1 return count mytxt = input() a = check_palindrome(mytxt) if a==1: print("YES") else: print("NO") ```
0
37
C
Old Berland Language
PROGRAMMING
1,900
[ "data structures", "greedy", "trees" ]
C. Old Berland Language
2
256
Berland scientists know that the Old Berland language had exactly *n* words. Those words had lengths of *l*1,<=*l*2,<=...,<=*l**n* letters. Every word consisted of two letters, 0 and 1. Ancient Berland people spoke quickly and didn’t make pauses between the words, but at the same time they could always understand each other perfectly. It was possible because no word was a prefix of another one. The prefix of a string is considered to be one of its substrings that starts from the initial symbol. Help the scientists determine whether all the words of the Old Berland language can be reconstructed and if they can, output the words themselves.
The first line contains one integer *N* (1<=≤<=*N*<=≤<=1000) — the number of words in Old Berland language. The second line contains *N* space-separated integers — the lengths of these words. All the lengths are natural numbers not exceeding 1000.
If there’s no such set of words, in the single line output NO. Otherwise, in the first line output YES, and in the next *N* lines output the words themselves in the order their lengths were given in the input file. If the answer is not unique, output any.
[ "3\n1 2 3\n", "3\n1 1 1\n" ]
[ "YES\n0\n10\n110\n", "NO\n" ]
none
1,500
[ { "input": "3\n1 2 3", "output": "YES\n0\n10\n110" }, { "input": "3\n1 1 1", "output": "NO" }, { "input": "10\n4 4 4 4 4 4 4 4 4 4", "output": "YES\n0000\n0001\n0010\n0011\n0100\n0101\n0110\n0111\n1000\n1001" }, { "input": "20\n6 7 7 7 7 6 7 7 7 7 7 7 7 7 7 7 7 7 6 7", "output": "YES\n000000\n0000110\n0000111\n0001000\n0001001\n000001\n0001010\n0001011\n0001100\n0001101\n0001110\n0001111\n0010000\n0010001\n0010010\n0010011\n0010100\n0010101\n000010\n0010110" }, { "input": "30\n9 10 8 10 10 10 10 10 7 7 10 10 10 10 10 10 10 10 10 10 9 10 10 10 10 10 10 10 4 3", "output": "YES\n001101010\n0011011000\n00110100\n0011011001\n0011011010\n0011011011\n0011011100\n0011011101\n0011000\n0011001\n0011011110\n0011011111\n0011100000\n0011100001\n0011100010\n0011100011\n0011100100\n0011100101\n0011100110\n0011100111\n001101011\n0011101000\n0011101001\n0011101010\n0011101011\n0011101100\n0011101101\n0011101110\n0010\n000" }, { "input": "50\n10 10 10 10 10 10 9 9 10 10 9 10 10 10 10 9 8 7 8 10 10 10 7 9 10 10 9 9 9 10 10 10 9 10 10 10 10 10 9 10 10 7 8 9 9 8 9 6 6 6", "output": "YES\n0001110010\n0001110011\n0001110100\n0001110101\n0001110110\n0001110111\n000101100\n000101101\n0001111000\n0001111001\n000101110\n0001111010\n0001111011\n0001111100\n0001111101\n000101111\n00010010\n0000110\n00010011\n0001111110\n0001111111\n0010000000\n0000111\n000110000\n0010000001\n0010000010\n000110001\n000110010\n000110011\n0010000011\n0010000100\n0010000101\n000110100\n0010000110\n0010000111\n0010001000\n0010001001\n0010001010\n000110101\n0010001011\n0010001100\n0001000\n00010100\n000110110\n0001..." }, { "input": "100\n17 18 22 15 14 18 9 21 14 19 14 20 12 15 9 23 19 20 19 22 13 22 17 11 21 22 8 17 23 18 21 23 22 23 15 18 21 17 17 9 13 21 23 19 18 23 15 14 17 19 22 23 12 16 23 16 20 9 12 17 18 11 10 17 16 21 8 21 16 19 21 17 12 20 14 16 17 10 22 20 17 13 15 19 9 22 12 20 20 13 19 16 18 7 15 18 6 18 19 21", "output": "YES\n00001011110101100\n000010111101101110\n0000101111011111100110\n000010111100010\n00001011101100\n000010111101101111\n000010000\n000010111101111101010\n00001011101101\n0000101111011101110\n00001011101110\n00001011110111101110\n000010110100\n000010111100011\n000010001\n00001011110111111011100\n0000101111011101111\n00001011110111101111\n0000101111011110000\n0000101111011111100111\n0000101110010\n0000101111011111101000\n00001011110101101\n00001011000\n000010111101111101011\n0000101111011111101001\n00000110..." }, { "input": "20\n4 4 3 4 4 4 4 4 4 4 4 3 3 2 1 4 4 3 3 3", "output": "NO" }, { "input": "30\n6 7 7 6 7 7 7 7 7 7 7 7 7 7 7 5 7 7 7 7 2 1 5 3 7 3 2 7 5 1", "output": "NO" }, { "input": "65\n7 8 6 9 10 9 10 10 9 10 10 10 10 10 10 9 9 10 9 10 10 6 9 7 7 6 8 10 10 8 4 5 2 3 5 3 6 5 2 4 10 4 2 8 10 1 1 4 5 3 8 5 6 7 6 1 10 5 2 8 4 9 1 2 7", "output": "NO" }, { "input": "85\n7 9 8 9 5 6 9 8 10 10 9 10 10 10 10 7 7 4 8 7 7 7 9 10 10 9 10 9 10 10 10 8 8 10 10 10 10 10 10 10 10 10 10 10 10 10 10 9 7 10 4 2 9 3 3 6 2 6 5 6 4 1 7 3 7 7 5 8 4 5 4 1 10 2 9 3 1 4 2 9 9 3 5 6 8", "output": "NO" }, { "input": "10\n4 4 4 4 4 4 4 4 2 2", "output": "YES\n1000\n1001\n1010\n1011\n1100\n1101\n1110\n1111\n00\n01" }, { "input": "20\n5 4 5 5 5 6 5 6 4 5 6 4 5 4 2 4 6 4 4 5", "output": "YES\n10110\n0100\n10111\n11000\n11001\n111100\n11010\n111101\n0101\n11011\n111110\n0110\n11100\n0111\n00\n1000\n111111\n1001\n1010\n11101" }, { "input": "30\n7 8 6 4 2 8 8 7 7 10 4 6 4 7 4 4 7 6 7 9 7 3 5 5 10 4 5 8 5 8", "output": "YES\n1110110\n11111010\n111000\n0110\n00\n11111011\n11111100\n1110111\n1111000\n1111111110\n0111\n111001\n1000\n1111001\n1001\n1010\n1111010\n111010\n1111011\n111111110\n1111100\n010\n11000\n11001\n1111111111\n1011\n11010\n11111101\n11011\n11111110" }, { "input": "50\n4 7 9 7 7 5 5 5 8 9 9 7 9 7 7 6 5 6 4 9 6 5 6 6 5 7 7 6 6 6 5 8 2 7 8 7 6 5 7 9 8 7 5 6 6 8 6 6 7 7", "output": "YES\n0100\n1101110\n111111010\n1101111\n1110000\n01100\n01101\n01110\n11111000\n111111011\n111111100\n1110001\n111111101\n1110010\n1110011\n101010\n01111\n101011\n0101\n111111110\n101100\n10000\n101101\n101110\n10001\n1110100\n1110101\n101111\n110000\n110001\n10010\n11111001\n00\n1110110\n11111010\n1110111\n110010\n10011\n1111000\n111111111\n11111011\n1111001\n10100\n110011\n110100\n11111100\n110101\n110110\n1111010\n1111011" }, { "input": "100\n8 12 6 10 6 11 5 11 11 7 5 6 7 9 11 9 4 11 7 8 12 7 7 7 10 9 6 6 5 7 6 7 10 7 8 7 7 8 9 8 5 10 7 7 6 6 7 8 12 11 5 7 12 10 7 7 10 7 11 11 5 7 6 10 8 6 8 11 8 7 5 7 7 5 6 8 7 7 10 6 5 9 5 5 11 8 7 6 7 8 8 7 7 7 6 6 6 5 8 7", "output": "YES\n11101100\n111111111100\n011100\n1111110010\n011101\n11111110100\n00010\n11111110101\n11111110110\n1011000\n00011\n011110\n1011001\n111110100\n11111110111\n111110101\n0000\n11111111000\n1011010\n11101101\n111111111101\n1011011\n1011100\n1011101\n1111110011\n111110110\n011111\n100000\n00100\n1011110\n100001\n1011111\n1111110100\n1100000\n11101110\n1100001\n1100010\n11101111\n111110111\n11110000\n00101\n1111110101\n1100011\n1100100\n100010\n100011\n1100101\n11110001\n111111111110\n11111111001\n00110\n110..." }, { "input": "20\n2 3 4 4 2 4 4 2 4 4 3 4 4 3 1 3 3 3 2 1", "output": "NO" }, { "input": "30\n6 6 6 5 6 7 3 4 6 5 2 4 6 4 5 4 6 5 4 4 6 6 2 1 4 4 6 1 6 7", "output": "NO" }, { "input": "65\n9 7 8 6 6 10 3 9 10 4 8 3 2 8 9 1 6 3 2 7 9 7 8 10 10 4 5 6 8 8 7 10 10 8 6 6 4 8 8 7 6 9 10 7 8 7 3 3 10 8 9 10 1 9 6 9 2 7 9 10 8 10 3 7 3", "output": "NO" }, { "input": "85\n9 10 4 5 10 4 10 4 5 7 4 8 10 10 9 6 10 10 7 1 10 8 4 4 7 6 3 9 4 4 9 6 3 3 8 9 8 8 10 6 10 10 4 9 6 9 4 3 4 5 8 6 1 5 9 9 9 7 10 10 7 10 4 4 8 2 1 8 10 10 7 1 3 10 7 10 4 5 10 1 10 8 6 2 10", "output": "NO" }, { "input": "200\n11 23 6 1 15 6 5 9 8 9 13 11 7 21 14 17 8 8 12 6 18 4 9 20 3 9 6 9 9 12 18 5 22 5 16 20 11 6 22 10 5 6 8 19 9 12 14 2 10 6 7 7 18 17 4 16 9 13 3 10 15 8 8 9 13 7 8 18 12 12 13 14 9 8 5 5 22 19 23 15 11 7 23 7 5 3 9 3 15 9 22 9 2 11 21 8 12 7 6 8 10 6 12 9 11 8 7 6 5 7 8 9 10 7 19 12 14 9 6 7 2 7 8 4 12 21 14 4 11 12 9 13 17 4 10 8 17 3 9 5 11 6 4 11 1 13 10 10 8 10 14 23 17 8 20 23 23 23 14 7 18 5 10 21 9 7 7 7 4 23 13 8 9 22 7 4 8 12 8 19 17 11 10 8 8 7 7 13 6 13 14 14 22 2 10 11 5 1 14 13", "output": "NO" }, { "input": "1\n1", "output": "YES\n0" }, { "input": "2\n1 1", "output": "YES\n0\n1" }, { "input": "2\n1000 1", "output": "YES\n10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." }, { "input": "3\n1 1 2", "output": "NO" }, { "input": "3\n1 2 1000", "output": "YES\n0\n10\n1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000..." } ]
1,547,316,748
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
8
248
3,584,000
class Node: def __init__(self): self.endWord = False self.children = {} def withC(root, num, s, changed): if root.endWord == True: return '' if num == 0: root.endWord = True if changed == False: return '' return s for c in ['0', '1']: if c not in root.children: root.children[c] = Node() changed = True temp = withC(root.children[c], num-1, s+c, changed) if temp != '': return temp return '' def addNode(root, num): return withC(root, num, '', False) # def addNode(root, num): # cur = root # s = [] # st = [] # changed = False # c = '0' # while num != 0: # if c not in cur.children: # cur.children[c] = Node() # changed = True # num -= 1 # s.append(c) # st.append(cur) # cur = cur.children[c] # else: # if cur.children[c].endWord == True: # c = '1' if c == '0' else '0' # if c not in cur.children: # cur.children[c] = Node() # changed = True # num -= 1 # s.append(c) # st.append(cur) # cur = cur.children[c] # elif cur.children[c].endWord == True: # print('hi') # if len(st) > 0: # num += 1 # cur = st.pop() # s.pop() # c = '1' if c == '0' else '0' # else: # return '' # else: # num -= 1 # s.append(c) # st.append(cur) # cur = cur.children[c] # else: # num -= 1 # s.append(c) # st.append(cur) # cur = cur.children[c] # cur.endWord = True # if changed == False: # return '' # return ''.join(s) def main(): n = int(input()) nums = list(map(int, input().split())) res = [] words = {} root = Node() for num in nums: words[num] = words.get(num, 0) + 1 if words[num] > 2**(num): return [] for num in nums: s = addNode(root, num) res.append(s) return res ans = main() if len(ans) == 0: print('NO') else: print('YES') print('\n'.join(ans))
Title: Old Berland Language Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Berland scientists know that the Old Berland language had exactly *n* words. Those words had lengths of *l*1,<=*l*2,<=...,<=*l**n* letters. Every word consisted of two letters, 0 and 1. Ancient Berland people spoke quickly and didn’t make pauses between the words, but at the same time they could always understand each other perfectly. It was possible because no word was a prefix of another one. The prefix of a string is considered to be one of its substrings that starts from the initial symbol. Help the scientists determine whether all the words of the Old Berland language can be reconstructed and if they can, output the words themselves. Input Specification: The first line contains one integer *N* (1<=≤<=*N*<=≤<=1000) — the number of words in Old Berland language. The second line contains *N* space-separated integers — the lengths of these words. All the lengths are natural numbers not exceeding 1000. Output Specification: If there’s no such set of words, in the single line output NO. Otherwise, in the first line output YES, and in the next *N* lines output the words themselves in the order their lengths were given in the input file. If the answer is not unique, output any. Demo Input: ['3\n1 2 3\n', '3\n1 1 1\n'] Demo Output: ['YES\n0\n10\n110\n', 'NO\n'] Note: none
```python class Node: def __init__(self): self.endWord = False self.children = {} def withC(root, num, s, changed): if root.endWord == True: return '' if num == 0: root.endWord = True if changed == False: return '' return s for c in ['0', '1']: if c not in root.children: root.children[c] = Node() changed = True temp = withC(root.children[c], num-1, s+c, changed) if temp != '': return temp return '' def addNode(root, num): return withC(root, num, '', False) # def addNode(root, num): # cur = root # s = [] # st = [] # changed = False # c = '0' # while num != 0: # if c not in cur.children: # cur.children[c] = Node() # changed = True # num -= 1 # s.append(c) # st.append(cur) # cur = cur.children[c] # else: # if cur.children[c].endWord == True: # c = '1' if c == '0' else '0' # if c not in cur.children: # cur.children[c] = Node() # changed = True # num -= 1 # s.append(c) # st.append(cur) # cur = cur.children[c] # elif cur.children[c].endWord == True: # print('hi') # if len(st) > 0: # num += 1 # cur = st.pop() # s.pop() # c = '1' if c == '0' else '0' # else: # return '' # else: # num -= 1 # s.append(c) # st.append(cur) # cur = cur.children[c] # else: # num -= 1 # s.append(c) # st.append(cur) # cur = cur.children[c] # cur.endWord = True # if changed == False: # return '' # return ''.join(s) def main(): n = int(input()) nums = list(map(int, input().split())) res = [] words = {} root = Node() for num in nums: words[num] = words.get(num, 0) + 1 if words[num] > 2**(num): return [] for num in nums: s = addNode(root, num) res.append(s) return res ans = main() if len(ans) == 0: print('NO') else: print('YES') print('\n'.join(ans)) ```
-1
747
B
Mammoth's Genome Decoding
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s* is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'. It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal. Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal.
The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome. The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'.
If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes).
[ "8\nAG?C??CT\n", "4\nAGCT\n", "6\n????G?\n", "4\nAA??\n" ]
[ "AGACGTCT\n", "AGCT\n", "===\n", "===\n" ]
In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is exactly once in it. In the third and the fourth examples it is impossible to decode the genom.
1,000
[ { "input": "8\nAG?C??CT", "output": "AGACGTCT" }, { "input": "4\nAGCT", "output": "AGCT" }, { "input": "6\n????G?", "output": "===" }, { "input": "4\nAA??", "output": "===" }, { "input": "4\n????", "output": "ACGT" }, { "input": "252\n???????GCG??T??TT?????T?C???C?CCG???GA???????AC??A???AAC?C?CC??CCC??A??TA?CCC??T???C??CA???CA??G????C?C?C????C??C??A???C?T????C??ACGC??CC?A?????A??CC?C??C?CCG?C??C??A??CG?A?????A?CT???CC????CCC?CATC?G??????????A???????????????TCCCC?C?CA??AC??GC????????", "output": "AAAAAAAGCGAATAATTAAAAATACAAACACCGAAAGAAAAAAAAACAAAAAAAACACACCAACCCAAAACTACCCCCCTCCCCCGCAGGGCAGGGGGGGCGCGCGGGGCGGCGGAGGGCGTGGGGCGGACGCGGCCGAGGGGGAGGCCGCGGCGCCGGCGGCGGAGGCGGAGTTTTATCTTTTCCTTTTCCCTCATCTGTTTTTTTTTTATTTTTTTTTTTTTTTTCCCCTCTCATTACTTGCTTTTTTTT" }, { "input": "255\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "===" }, { "input": "4\n??A?", "output": "CGAT" }, { "input": "4\n?C??", "output": "ACGT" }, { "input": "4\nT???", "output": "TACG" }, { "input": "4\n???G", "output": "ACTG" }, { "input": "4\n??AC", "output": "GTAC" }, { "input": "8\n?C?AA???", "output": "CCGAAGTT" }, { "input": "12\n???A?G???A?T", "output": "ACCACGGGTATT" }, { "input": "16\n?????C??CAG??T??", "output": "AAACCCGGCAGGTTTT" }, { "input": "20\n???A?G??C?GC???????G", "output": "AAAAAGCCCCGCGGTTTTTG" }, { "input": "24\n?TG???AT?A?CTTG??T?GCT??", "output": "ATGAAAATCACCTTGCCTGGCTGG" }, { "input": "28\n??CTGAAG?GGT?CC?A??TT?CCACG?", "output": "AACTGAAGAGGTCCCGAGTTTTCCACGT" }, { "input": "32\n??A?????CAAG?C?C?CG??A?A??AAC?A?", "output": "CCACGGGGCAAGGCGCTCGTTATATTAACTAT" }, { "input": "36\n?GCC?CT?G?CGG?GCTGA?C?G?G????C??G?C?", "output": "AGCCACTAGACGGAGCTGAACAGAGCTTTCTTGTCT" }, { "input": "40\nTA?AA?C?G?ACC?G?GCTCGC?TG??TG?CT?G??CC??", "output": "TAAAAACAGAACCAGAGCTCGCCTGGGTGGCTTGTTCCTT" }, { "input": "44\nT?TA??A??AA???A?AGTA??TAT??ACTGAT??CT?AC?T??", "output": "TCTACCACCAACCCAGAGTAGGTATGGACTGATGGCTGACGTTT" }, { "input": "48\nG?G??GC??CA?G????AG?CA?CG??GGCCCCAA??G??C?T?TCA?", "output": "GAGAAGCAACAAGCCGGAGGCATCGTTGGCCCCAATTGTTCTTTTCAT" }, { "input": "52\n??G?G?CTGT??T?GCGCT?TAGGTT??C???GTCG??GC??C???????CG", "output": "AAGAGACTGTAATAGCGCTATAGGTTAACAACGTCGCCGCCCCGGTTTTTCG" }, { "input": "56\n?GCCA?GC?GA??GA??T?CCGC?????TGGC?AGGCCGC?AC?TGAT??CG?A??", "output": "AGCCAAGCAGAAAGAAATCCCGCCGGTTTGGCTAGGCCGCTACTTGATTTCGTATT" }, { "input": "60\nAT?T?CCGG??G?CCT?CCC?C?CGG????TCCCG?C?TG?TT?TA??A?TGT?????G?", "output": "ATATACCGGAAGACCTACCCACACGGAAAATCCCGCCCTGGTTGTAGGAGTGTGTTTTGT" }, { "input": "64\n?G??C??????C??C??AG?T?GC?TT??TAGA?GA?A??T?C???TC??A?CA??C??A???C", "output": "AGAACAAAAACCCCCCCAGCTCGCGTTGGTAGAGGAGAGGTGCGGGTCTTATCATTCTTATTTC" }, { "input": "68\nC?T??????C????G?T??TTT?T?T?G?CG??GCC??CT??????C??T?CC?T?T????CTT?T??", "output": "CATAAAAAACAAAAGATAATTTATATAGCCGCCGCCCCCTCCGGGGCGGTGCCGTGTGGGGCTTTTTT" }, { "input": "72\nA?GTA??A?TG?TA???AAAGG?A?T?TTAAT??GGA?T??G?T?T????TTATAAA?AA?T?G?TGT??TG", "output": "AAGTACCACTGCTACCCAAAGGCACTCTTAATCCGGACTCCGCTCTCGGGTTATAAAGAAGTGGGTGTGTTG" }, { "input": "76\nG?GTAC?CG?AG?AGC???A??T?TC?G??C?G?A???TC???GTG?C?AC???A??????TCA??TT?A?T?ATG", "output": "GAGTACACGAAGAAGCAAAAAATCTCCGCCCCGCACCCTCCGGGTGGCGACGGGAGGTTTTTCATTTTTATTTATG" }, { "input": "80\nGG???TAATT?A?AAG?G?TT???G??TTA?GAT?????GT?AA?TT?G?AG???G?T?A??GT??TTT?TTG??AT?T?", "output": "GGAAATAATTAAAAAGAGATTACCGCCTTACGATCCCCCGTCAACTTCGCAGCCCGCTCACGGTGGTTTGTTGGGATGTG" }, { "input": "84\n?C??G??CGGC????CA?GCGG???G?CG??GA??C???C???GC???CG?G?A?C?CC?AC?C?GGAG???C??????G???C", "output": "ACAAGAACGGCAAAACAAGCGGAAAGACGAAGACCCCCGCGGGGCGTTCGTGTATCTCCTACTCTGGAGTTTCTTTTTTGTTTC" }, { "input": "88\nGTTC?TCTGCGCGG??CATC?GTGCTCG?A?G?TGCAGCAG??A?CAG???GGTG?ATCAGG?TCTACTC?CG?GGT?A?TCC??AT?", "output": "GTTCATCTGCGCGGAACATCAGTGCTCGAAAGATGCAGCAGAAAACAGACCGGTGCATCAGGCTCTACTCGCGTGGTTATTCCTTATT" }, { "input": "92\n??TT????AT?T????A???TC????A?C????AT???T?T???T??A???T??TTA?AT?AA?C????C??????????????TAA?T???", "output": "AATTAAAAATATAAAAAACCTCCCCCACCCCCCATCCCTCTCCCTCGAGGGTGGTTAGATGAAGCGGGGCGGGGGGGGGGTTTTTAATTTTT" }, { "input": "96\nT?????C?CT?T??GGG??G??C???A?CC??????G???TCCCT??C?G??GC?CT?CGT?GGG??TCTC?C?CCGT?CCTCTT??CC?C?????", "output": "TAAAAACACTATAAGGGAAGAACAAAAACCAAAAAAGCGGTCCCTGGCGGGGGCGCTGCGTGGGGGGTCTCTCTCCGTTCCTCTTTTCCTCTTTTT" }, { "input": "100\n???GGA?C?A?A??A?G??GT?GG??G????A?ATGGAA???A?A?A?AGAGGT?GA?????AA???G???GA???TAGAG?ACGGA?AA?G???GGGAT", "output": "ACCGGACCCACACCACGCCGTCGGCCGCCCCACATGGAACCCACACAGAGAGGTGGATTTTTAATTTGTTTGATTTTAGAGTACGGATAATGTTTGGGAT" }, { "input": "104\n???TTG?C???G?G??G??????G?T??TC???CCC????TG?GGT??GG?????T?CG???GGG??GTC?G??TC??GG??CTGGCT??G????C??????TG", "output": "AAATTGACAAAGAGAAGAAAAAAGATAATCAAACCCAAAATGCGGTCCGGCCCCCTCCGCCCGGGCCGTCCGGGTCGGGGTTCTGGCTTTGTTTTCTTTTTTTG" }, { "input": "108\n??CAC?A?ACCA??A?CA??AA?TA?AT?????CCC????A??T?C?CATA??CAA?TACT??A?TA?AC?T??G???GG?G??CCC??AA?CG????T?CT?A??AA", "output": "AACACAACACCACCACCACCAACTACATCGGGGCCCGGGGAGGTGCGCATAGGCAAGTACTGGAGTAGACGTGGGTTTGGTGTTCCCTTAATCGTTTTTTCTTATTAA" }, { "input": "112\n???T?TC?C?AC???TC?C???CCC??C????C?CCGC???TG?C?T??????C?C?????G?C????A????????G?C?A?C?A?C?C??C????CC?TC??C??C?A??", "output": "AAATATCACAACAAATCACAAACCCAACAAAACACCGCAAATGCCGTGGGGGGCGCGGGGGGGCGGGGAGGGGGGTTGTCTATCTATCTCTTCTTTTCCTTCTTCTTCTATT" }, { "input": "116\n????C??A?A??AAC???????C???CCCTC??A????ATA?T??AT???C?TCCC???????C????CTC??T?A???C??A???CCA?TAC?AT?????C??CA???C?????C", "output": "AAAACAAAAAAAAACAAAAAACCCCCCCCTCCCACGGGATAGTGGATGGGCGTCCCGGGGGGGCGGGGCTCGGTGAGGGCGGATTTCCATTACTATTTTTTCTTCATTTCTTTTTC" }, { "input": "120\nTC?AGATG?GAT??G????C?C??GA?GT?TATAC?AGA?TCG?TCT???A?AAA??C?T?A???AA?TAC?ATTT???T?AA?G???TG?AT???TA??GCGG?AC?A??AT??T???C", "output": "TCAAGATGAGATAAGAACCCCCCCGACGTCTATACCAGACTCGCTCTCCCACAAACCCCTCACGGAAGTACGATTTGGGTGAAGGGGGTGGATGGGTAGTGCGGTACTATTATTTTTTTC" }, { "input": "124\n???C?????C?AGG??A?A?CA????A??A?AA??A????????G?A?????????AG?A??G?C??A??C???G??CG??C???????A????C???AG?AA???AC????????????C??G", "output": "AAACAAAAACAAGGAAAAAACACCCCACCACAACCACCCCCCCCGCACCCGGGGGGAGGAGGGGCGGAGGCGGGGGGCGGGCGTTTTTTATTTTCTTTAGTAATTTACTTTTTTTTTTTTCTTG" }, { "input": "128\nAT?GC?T?C?GATTTG??ATTGG?AC?GGCCA?T?GG?CCGG??AGT?TGT?G??A?AAGGCGG?T??TCT?CT??C?TTGTTG??????CCGG?TGATAT?T?TTGTCCCT??CTGTGTAATA??G?", "output": "ATAGCATACAGATTTGAAATTGGAACAGGCCAATAGGACCGGAAAGTATGTAGAAAAAAGGCGGCTCCTCTCCTCCCCTTGTTGCCCCCCCCGGCTGATATCTGTTGTCCCTGGCTGTGTAATAGGGT" }, { "input": "132\nAC???AA??T???T??G??ACG?C??AA?GA?C???CGAGTA?T??TTGTC???GCTGATCA????C??TA???ATTTA?C??GT??GTCTCTCGT?AAGGACTG?TC????T???C?T???ATTTT?T?AT", "output": "ACAAAAAAATAAATAAGAAACGACACAACGACCCCCCGAGTACTCCTTGTCCCCGCTGATCACCCCCCGTAGGGATTTAGCGGGTGGGTCTCTCGTGAAGGACTGGTCGGGGTGGGCGTTTTATTTTTTTAT" }, { "input": "136\n?A?C???????C??????????????C?????C???????????CCCC?????????C??????C??C??????CC??C??C?C???C??????C??C?C??????????C?????????GC????C???????C?", "output": "AAACAAAAAAACAAAAAAAAAAAAAACAAAAACAAAAACCCCCCCCCCCCCCGGGGGCGGGGGGCGGCGGGGGGCCGGCGGCGCGGGCGGGGGGCTTCTCTTTTTTTTTTCTTTTTTTTTGCTTTTCTTTTTTTCT" }, { "input": "140\nTTG??G?GG?G??C??CTC?CGG?TTCGC????GGCG?G??TTGCCCC?TCC??A??CG?GCCTTT?G??G??CT??TG?G?TTC?TGC?GG?TGT??CTGGAT??TGGTTG??TTGGTTTTTTGGTCGATCGG???C??", "output": "TTGAAGAGGAGAACAACTCACGGATTCGCAAAAGGCGAGAATTGCCCCATCCAAAAACGAGCCTTTAGAAGAACTAATGAGATTCCTGCCGGCTGTCCCTGGATCCTGGTTGCCTTGGTTTTTTGGTCGATCGGCCCCTT" }, { "input": "144\n?????A?C?A?A???TTT?GAATA?G??T?T?????AT?AA??TT???TT??A?T????AT??TA??AA???T??A??TT???A????T???T????A??T?G???A?C?T????A?AA??A?T?C??A??A???AA????ATA", "output": "AAAAAAACAAAACCCTTTCGAATACGCCTCTCCCCCATCAACCTTCCCTTCCACTCCCCATCCTACCAACCCTGGAGGTTGGGAGGGGTGGGTGGGGAGGTGGGGGAGCGTGGGGAGAAGGATTTCTTATTATTTAATTTTATA" }, { "input": "148\nACG?GGGT?A??C????TCTTGCTG?GTA?C?C?TG?GT??GGGG??TTG?CA????GT???G?TT?T?CT?C??C???CTTCATTA?G?G???GC?AAT??T???AT??GGATT????TC?C???????T??TATCG???T?T?CG?", "output": "ACGAGGGTAAAACAAAATCTTGCTGAGTAACACATGAGTAAGGGGAATTGACAAAAAGTAAAGATTCTCCTCCCCCCCCCTTCATTACGCGCCCGCCAATCCTCCCATCGGGATTGGGGTCGCGGGGGGGTGTTATCGTTTTTTTCGT" }, { "input": "152\n??CTA??G?GTC?G??TTCC?TG??????T??C?G???G?CC???C?GT?G?G??C?CGGT?CC????G?T?T?C?T??G?TCGT??????A??TCC?G?C???GTT?GC?T?CTT?GT?C??C?TCGTTG?TTG?G????CG?GC??G??G", "output": "AACTAAAGAGTCAGAATTCCATGAAAAAATAACAGAAAGACCAAACAGTAGAGAACACGGTACCAAAAGCTCTCCCTCCGCTCGTCCCCCCACGTCCGGGCGGGGTTGGCGTGCTTGGTGCGTCTTCGTTGTTTGTGTTTTCGTGCTTGTTG" }, { "input": "156\nGCA????A???AAT?C??????GAG?CCA?A?CG??ACG??????GCAAAC??GCGGTCC??GT???C???????CC???????ACGCA????C??A??CC??A?GAATAC?C?CA?CCCT?TCACA?A???????C??TAG?C??T??A??A?CA", "output": "GCAAAAAAAAAAATACAAAAACGAGCCCACACCGCCACGCCCGGGGCAAACGGGCGGTCCGGGTGGGCGGGGGGGCCGGGGGGGACGCAGGTTCTTATTCCTTATGAATACTCTCATCCCTTTCACATATTTTTTTCTTTAGTCTTTTTATTATCA" }, { "input": "160\nGCACC????T?TGATAC??CATATCC?GT?AGT?ATGGATA?CC?????GCTCG?A?GG?A?GCCAG??C?CGGATC?GCAA?AAGCCCCC?CAT?GA?GC?CAC?TAA?G?CACAACGG?AAA??CA?ACTCGA?CAC?GAGCAAC??A?G?AAA?TC?", "output": "GCACCACCCTGTGATACGGCATATCCGGTGAGTGATGGATAGCCGGGGGGCTCGGAGGGGATGCCAGTTCTCGGATCTGCAATAAGCCCCCTCATTGATGCTCACTTAATGTCACAACGGTAAATTCATACTCGATCACTGAGCAACTTATGTAAATTCT" }, { "input": "164\nGA?AGGT???T?G?A?G??TTA?TGTG?GTAGT?????T??TTTG?A?T??T?TA?G?T?GGT?????TGTGG?A?A?T?A?T?T?????TT?AAGAG?????T??TATATG?TATT??G?????GGGTATTTT?GG?A??TG??T?GAATGTG?AG?T???A?", "output": "GAAAGGTAAATAGAAAGAATTAATGTGAGTAGTAAAAATAATTTGAACTCCTCTACGCTCGGTCCCCCTGTGGCACACTCACTCTCCCCCTTCAAGAGCCCCCTCCTATATGCTATTCCGCCCCCGGGTATTTTCGGCAGGTGGGTGGAATGTGGAGGTGGGAG" }, { "input": "168\n?C?CAGTCCGT?TCC?GCG?T??T?TA?GG?GCTTGTTTTGT??GC???CTGT??T?T?C?ACG?GTGG??C??TC?GT??CTT?GGT??TGGC??G?TTTCTT?G??C?CTC??CT?G?TT?CG?C?A???GCCGTGAG?CTTC???TTCTCGG?C?CC??GTGCTT", "output": "ACACAGTCCGTATCCAGCGATAATATAAGGAGCTTGTTTTGTAAGCAAACTGTAATATACAACGAGTGGAACAATCAGTAACTTAGGTAATGGCAAGATTTCTTAGAACCCTCCCCTCGCTTCCGCCCACGGGCCGTGAGGCTTCGGGTTCTCGGGCGCCGGGTGCTT" }, { "input": "172\nG?ATG??G?TTT?ATA?GAAGCACTTGCT?AGC??AG??GTTCG?T?G??G?AC?TAGGGCT?TA?TTCTA?TTCAGGAA?GGAAATTGAAG?A?CT?GGTGAGTCTCT?AAACAGT??T??TCAGG?AGTG?TT?TAAT??GG?G?GCA???G?GGA?GACGAATACTCAA", "output": "GAATGAAGATTTAATACGAAGCACTTGCTCAGCCCAGCCGTTCGCTCGCCGCACCTAGGGCTCTACTTCTACTTCAGGAACGGAAATTGAAGCACCTCGGTGAGTCTCTCAAACAGTCCTCCTCAGGCAGTGGTTGTAATGGGGTGTGCATTTGTGGATGACGAATACTCAA" }, { "input": "176\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "180\n?GTTACA?A?A?G??????GGGA?A??T?????C?AC??GG???G????T??CC??T?CGG?AG???GAAGG?????A?GT?G?????CTAA?A??C?A???A?T??C?A???AAA???G?GG?C?A??C???????GTCC?G??GT??G?C?G?C????TT??G????A???A???A?G", "output": "AGTTACAAAAAAGAAAAAAGGGAAAAATAAAAACAACAAGGCCCGCCCCTCCCCCCTCCGGCAGCCCGAAGGCCCCCACGTCGCCCCCCTAACACGCGAGGGAGTGGCGAGGGAAAGGGGGGGGCGAGTCTTTTTTTGTCCTGTTGTTTGTCTGTCTTTTTTTTGTTTTATTTATTTATG" }, { "input": "184\n?CTC?A??????C?T?TG??AC??????G???CCT????CT?C?TT???C???AT????????????T??T?A?AGT?C?C?C?C?CG??CAT?C??C???T??T?TCCTC????C??A???CG?C???C??TC??C?G?C????CTT????C??A?AT??C????T?TCT?T???C?CT??C?", "output": "ACTCAAAAAAAACATATGAAACAAAAAAGAAACCTAAAACTACATTAAACAAAATAAAACCCCCCCCTCCTCACAGTGCGCGCGCGCGGGCATGCGGCGGGTGGTGTCCTCGGGGCGGAGGGCGGCGGGCGGTCGGCGGGCGGGGCTTGTTTCTTATATTTCTTTTTTTCTTTTTTCTCTTTCT" }, { "input": "188\n????TG??A?G?GG?AGA??T??G?TA?ATTT?TTGA??TTA??T?G???GA?G?A??GG??ACTTGT?T?T?TCT?TG?TGAG??GT?A???TT?G???????TA???G?G?GTAG?G?T????????A?TT?TT?T??GGTGT??TTT?T?T?TT???GAGA??G?GGG?G??TG?GT?GT?A??T", "output": "AAAATGAAAAGAGGAAGAAATAAGATAAATTTATTGAAATTAAATAGAAAGAAGAAAAGGACACTTGTCTCTCTCTCTGCTGAGCCGTCACCCTTCGCCCCCCCTACCCGCGCGTAGCGCTCCCCCCCCACTTCTTCTCCGGTGTCCTTTCTCTCTTGGGGAGAGGGGGGGGGGGTGGGTGGTTATTT" }, { "input": "192\nTT???TA?A?TTCTCA?ATCCCC?TA?T??A?A?TGT?TT??TAA?C?C?TA?CTAAAT???AA?TT???T?AATAG?AC??AC?A??A?TT?A?TT?AA?TCTTTC??A?AAA?AA??T?AG?C??AT?T?TATCT?CTTCAA?ACAAAT???AT?TT??????C?CTC???TT?ACACACTGCA?AC??T", "output": "TTAACTACACTTCTCACATCCCCCTACTCCACACTGTCTTCCTAACCCCCTACCTAAATCCCAACTTCGGTGAATAGGACGGACGAGGAGTTGAGTTGAAGTCTTTCGGAGAAAGAAGGTGAGGCGGATGTGTATCTGCTTCAAGACAAATGGGATGTTGGGGGGCGCTCGGGTTGACACACTGCAGACTTT" }, { "input": "196\n??ACATCC??TGA?C?AAA?A???T????A??ACAC????T???????CCC?AAT?T?AT?A?A??TATC??CC?CCACACA?CC?A?AGC??AAA??A???A?CA??A?AT??G???CA?ACATTCG??CACAT?AC???A?A?C?CTTT?AAG??A?TAC???C?GCAA?T??C??AA???GAC?ATTAT????", "output": "ACACATCCCCTGACCCAAACACCCTCCCCACCACACCGGGTGGGGGGGCCCGAATGTGATGAGAGGTATCGGCCGCCACACAGCCGAGAGCGGAAAGGAGGGAGCAGGAGATGGGGGGCAGACATTCGGGCACATTACTTTATATCTCTTTTAAGTTATTACTTTCTGCAATTTTCTTAATTTGACTATTATTTTT" }, { "input": "200\n?CT?T?C???AC?G?CAC?C?T??T?G?AGAGTA?CT????A?CCCAT?GCT?TTC?CAG???TCCATAAC?GACT?TC??C?AG?AA?A?C??ATC?CTAT?AC??????ACCGA??A????C?AA???CGCTTCGC?A????A??GCC?AG?T?????T?A?C?A?CTTC?????T?T?????GC?GTACTC??TG??", "output": "ACTATACAAAACAGACACACATAATAGAAGAGTAACTAAAAAACCCATCGCTCTTCCCAGCCCTCCATAACCGACTCTCCCCCAGCAAGAGCGGATCGCTATGACGGGGGGACCGAGGAGGGGCGAAGGGCGCTTCGCGAGGGGAGGGCCGAGGTGGGTTTTATCTATCTTCTTTTTTTTTTTTTGCTGTACTCTTTGTT" }, { "input": "204\n??????T???T?GC?TC???TA?TC?????A??C?C??G??????G?CTC????A?CTTT?T???T??CTTA???????T??C??G????A?????TTTA??AT?A??C?C?T?C???C?????T???????GT????T????AT?CT????C??C??T???C????C?GCTTCCC?G?????T???C?T??????????TT??", "output": "AAAAAATAAATAGCATCAAATAATCAAAAAAAACACAAGAAAAAAGACTCAAAAAACTTTATAAATACCTTACCCCCCCTCCCCCGCCCCACCCCCTTTACCATCACCCCCGTGCGGGCGGGGGTGGGGGGGGTGGGGTGGGGATGCTGGGGCGGCGGTGGGCGGGGCGGCTTCCCGGGTTTTTTTTCTTTTTTTTTTTTTTTT" }, { "input": "208\nA?GGT?G??A???????G??A?A?GA?T?G???A?AAG?AT????GG?????AT??A?A???T?A??????A????AGGCGT???A???TA????TGGT???GA????GGTG???TA??GA??TA?GGG?????G?????AT?GGGG??TG?T?AA??A??AG?AA?TGA???A?A?GG???GAAT?G?T??T?A??G?CAGT?T?A?", "output": "AAGGTAGAAAAAAAAAAGAAAAAAGAATCGCCCACAAGCATCCCCGGCCCCCATCCACACCCTCACCCCCCACCCCAGGCGTCCCACCCTACCCCTGGTCCCGACCCCGGTGCGGTAGGGAGGTAGGGGGGGGGGGGGGTATTGGGGTTTGTTTAATTATTAGTAATTGATTTATATGGTTTGAATTGTTTTTTATTGTCAGTTTTAT" }, { "input": "212\nT?TTT?A??TC?????A?T??T????T????????C??T??AT????????T???TT????T?TTT??????????TTC???T?T?C??T?TA?C??TTT????T???????C????????A?TT???T??TTT??AT?T????T????T?????A??C????T??T???TA???A?????????T???C????????C???T?TA???TTT", "output": "TATTTAAAATCAAAAAAATAATAAAATAAAAAAAACAATAAATAAAAAAAATAAATTAAAATCTTTCCCCCCCCCCTTCCCCTCTCCCCTCTACCCCTTTCCCCTCCCCCCCCCCCCCCCCACTTCCGTGGTTTGGATGTGGGGTGGGGTGGGGGAGGCGGGGTGGTGGGTAGGGAGGGGGGGGGTGGGCGGGGGGGGCTTTTTTATTTTTT" }, { "input": "216\n?CT?A?CC?GCC?C?AT?A???C???TA????ATGTCCG??CCG?CGG?TCC?TTC??CCT????????G?GGC?TACCCGACCGAG?C???C?G?G??C??CGTCCTG??AGG??CT?G???TC?CT????A?GTA??C?C?CTGTTAC??C?TCT?C?T???T??GTGGA?AG?CGCT?CGTC???T?C?T?C?GTT???C??GCC?T??C?T?", "output": "ACTAAACCAGCCACAATAAAAACAAATAAAAAATGTCCGAACCGACGGATCCATTCAACCTAAAAAAAAGAGGCATACCCGACCGAGACAAACAGAGCCCCCCGTCCTGCGAGGGGCTGGGGGTCGCTGGGGAGGTAGGCGCGCTGTTACGGCGTCTGCGTGGGTTTGTGGATAGTCGCTTCGTCTTTTTCTTTCTGTTTTTCTTGCCTTTTCTTT" }, { "input": "220\n?GCC??????T????G?CTC???CC?C????GC??????C???TCCC???????GCC????????C?C??C?T?C?CC????CC??C???????CC??C?G?A?T???CC??C????????C????CTA?GC?????CC??C?C?????T?????G?????????G???AC????C?CG?????C?G?C?CG?????????G?C????C?G??????C??", "output": "AGCCAAAAAATAAAAGACTCAAACCACAAAAGCAAAAAACAAATCCCAAAAAAAGCCAAAAAAAACACAACATACACCAACCCCCCCCCCCCCGCCGGCGGGAGTGGGCCGGCGGGGGGGGCGGGGCTAGGCGGGGGCCGGCGCGGGGGTGGGGGGTTTTTTTTTGTTTACTTTTCTCGTTTTTCTGTCTCGTTTTTTTTTGTCTTTTCTGTTTTTTCTT" }, { "input": "224\nTTGC?G??A?ATCA??CA???T?TG?C?CGA?CTTA?C??C?TTC?AC?CTCA?A?AT?C?T?CT?CATGT???A??T?CT????C?AACT?TTCCC??C?AAC???AC?TTTC?TTAAA??????TGT????CGCT????GCCC?GCCCA?????TCGA??C?TATACA??C?CC?CATAC?GGACG??GC??GTT?TT?T???GCT??T?C?T?C??T?CC?", "output": "TTGCAGAAAAATCAAACAAAATATGACACGAACTTAACAACATTCAACACTCAAAAATACATACTACATGTAAAACCTCCTCCCCCCAACTGTTCCCGGCGAACGGGACGTTTCGTTAAAGGGGGGTGTGGGGCGCTGGGGGCCCGGCCCAGGGGGTCGAGGCGTATACAGGCGCCGCATACGGGACGGGGCGTGTTTTTTTTTTGCTTTTTCTTTCTTTTCCT" }, { "input": "228\nA??A?C???AG?C?AC???A?T?????AA??????C?A??A?AC?????C?C???A??????A???AC?C????T?C?AA?C??A???CC??????????????????A???CC????A?????C??TC???A???????????A??A????????????????CC?????CCA??????????????C??????C????T?CT???C???A???T?CC?G??C??A?", "output": "AAAAACAAAAGACAACAAAAATAAAAAAAAAAAAACAAAAAAACAAAAACACCCCACCCCCCACCCACCCCCCCTCCCAACCCCACCCCCCCCCGGGGGGGGGGGGGGAGGGCCGGGGAGGGGGCGGTCGGGAGGGGGGGGGGGAGGAGGGGGGGGGGGTTTTTCCTTTTTCCATTTTTTTTTTTTTTCTTTTTTCTTTTTTCTTTTCTTTATTTTTCCTGTTCTTAT" }, { "input": "232\nA??AAGC?GCG?AG???GGGCG?C?A?GCAAC?AG?C?GC??CA??A??CC?AA?A????G?AGA?ACACA?C?G?G?G?CGC??G???????GAGC?CAA??????G?A???AGGG?????AAC?AG?A?A??AG?CG?G???G????GGGA?C?G?A?A??GC????C??A?ACG?AA?G?ACG????AC?C?GA??GGCAG?GAA??ACA??A?AGGAGG???CGGA?C", "output": "AAAAAGCAGCGAAGAAAGGGCGACAAAGCAACCAGCCCGCCCCACCACCCCCAACACCCCGCAGACACACACCCGCGCGCCGCCCGCCCGGGGGAGCGCAAGGGGGTGTATTTAGGGTTTTTAACTAGTATATTAGTCGTGTTTGTTTTGGGATCTGTATATTGCTTTTCTTATACGTAATGTACGTTTTACTCTGATTGGCAGTGAATTACATTATAGGAGGTTTCGGATC" }, { "input": "236\nAAGCCC?A?TT??C?AATGC?A?GC?GACGT?CTT?TA??CCG?T?CAA?AGT?CTG???GCGATG?TG?A?A?ACT?AT?GGG?GC?C?CGCCCTT?GT??G?T?????GACTT??????CT?GA?GG?C?T?G??CTG??G??TG?TCA?TCGTT?GC?A?G?GGGT?CG?CGAG??CG?TC?TAT?A???T??GAGTC?CGGC?CG??CT?TAAT??GGAA?G??GG?GCGAC", "output": "AAGCCCAAATTAACAAATGCAAAGCAGACGTACTTATAAACCGATACAAAAGTACTGAAAGCGATGATGAAAAAACTAATAGGGAGCACACGCCCTTAGTACGCTCCCCCGACTTCCCCCCCTCGACGGCCCTCGCCCTGCGGGGTGGTCAGTCGTTGGCGAGGGGGGTGCGTCGAGTTCGTTCTTATTATTTTTTGAGTCTCGGCTCGTTCTTTAATTTGGAATGTTGGTGCGAC" }, { "input": "240\n?T?A?A??G????G????AGGAGTAA?AGGCT??C????AT?GAA?ATGCT???GA?G?A??G?TC??TATT???AG?G?G?A?A??TTGT??GGTCAG?GA?G?AAT?G?GG??CAG?T?GT?G?GC???GC??????GA?A?AAATGGGC??G??????TTA??GTCG?TC?GCCG?GGGA??T?A????T?G?T???G?GG?ATG???A?ATGAC?GGT?CTG?AGGG??TAGT?AG", "output": "ATAAAAAAGAAAAGAAAAAGGAGTAAAAGGCTAACAAAAATAGAAAATGCTACCGACGCACCGCTCCCTATTCCCAGCGCGCACACCTTGTCCGGTCAGCGACGCAATCGCGGCCCAGCTCGTCGCGCCCCGCCCCCCCGACACAAATGGGCCCGCGGGGGTTATTGTCGTTCTGCCGTGGGATTTTATTTTTTGTTTTTGTGGTATGTTTATATGACTGGTTCTGTAGGGTTTAGTTAG" }, { "input": "244\nC?GT???T??TA?CC??TACT???TC?C?A???G??G?TCC?AC??AA???C?CCACC????A?AGCC??T?CT??CCGG?CC?T?C??GCCCTGGCCAAAC???GC?C???AT?CC?CT?TAG??CG?C?T?C??A?AC?GC????A??C?C?A??TC?T????GCCCT??GG???CC?A?CC?G?A?CA?G??CCCG??CG?T?TAC?G???C?AC??G??CCA???G????C??G?CT?C?", "output": "CAGTAAATAATAACCAATACTAAATCACAAAAAGAAGATCCAACAAAAAAACACCACCAAAAAAAGCCAATACTAACCGGGCCGTGCGGGCCCTGGCCAAACGGGGCGCGGGATGCCGCTGTAGGGCGGCGTGCGGAGACGGCGGGGAGGCGCGAGGTCGTGGTTGCCCTTTGGTTTCCTATCCTGTATCATGTTCCCGTTCGTTTTACTGTTTCTACTTGTTCCATTTGTTTTCTTGTCTTCT" }, { "input": "248\n??TC???TG??G??T????CC???C?G?????G?????GT?A?CT?AAT?GG?AGA?????????G???????G???CG??AA?A????T???????TG?CA????C?TT?G?GC???AA?G????G????T??G??A??????TT???G???CG?????A??A??T?GA??G??T?CC?TA??GCTG?A????G?CG??GGTG??CA???????TA??G?????????A???????GC?GG????GC", "output": "AATCAAATGAAGAATAAAACCAAACAGAAAAAGAAAAAGTAAACTAAATAGGAAGAAAAAAAAAAGACCCCCCGCCCCGCCAACACCCCTCCCCCCCTGCCACCCCCCTTCGCGCCCCAACGCCCCGCCCCTCCGGGAGGGGGGTTGGGGGGGCGGGGGGAGGAGGTGGAGGGGGTGCCTTATTGCTGTATTTTGTCGTTGGTGTTCATTTTTTTTATTGTTTTTTTTTATTTTTTTGCTGGTTTTGC" }, { "input": "8\n???AAA??", "output": "===" }, { "input": "12\nC??CC??????C", "output": "===" }, { "input": "4\nG??G", "output": "===" }, { "input": "4\nTT??", "output": "===" }, { "input": "4\nACAC", "output": "===" }, { "input": "8\nACGT???T", "output": "ACGTACGT" }, { "input": "252\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "252\n??????????????????????????????????????????????????????????????????????????????A?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????C????????????????????????????????????????????????????????????????", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGCGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????G", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTG" }, { "input": "252\nT???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????", "output": "TAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" }, { "input": "4\nAA?T", "output": "===" }, { "input": "4\nAAAA", "output": "===" }, { "input": "8\nAAA?????", "output": "===" }, { "input": "10\nACGT??????", "output": "===" }, { "input": "6\nACGACG", "output": "===" }, { "input": "5\nAAAAA", "output": "===" }, { "input": "8\nGGGGAA??", "output": "===" }, { "input": "5\nATGCA", "output": "===" }, { "input": "4\nTTTT", "output": "===" }, { "input": "4\nACCG", "output": "===" }, { "input": "8\nACGTA?GT", "output": "ACGTACGT" } ]
1,482,141,495
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
74
62
4,608,000
n = int(input()) s = str(input()) if n % 4 != 0: print("===") exit() div = n // 4 a, g, c, t = 0, 0, 0, 0 for i in range(n): if any([a>div, g>div, c>div, t>div]): print("===") exit() else: cur = s[i] if cur == 'A': a += 1 elif cur == 'G': g += 1 elif cur == 'C': c += 1 elif cur == 'T': t += 1 ss = "" for i in range(n): if s[i] == '?': if a < div: ss += 'A' a += 1 elif g < div: ss += 'G' g += 1 elif c < div: ss += 'C' c += 1 else: ss += 'T' t += 1 else: ss += s[i] print(ss)
Title: Mammoth's Genome Decoding Time Limit: None seconds Memory Limit: None megabytes Problem Description: The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s* is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'. It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal. Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal. Input Specification: The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome. The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. Output Specification: If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). Demo Input: ['8\nAG?C??CT\n', '4\nAGCT\n', '6\n????G?\n', '4\nAA??\n'] Demo Output: ['AGACGTCT\n', 'AGCT\n', '===\n', '===\n'] Note: In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is exactly once in it. In the third and the fourth examples it is impossible to decode the genom.
```python n = int(input()) s = str(input()) if n % 4 != 0: print("===") exit() div = n // 4 a, g, c, t = 0, 0, 0, 0 for i in range(n): if any([a>div, g>div, c>div, t>div]): print("===") exit() else: cur = s[i] if cur == 'A': a += 1 elif cur == 'G': g += 1 elif cur == 'C': c += 1 elif cur == 'T': t += 1 ss = "" for i in range(n): if s[i] == '?': if a < div: ss += 'A' a += 1 elif g < div: ss += 'G' g += 1 elif c < div: ss += 'C' c += 1 else: ss += 'T' t += 1 else: ss += s[i] print(ss) ```
0
2
A
Winner
PROGRAMMING
1,500
[ "hashing", "implementation" ]
A. Winner
1
64
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Print the name of the winner.
[ "3\nmike 3\nandrew 5\nmike 2\n", "3\nandrew 3\nandrew 2\nmike 5\n" ]
[ "andrew\n", "andrew\n" ]
none
0
[ { "input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew" }, { "input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew" }, { "input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "output": "kaxqybeultn" }, { "input": "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734", "output": "ksjuuerbnlklcfdjeyq" }, { "input": "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879", "output": "fcgslzkicjrpbqaifgweyzreajjfdo" }, { "input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735", "output": "aawtvezfntstrcpgbzjbf" }, { "input": "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158", "output": "ivhgbxiv" } ]
1,616,762,378
2,147,483,647
PyPy 3
OK
TESTS
20
248
1,740,800
from math import inf n = int(input()) rounds = [] for i in range(n): a,b = input().split() rounds.append([a,int(b)]) tot_scores = {} for i in range(n): move = rounds[i] tot_scores[move[0]] = tot_scores.get(move[0],0) + move[1] m = -inf for player in tot_scores: m = max(m, tot_scores[player]) pos_winners = set() for player in tot_scores: if tot_scores[player] == m: pos_winners.add(player) scores = {} for i in range(n): move = rounds[i] scores[move[0]] = scores.get(move[0],0) + move[1] if scores[move[0]] >= m and move[0] in pos_winners: print(move[0]) break
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. Input Specification: The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. Output Specification: Print the name of the winner. Demo Input: ['3\nmike 3\nandrew 5\nmike 2\n', '3\nandrew 3\nandrew 2\nmike 5\n'] Demo Output: ['andrew\n', 'andrew\n'] Note: none
```python from math import inf n = int(input()) rounds = [] for i in range(n): a,b = input().split() rounds.append([a,int(b)]) tot_scores = {} for i in range(n): move = rounds[i] tot_scores[move[0]] = tot_scores.get(move[0],0) + move[1] m = -inf for player in tot_scores: m = max(m, tot_scores[player]) pos_winners = set() for player in tot_scores: if tot_scores[player] == m: pos_winners.add(player) scores = {} for i in range(n): move = rounds[i] scores[move[0]] = scores.get(move[0],0) + move[1] if scores[move[0]] >= m and move[0] in pos_winners: print(move[0]) break ```
3.86303
985
B
Switches and Lamps
PROGRAMMING
1,200
[ "implementation" ]
null
null
You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th switch turns on the *j*-th lamp and *a**i*,<=*j*<==<=0 if the *i*-th switch is not connected to the *j*-th lamp. Initially all *m* lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all *n* switches then all *m* lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other *n*<=-<=1 switches then all the *m* lamps will be turned on.
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2000) — the number of the switches and the number of the lamps. The following *n* lines contain *m* characters each. The character *a**i*,<=*j* is equal to '1' if the *i*-th switch turns on the *j*-th lamp and '0' otherwise. It is guaranteed that if you press all *n* switches all *m* lamps will be turned on.
Print "YES" if there is a switch that if you will ignore it and press all the other *n*<=-<=1 switches then all *m* lamps will be turned on. Print "NO" if there is no such switch.
[ "4 5\n10101\n01000\n00111\n10000\n", "4 5\n10100\n01000\n00110\n00101\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "4 5\n10101\n01000\n00111\n10000", "output": "YES" }, { "input": "4 5\n10100\n01000\n00110\n00101", "output": "NO" }, { "input": "1 5\n11111", "output": "NO" }, { "input": "10 1\n1\n0\n0\n0\n0\n0\n0\n0\n0\n1", "output": "YES" }, { "input": "1 1\n1", "output": "NO" }, { "input": "3 4\n1010\n0100\n1101", "output": "YES" }, { "input": "2 5\n10101\n11111", "output": "YES" }, { "input": "5 5\n10000\n11000\n11100\n11110\n11111", "output": "YES" }, { "input": "2 5\n10000\n11111", "output": "YES" }, { "input": "4 5\n01000\n10100\n00010\n10101", "output": "YES" }, { "input": "2 2\n10\n11", "output": "YES" }, { "input": "2 5\n00100\n11111", "output": "YES" }, { "input": "4 5\n00000\n11000\n00110\n00011", "output": "YES" }, { "input": "4 3\n000\n010\n001\n100", "output": "YES" }, { "input": "4 5\n10000\n10101\n01000\n00111", "output": "YES" }, { "input": "4 5\n10000\n01000\n10101\n00111", "output": "YES" }, { "input": "2 2\n01\n11", "output": "YES" }, { "input": "3 3\n010\n101\n000", "output": "YES" }, { "input": "2 2\n11\n00", "output": "YES" }, { "input": "3 5\n10110\n11000\n00111", "output": "YES" }, { "input": "3 8\n00111111\n01011100\n11000000", "output": "YES" }, { "input": "4 6\n100000\n110000\n001100\n000011", "output": "YES" }, { "input": "2 5\n11111\n00000", "output": "YES" }, { "input": "2 3\n101\n111", "output": "YES" }, { "input": "2 5\n01000\n11111", "output": "YES" }, { "input": "2 2\n00\n11", "output": "YES" }, { "input": "4 15\n111110100011010\n111111011010110\n101000001011001\n100110000111011", "output": "YES" }, { "input": "2 3\n010\n111", "output": "YES" }, { "input": "4 5\n10100\n11000\n00110\n00101", "output": "YES" }, { "input": "4 4\n1111\n0000\n0000\n0000", "output": "YES" }, { "input": "3 5\n11100\n00110\n00011", "output": "YES" }, { "input": "2 1\n0\n1", "output": "YES" }, { "input": "4 4\n1000\n1001\n0010\n0100", "output": "YES" }, { "input": "3 5\n00110\n10011\n01100", "output": "YES" }, { "input": "3 5\n10101\n00111\n01000", "output": "NO" }, { "input": "4 5\n00101\n00011\n01000\n10010", "output": "YES" }, { "input": "3 3\n100\n110\n111", "output": "YES" }, { "input": "2 2\n11\n01", "output": "YES" }, { "input": "3 3\n100\n100\n111", "output": "YES" }, { "input": "4 2\n10\n01\n10\n01", "output": "YES" }, { "input": "3 3\n111\n000\n000", "output": "YES" }, { "input": "3 3\n010\n100\n011", "output": "YES" }, { "input": "2 3\n111\n000", "output": "YES" }, { "input": "3 4\n0001\n1101\n1010", "output": "YES" }, { "input": "3 4\n1010\n0101\n1000", "output": "YES" }, { "input": "3 4\n0001\n1101\n0110", "output": "YES" }, { "input": "3 3\n111\n101\n001", "output": "YES" }, { "input": "4 5\n10001\n10010\n01010\n00101", "output": "YES" }, { "input": "3 3\n000\n000\n111", "output": "YES" }, { "input": "2 3\n100\n111", "output": "YES" }, { "input": "3 10\n1111011100\n0001100011\n1111010101", "output": "YES" }, { "input": "3 4\n0110\n1010\n0101", "output": "YES" }, { "input": "3 3\n100\n001\n011", "output": "YES" }, { "input": "3 3\n100\n010\n001", "output": "NO" }, { "input": "3 3\n010\n100\n001", "output": "NO" }, { "input": "3 5\n10101\n01010\n01010", "output": "YES" }, { "input": "2 6\n111111\n000000", "output": "YES" }, { "input": "3 5\n00000\n10101\n01010", "output": "YES" }, { "input": "4 6\n111000\n100100\n010010\n001001", "output": "YES" } ]
1,600,387,237
2,147,483,647
PyPy 3
OK
TESTS
67
670
25,804,800
n,m=map(int,input().split()) ar=[] for i in range(n): ar.append(list(map(int,list(input())))) br=[0]*m for i in range(n): for j in range(m): br[j]+=ar[i][j] flag=False for i in range(n): f1=True for j in range(m): if(ar[i][j]==1 and br[j]==1): f1=False break if(f1): flag=True break if(flag): print("YES") else: print("NO")
Title: Switches and Lamps Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th switch turns on the *j*-th lamp and *a**i*,<=*j*<==<=0 if the *i*-th switch is not connected to the *j*-th lamp. Initially all *m* lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all *n* switches then all *m* lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other *n*<=-<=1 switches then all the *m* lamps will be turned on. Input Specification: The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2000) — the number of the switches and the number of the lamps. The following *n* lines contain *m* characters each. The character *a**i*,<=*j* is equal to '1' if the *i*-th switch turns on the *j*-th lamp and '0' otherwise. It is guaranteed that if you press all *n* switches all *m* lamps will be turned on. Output Specification: Print "YES" if there is a switch that if you will ignore it and press all the other *n*<=-<=1 switches then all *m* lamps will be turned on. Print "NO" if there is no such switch. Demo Input: ['4 5\n10101\n01000\n00111\n10000\n', '4 5\n10100\n01000\n00110\n00101\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python n,m=map(int,input().split()) ar=[] for i in range(n): ar.append(list(map(int,list(input())))) br=[0]*m for i in range(n): for j in range(m): br[j]+=ar[i][j] flag=False for i in range(n): f1=True for j in range(m): if(ar[i][j]==1 and br[j]==1): f1=False break if(f1): flag=True break if(flag): print("YES") else: print("NO") ```
3
0
none
none
none
0
[ "none" ]
null
null
We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor. There are *n* citizens in Kekoland, each person has *c**i* coins. Each day, Robin Hood will take exactly 1 coin from the richest person in the city and he will give it to the poorest person (poorest person right after taking richest's 1 coin). In case the choice is not unique, he will select one among them at random. Sadly, Robin Hood is old and want to retire in *k* days. He decided to spend these last days with helping poor people. After taking his money are taken by Robin Hood richest person may become poorest person as well, and it might even happen that Robin Hood will give his money back. For example if all people have same number of coins, then next day they will have same number of coins too. Your task is to find the difference between richest and poorest persons wealth after *k* days. Note that the choosing at random among richest and poorest doesn't affect the answer.
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=500<=000,<=0<=≤<=*k*<=≤<=109) — the number of citizens in Kekoland and the number of days left till Robin Hood's retirement. The second line contains *n* integers, the *i*-th of them is *c**i* (1<=≤<=*c**i*<=≤<=109) — initial wealth of the *i*-th person.
Print a single line containing the difference between richest and poorest peoples wealth.
[ "4 1\n1 1 4 2\n", "3 1\n2 2 2\n" ]
[ "2\n", "0\n" ]
Lets look at how wealth changes through day in the first sample. 1. [1, 1, 4, 2] 1. [2, 1, 3, 2] or [1, 2, 3, 2] So the answer is 3 - 1 = 2 In second sample wealth will remain the same for each person.
0
[ { "input": "4 1\n1 1 4 2", "output": "2" }, { "input": "3 1\n2 2 2", "output": "0" }, { "input": "10 20\n6 4 7 10 4 5 5 3 7 10", "output": "1" }, { "input": "30 7\n3 3 2 2 2 2 3 4 4 5 2 1 1 5 5 3 4 3 2 1 3 4 3 2 2 5 2 5 1 2", "output": "2" }, { "input": "2 0\n182 2", "output": "180" }, { "input": "123 54564\n38 44 41 42 59 3 95 15 45 32 44 69 35 83 94 57 65 85 64 47 24 20 34 86 26 91 98 12 36 96 80 4 70 40 95 38 70 22 58 50 34 84 80 45 14 60 61 43 11 56 19 59 50 63 21 15 97 98 27 13 9 71 32 18 90 10 2 99 75 87 74 83 79 37 89 3 49 27 92 95 49 1 26 50 72 75 81 37 60 98 28 28 10 93 99 63 14 26 69 51 47 59 42 7 20 17 75 44 44 20 44 85 27 32 65 95 47 46 12 22 64 77 21", "output": "1" }, { "input": "111 10\n2 8 6 1 3 5 8 3 8 2 9 9 6 9 8 8 5 2 3 8 8 3 8 3 7 9 4 3 9 7 1 8 3 1 5 5 5 8 2 4 2 7 9 1 4 4 3 1 6 7 7 4 1 3 5 3 9 4 4 4 8 8 7 3 5 6 3 3 8 2 8 4 5 8 1 8 4 1 7 1 4 9 8 9 7 6 5 6 3 7 4 8 9 3 8 9 9 3 5 9 1 3 6 8 9 1 1 3 8 7 6", "output": "8" }, { "input": "10 1000000\n307196 650096 355966 710719 99165 959865 500346 677478 614586 6538", "output": "80333" }, { "input": "5 1000000\n145119584 42061308 953418415 717474449 57984109", "output": "909357107" }, { "input": "100 20\n2 5 3 3 2 7 6 2 2 2 6 7 2 1 8 10 2 4 10 6 10 2 1 1 4 7 1 2 9 7 5 3 7 4 6 3 10 10 3 7 6 8 2 2 10 3 1 2 1 3 1 6 3 1 4 10 3 10 9 5 10 4 3 10 3 3 5 3 10 2 1 5 10 7 8 7 7 2 4 2 1 3 3 8 8 5 7 3 1 1 8 10 5 7 4 4 7 7 1 9", "output": "7" }, { "input": "10 1000\n1000000000 999999994 999999992 1000000000 999999994 999999999 999999990 999999997 999999995 1000000000", "output": "1" }, { "input": "2 100000\n1 3", "output": "0" }, { "input": "4 0\n1 4 4 4", "output": "3" }, { "input": "4 42\n1 1 1 1000000000", "output": "999999943" }, { "input": "3 4\n1 2 7", "output": "1" }, { "input": "4 100\n1 1 10 10", "output": "1" } ]
1,663,580,871
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
7
1,000
51,609,600
no_of_citizens, days_left_for_retirement = map(int, input().split()) wealth = list(map(int, input().split())) if sum(wealth) == wealth[0]*no_of_citizens: print(0) else: while days_left_for_retirement: wealth[wealth.index(max(wealth))] -= 1 wealth[wealth.index(min(wealth))] += 1 days_left_for_retirement -= 1 print(max(wealth)-min(wealth))
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor. There are *n* citizens in Kekoland, each person has *c**i* coins. Each day, Robin Hood will take exactly 1 coin from the richest person in the city and he will give it to the poorest person (poorest person right after taking richest's 1 coin). In case the choice is not unique, he will select one among them at random. Sadly, Robin Hood is old and want to retire in *k* days. He decided to spend these last days with helping poor people. After taking his money are taken by Robin Hood richest person may become poorest person as well, and it might even happen that Robin Hood will give his money back. For example if all people have same number of coins, then next day they will have same number of coins too. Your task is to find the difference between richest and poorest persons wealth after *k* days. Note that the choosing at random among richest and poorest doesn't affect the answer. Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=500<=000,<=0<=≤<=*k*<=≤<=109) — the number of citizens in Kekoland and the number of days left till Robin Hood's retirement. The second line contains *n* integers, the *i*-th of them is *c**i* (1<=≤<=*c**i*<=≤<=109) — initial wealth of the *i*-th person. Output Specification: Print a single line containing the difference between richest and poorest peoples wealth. Demo Input: ['4 1\n1 1 4 2\n', '3 1\n2 2 2\n'] Demo Output: ['2\n', '0\n'] Note: Lets look at how wealth changes through day in the first sample. 1. [1, 1, 4, 2] 1. [2, 1, 3, 2] or [1, 2, 3, 2] So the answer is 3 - 1 = 2 In second sample wealth will remain the same for each person.
```python no_of_citizens, days_left_for_retirement = map(int, input().split()) wealth = list(map(int, input().split())) if sum(wealth) == wealth[0]*no_of_citizens: print(0) else: while days_left_for_retirement: wealth[wealth.index(max(wealth))] -= 1 wealth[wealth.index(min(wealth))] += 1 days_left_for_retirement -= 1 print(max(wealth)-min(wealth)) ```
0
862
C
Mahmoud and Ehab and the xor
PROGRAMMING
1,900
[ "constructive algorithms" ]
null
null
Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets. Dr. Evil has his favorite evil integer *x*. He asks Mahmoud and Ehab to find a set of *n* distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly *x*. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106.
The only line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=105, 0<=≤<=*x*<=≤<=105) — the number of elements in the set and the desired bitwise-xor, respectively.
If there is no such set, print "NO" (without quotes). Otherwise, on the first line print "YES" (without quotes) and on the second line print *n* distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them.
[ "5 5\n", "3 6\n" ]
[ "YES\n1 2 4 5 7", "YES\n1 2 5" ]
You can read more about the bitwise-xor operation here: [https://en.wikipedia.org/wiki/Bitwise_operation#XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) For the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb8ccd05d3a7a41eff93c98f79d158cf85e702f9.png" style="max-width: 100.0%;max-height: 100.0%;"/>. For the second sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d05d19f05b03f8ac89b7f86ef830eeccc0050c42.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
1,500
[ { "input": "5 5", "output": "YES\n1 2 131072 131078 0 " }, { "input": "3 6", "output": "YES\n131072 131078 0 " }, { "input": "3 0", "output": "YES\n393216 131072 262144" }, { "input": "1 0", "output": "YES\n0" }, { "input": "3 3", "output": "YES\n131072 131075 0 " }, { "input": "100000 41243", "output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..." }, { "input": "100000 100000", "output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..." }, { "input": "32 32", "output": "YES\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 131072 131105 0 " }, { "input": "32 31", "output": "YES\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 131072 131102 0 " }, { "input": "1 1", "output": "YES\n1" }, { "input": "2 0", "output": "NO" }, { "input": "3 1", "output": "YES\n131072 131073 0 " }, { "input": "3 2", "output": "YES\n131072 131074 0 " }, { "input": "3 5", "output": "YES\n131072 131077 0 " }, { "input": "3 4", "output": "YES\n131072 131076 0 " }, { "input": "3 10203", "output": "YES\n131072 141275 0 " }, { "input": "3 10100", "output": "YES\n131072 141172 0 " }, { "input": "5 0", "output": "YES\n1 2 131072 131075 0 " }, { "input": "5 1", "output": "YES\n1 2 131072 131074 0 " }, { "input": "5 2", "output": "YES\n1 2 131072 131073 0 " }, { "input": "5 3", "output": "YES\n1 2 393216 131072 262144" }, { "input": "5 4", "output": "YES\n1 2 131072 131079 0 " }, { "input": "5 6", "output": "YES\n1 2 131072 131077 0 " }, { "input": "5 7", "output": "YES\n1 2 131072 131076 0 " }, { "input": "5 8", "output": "YES\n1 2 131072 131083 0 " }, { "input": "5 9", "output": "YES\n1 2 131072 131082 0 " }, { "input": "100000 1", "output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..." }, { "input": "100000 0", "output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..." }, { "input": "100000 21323", "output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..." }, { "input": "100000 65536", "output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..." }, { "input": "100000 65537", "output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..." }, { "input": "100000 65535", "output": "YES\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..." }, { "input": "4 2", "output": "YES\n1 131072 131075 0 " }, { "input": "10 2", "output": "YES\n1 2 3 4 5 6 7 131072 131074 0 " }, { "input": "1 2", "output": "YES\n2" }, { "input": "1 3", "output": "YES\n3" }, { "input": "2 1", "output": "YES\n0 1" }, { "input": "2 2", "output": "YES\n0 2" }, { "input": "2 3", "output": "YES\n0 3" }, { "input": "4 0", "output": "YES\n1 131072 131073 0 " }, { "input": "4 1", "output": "YES\n1 393216 131072 262144" }, { "input": "4 3", "output": "YES\n1 131072 131074 0 " }, { "input": "6 0", "output": "YES\n1 2 3 393216 131072 262144" }, { "input": "7 1", "output": "YES\n1 2 3 4 131072 131077 0 " } ]
1,506,723,641
6,041
Python 3
RUNTIME_ERROR
TESTS
3
46
0
arr=list(map(int,input().strip().split(' '))) n,x=arr[0],arr[1] if(n==1): print(x) elif(n==2): if(x%2==1): ans=x-1 else: ans=x+1 alist=[1,ans] elif(n==3): alist=[1,2] alist.append(3^x) else: i=0 ans=0 alist=[] while(len(alist)<n-2): ans=ans^2**i alist.append(2**i) i+=1 if(ans>x): if(not ans in alist): alist.append(ans) ans=0 alist.append(ans) alist.append(x) while(0 in alist): alist.remove(0) if(len(alist)!=n): print("NO") else: print("YES") alist.sort() for i in alist: if(i!=0): print(i,end=" ")
Title: Mahmoud and Ehab and the xor Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets. Dr. Evil has his favorite evil integer *x*. He asks Mahmoud and Ehab to find a set of *n* distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly *x*. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106. Input Specification: The only line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=105, 0<=≤<=*x*<=≤<=105) — the number of elements in the set and the desired bitwise-xor, respectively. Output Specification: If there is no such set, print "NO" (without quotes). Otherwise, on the first line print "YES" (without quotes) and on the second line print *n* distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them. Demo Input: ['5 5\n', '3 6\n'] Demo Output: ['YES\n1 2 4 5 7', 'YES\n1 2 5'] Note: You can read more about the bitwise-xor operation here: [https://en.wikipedia.org/wiki/Bitwise_operation#XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) For the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb8ccd05d3a7a41eff93c98f79d158cf85e702f9.png" style="max-width: 100.0%;max-height: 100.0%;"/>. For the second sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/d05d19f05b03f8ac89b7f86ef830eeccc0050c42.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python arr=list(map(int,input().strip().split(' '))) n,x=arr[0],arr[1] if(n==1): print(x) elif(n==2): if(x%2==1): ans=x-1 else: ans=x+1 alist=[1,ans] elif(n==3): alist=[1,2] alist.append(3^x) else: i=0 ans=0 alist=[] while(len(alist)<n-2): ans=ans^2**i alist.append(2**i) i+=1 if(ans>x): if(not ans in alist): alist.append(ans) ans=0 alist.append(ans) alist.append(x) while(0 in alist): alist.remove(0) if(len(alist)!=n): print("NO") else: print("YES") alist.sort() for i in alist: if(i!=0): print(i,end=" ") ```
-1
894
A
QAQ
PROGRAMMING
800
[ "brute force", "dp" ]
null
null
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Print a single integer — the number of subsequences "QAQ" in the string.
[ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n" ]
[ "4\n", "3\n" ]
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
500
[ { "input": "QAQAQYSYIOIWIN", "output": "4" }, { "input": "QAQQQZZYNOIWIN", "output": "3" }, { "input": "QA", "output": "0" }, { "input": "IAQVAQZLQBQVQFTQQQADAQJA", "output": "24" }, { "input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ", "output": "378" }, { "input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ", "output": "1077" }, { "input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA", "output": "568" }, { "input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA", "output": "70" }, { "input": "W", "output": "0" }, { "input": "DBA", "output": "0" }, { "input": "RQAWNACASAAKAGAAAAQ", "output": "10" }, { "input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA", "output": "111" }, { "input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA", "output": "411" }, { "input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ", "output": "625" }, { "input": "QORZOYAQ", "output": "1" }, { "input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA", "output": "13174" }, { "input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT", "output": "10420" }, { "input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ", "output": "12488" }, { "input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA", "output": "9114" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "35937" }, { "input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE", "output": "254" }, { "input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE", "output": "2174" }, { "input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ", "output": "2962" }, { "input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA", "output": "2482" }, { "input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ", "output": "7768" }, { "input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA", "output": "5422" }, { "input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ", "output": "3024" }, { "input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ", "output": "4527" }, { "input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH", "output": "6416" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ", "output": "13136" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "14270" }, { "input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA", "output": "14231" }, { "input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA", "output": "15296" }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "0" }, { "input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ", "output": "0" }, { "input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA", "output": "20825" }, { "input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ", "output": "20825" }, { "input": "Q", "output": "0" }, { "input": "A", "output": "0" }, { "input": "FFF", "output": "0" }, { "input": "AAAAAA", "output": "0" } ]
1,600,334,900
2,147,483,647
PyPy 3
OK
TESTS
43
155
0
char_list = [char for char in input()] q_before = [0] * len(char_list) q_before[0] = 1 if char_list[0] == 'Q' else 0 for i in range(1, len(char_list)): q_before[i] = q_before[i-1] if char_list[i] == 'Q': q_before[i] += 1 qa_before = [0] * len(char_list) for i in range(1, len(char_list)): qa_before[i] = qa_before[i-1] if char_list[i] == 'A': qa_before[i] += q_before[i-1] qaq_count = 0 for i in range(2, len(char_list)): if char_list[i] == "Q": qaq_count += qa_before[i] print(qaq_count)
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 char_list = [char for char in input()] q_before = [0] * len(char_list) q_before[0] = 1 if char_list[0] == 'Q' else 0 for i in range(1, len(char_list)): q_before[i] = q_before[i-1] if char_list[i] == 'Q': q_before[i] += 1 qa_before = [0] * len(char_list) for i in range(1, len(char_list)): qa_before[i] = qa_before[i-1] if char_list[i] == 'A': qa_before[i] += q_before[i-1] qaq_count = 0 for i in range(2, len(char_list)): if char_list[i] == "Q": qaq_count += qa_before[i] print(qaq_count) ```
3
769
A
Year of University Entrance
PROGRAMMING
800
[ "*special", "implementation", "sortings" ]
null
null
There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than *x* from the year of university entrance of this student, where *x* — some non-negative integer. A value *x* is not given, but it can be uniquely determined from the available data. Note that students don't join other groups. You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance.
The first line contains the positive odd integer *n* (1<=≤<=*n*<=≤<=5) — the number of groups which Igor joined. The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (2010<=≤<=*a**i*<=≤<=2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly.
Print the year of Igor's university entrance.
[ "3\n2014 2016 2015\n", "1\n2050\n" ]
[ "2015\n", "2050\n" ]
In the first test the value *x* = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016. In the second test the value *x* = 0. Igor entered only the group which corresponds to the year of his university entrance.
500
[ { "input": "3\n2014 2016 2015", "output": "2015" }, { "input": "1\n2050", "output": "2050" }, { "input": "1\n2010", "output": "2010" }, { "input": "1\n2011", "output": "2011" }, { "input": "3\n2010 2011 2012", "output": "2011" }, { "input": "3\n2049 2047 2048", "output": "2048" }, { "input": "5\n2043 2042 2041 2044 2040", "output": "2042" }, { "input": "5\n2012 2013 2014 2015 2016", "output": "2014" }, { "input": "1\n2045", "output": "2045" }, { "input": "1\n2046", "output": "2046" }, { "input": "1\n2099", "output": "2099" }, { "input": "1\n2100", "output": "2100" }, { "input": "3\n2011 2010 2012", "output": "2011" }, { "input": "3\n2011 2012 2010", "output": "2011" }, { "input": "3\n2012 2011 2010", "output": "2011" }, { "input": "3\n2010 2012 2011", "output": "2011" }, { "input": "3\n2012 2010 2011", "output": "2011" }, { "input": "3\n2047 2048 2049", "output": "2048" }, { "input": "3\n2047 2049 2048", "output": "2048" }, { "input": "3\n2048 2047 2049", "output": "2048" }, { "input": "3\n2048 2049 2047", "output": "2048" }, { "input": "3\n2049 2048 2047", "output": "2048" }, { "input": "5\n2011 2014 2012 2013 2010", "output": "2012" }, { "input": "5\n2014 2013 2011 2012 2015", "output": "2013" }, { "input": "5\n2021 2023 2024 2020 2022", "output": "2022" }, { "input": "5\n2081 2079 2078 2080 2077", "output": "2079" }, { "input": "5\n2095 2099 2097 2096 2098", "output": "2097" }, { "input": "5\n2097 2099 2100 2098 2096", "output": "2098" }, { "input": "5\n2012 2010 2014 2011 2013", "output": "2012" }, { "input": "5\n2012 2011 2013 2015 2014", "output": "2013" }, { "input": "5\n2023 2024 2022 2021 2020", "output": "2022" }, { "input": "5\n2077 2078 2080 2079 2081", "output": "2079" }, { "input": "5\n2099 2096 2095 2097 2098", "output": "2097" }, { "input": "5\n2097 2100 2098 2096 2099", "output": "2098" }, { "input": "5\n2011 2014 2013 2010 2012", "output": "2012" }, { "input": "5\n2013 2011 2015 2012 2014", "output": "2013" }, { "input": "5\n2024 2020 2021 2023 2022", "output": "2022" }, { "input": "5\n2079 2080 2077 2081 2078", "output": "2079" }, { "input": "5\n2095 2097 2096 2098 2099", "output": "2097" }, { "input": "5\n2099 2096 2100 2097 2098", "output": "2098" }, { "input": "5\n2034 2033 2036 2032 2035", "output": "2034" }, { "input": "5\n2030 2031 2033 2032 2029", "output": "2031" }, { "input": "5\n2093 2092 2094 2096 2095", "output": "2094" }, { "input": "5\n2012 2015 2014 2013 2011", "output": "2013" }, { "input": "5\n2056 2057 2058 2059 2060", "output": "2058" } ]
1,488,630,502
1,702
Python 3
OK
TESTS
45
62
4,608,000
""" Created by Shahen Kosyan on 3/4/17 """ if __name__ == "__main__": n = int(input()) arr = [int(x) for x in input().split()] arr = sorted(arr) print(arr[len(arr) // 2])
Title: Year of University Entrance Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than *x* from the year of university entrance of this student, where *x* — some non-negative integer. A value *x* is not given, but it can be uniquely determined from the available data. Note that students don't join other groups. You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance. Input Specification: The first line contains the positive odd integer *n* (1<=≤<=*n*<=≤<=5) — the number of groups which Igor joined. The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (2010<=≤<=*a**i*<=≤<=2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly. Output Specification: Print the year of Igor's university entrance. Demo Input: ['3\n2014 2016 2015\n', '1\n2050\n'] Demo Output: ['2015\n', '2050\n'] Note: In the first test the value *x* = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016. In the second test the value *x* = 0. Igor entered only the group which corresponds to the year of his university entrance.
```python """ Created by Shahen Kosyan on 3/4/17 """ if __name__ == "__main__": n = int(input()) arr = [int(x) for x in input().split()] arr = sorted(arr) print(arr[len(arr) // 2]) ```
3
88
A
Chord
PROGRAMMING
1,200
[ "brute force", "implementation" ]
A. Chord
2
256
Vasya studies music. He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor. Let's define a major triad. Let the triad consist of notes *X*, *Y* and *Z*. If we can order the notes so as the distance along the musical scale between *X* and *Y* equals 4 semitones and the distance between *Y* and *Z* is 3 semitones, then the triad is major. The distance between *X* and *Z*, accordingly, equals 7 semitones. A minor triad is different in that the distance between *X* and *Y* should be 3 semitones and between *Y* and *Z* — 4 semitones. For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones. Help Vasya classify the triad the teacher has given to him.
The only line contains 3 space-separated notes in the above-given notation.
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
[ "C E G\n", "C# B F\n", "A B H\n" ]
[ "major\n", "minor\n", "strange\n" ]
none
500
[ { "input": "C E G", "output": "major" }, { "input": "C# B F", "output": "minor" }, { "input": "A B H", "output": "strange" }, { "input": "G H E", "output": "minor" }, { "input": "D# B G", "output": "major" }, { "input": "D# B F#", "output": "minor" }, { "input": "F H E", "output": "strange" }, { "input": "B F# G", "output": "strange" }, { "input": "F# H C", "output": "strange" }, { "input": "C# F C", "output": "strange" }, { "input": "G# C# E", "output": "minor" }, { "input": "D# H G#", "output": "minor" }, { "input": "C F A", "output": "major" }, { "input": "H E G#", "output": "major" }, { "input": "G D# B", "output": "major" }, { "input": "E C G", "output": "major" }, { "input": "G# C# F", "output": "major" }, { "input": "D# C G#", "output": "major" }, { "input": "C# F B", "output": "minor" }, { "input": "D# C G", "output": "minor" }, { "input": "A D F", "output": "minor" }, { "input": "F# H D", "output": "minor" }, { "input": "D A F", "output": "minor" }, { "input": "D A F#", "output": "major" }, { "input": "C# B F", "output": "minor" }, { "input": "A C F", "output": "major" }, { "input": "D F# H", "output": "minor" }, { "input": "H G# D#", "output": "minor" }, { "input": "A D F#", "output": "major" }, { "input": "H E G#", "output": "major" }, { "input": "D# B F#", "output": "minor" }, { "input": "D# H F#", "output": "major" }, { "input": "A D F#", "output": "major" }, { "input": "B G D#", "output": "major" }, { "input": "E A C#", "output": "major" }, { "input": "D H G", "output": "major" }, { "input": "H D F#", "output": "minor" }, { "input": "G D# C", "output": "minor" }, { "input": "H D G", "output": "major" }, { "input": "E C G", "output": "major" }, { "input": "D# A E", "output": "strange" }, { "input": "A F E", "output": "strange" }, { "input": "C E F", "output": "strange" }, { "input": "A B C", "output": "strange" }, { "input": "E F D#", "output": "strange" }, { "input": "C G# G#", "output": "strange" }, { "input": "F D# G#", "output": "strange" }, { "input": "B G D#", "output": "major" }, { "input": "E E G#", "output": "strange" }, { "input": "A G H", "output": "strange" }, { "input": "F E A", "output": "strange" }, { "input": "D B E", "output": "strange" }, { "input": "G# C# D", "output": "strange" }, { "input": "D# D# F#", "output": "strange" }, { "input": "H B G", "output": "strange" }, { "input": "D C B", "output": "strange" }, { "input": "D B B", "output": "strange" }, { "input": "C A H", "output": "strange" }, { "input": "F# H F#", "output": "strange" }, { "input": "A F F#", "output": "strange" }, { "input": "C D C", "output": "strange" }, { "input": "G F# A", "output": "strange" }, { "input": "C C# D", "output": "strange" }, { "input": "C A E", "output": "minor" }, { "input": "A H B", "output": "strange" }, { "input": "B E F#", "output": "strange" }, { "input": "G# G# A", "output": "strange" }, { "input": "B C# C#", "output": "strange" }, { "input": "C G D#", "output": "minor" }, { "input": "C B D#", "output": "strange" }, { "input": "F H F", "output": "strange" }, { "input": "E G# C", "output": "strange" }, { "input": "F# F# F#", "output": "strange" }, { "input": "F C F", "output": "strange" }, { "input": "A F D", "output": "minor" } ]
1,631,408,371
2,147,483,647
PyPy 3
OK
TESTS
75
248
20,172,800
def nm(a): s = list(map(lambda i:a.index(i),input().split())) for i in range(3): s.sort() x,y = abs(s[0] - s[1]),abs(s[1] - s[2]) if [x,y] == [4,3]: return 'major' elif [x,y] == [3,4]: return 'minor' s[0] += 12 return 'strange' print(nm((0,'C','C#','D','D#','E','F','F#','G','G#','A','B','H')))
Title: Chord Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya studies music. He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor. Let's define a major triad. Let the triad consist of notes *X*, *Y* and *Z*. If we can order the notes so as the distance along the musical scale between *X* and *Y* equals 4 semitones and the distance between *Y* and *Z* is 3 semitones, then the triad is major. The distance between *X* and *Z*, accordingly, equals 7 semitones. A minor triad is different in that the distance between *X* and *Y* should be 3 semitones and between *Y* and *Z* — 4 semitones. For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones. Help Vasya classify the triad the teacher has given to him. Input Specification: The only line contains 3 space-separated notes in the above-given notation. Output Specification: Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously. Demo Input: ['C E G\n', 'C# B F\n', 'A B H\n'] Demo Output: ['major\n', 'minor\n', 'strange\n'] Note: none
```python def nm(a): s = list(map(lambda i:a.index(i),input().split())) for i in range(3): s.sort() x,y = abs(s[0] - s[1]),abs(s[1] - s[2]) if [x,y] == [4,3]: return 'major' elif [x,y] == [3,4]: return 'minor' s[0] += 12 return 'strange' print(nm((0,'C','C#','D','D#','E','F','F#','G','G#','A','B','H'))) ```
3.900425
483
A
Counterexample
PROGRAMMING
1,100
[ "brute force", "implementation", "math", "number theory" ]
null
null
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one. Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime. You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=&lt;<=*b*<=&lt;<=*c*<=≤<=*r*. More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=&lt;<=*b*<=&lt;<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime.
The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50).
Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order. If the counterexample does not exist, print the single number -1.
[ "2 4\n", "10 11\n", "900000000000000009 900000000000000029\n" ]
[ "2 3 4\n", "-1\n", "900000000000000009 900000000000000010 900000000000000021\n" ]
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are. In the second sample you cannot form a group of three distinct integers, so the answer is -1. In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
500
[ { "input": "2 4", "output": "2 3 4" }, { "input": "10 11", "output": "-1" }, { "input": "900000000000000009 900000000000000029", "output": "900000000000000009 900000000000000010 900000000000000021" }, { "input": "640097987171091791 640097987171091835", "output": "640097987171091792 640097987171091793 640097987171091794" }, { "input": "19534350415104721 19534350415104725", "output": "19534350415104722 19534350415104723 19534350415104724" }, { "input": "933700505788726243 933700505788726280", "output": "933700505788726244 933700505788726245 933700505788726246" }, { "input": "1 3", "output": "-1" }, { "input": "1 4", "output": "2 3 4" }, { "input": "1 1", "output": "-1" }, { "input": "266540997167959130 266540997167959164", "output": "266540997167959130 266540997167959131 266540997167959132" }, { "input": "267367244641009850 267367244641009899", "output": "267367244641009850 267367244641009851 267367244641009852" }, { "input": "268193483524125978 268193483524125993", "output": "268193483524125978 268193483524125979 268193483524125980" }, { "input": "269019726702209402 269019726702209432", "output": "269019726702209402 269019726702209403 269019726702209404" }, { "input": "269845965585325530 269845965585325576", "output": "269845965585325530 269845965585325531 269845965585325532" }, { "input": "270672213058376250 270672213058376260", "output": "270672213058376250 270672213058376251 270672213058376252" }, { "input": "271498451941492378 271498451941492378", "output": "-1" }, { "input": "272324690824608506 272324690824608523", "output": "272324690824608506 272324690824608507 272324690824608508" }, { "input": "273150934002691930 273150934002691962", "output": "273150934002691930 273150934002691931 273150934002691932" }, { "input": "996517375802030516 996517375802030524", "output": "996517375802030516 996517375802030517 996517375802030518" }, { "input": "997343614685146644 997343614685146694", "output": "997343614685146644 997343614685146645 997343614685146646" }, { "input": "998169857863230068 998169857863230083", "output": "998169857863230068 998169857863230069 998169857863230070" }, { "input": "998996101041313492 998996101041313522", "output": "998996101041313492 998996101041313493 998996101041313494" }, { "input": "999822344219396916 999822344219396961", "output": "999822344219396916 999822344219396917 999822344219396918" }, { "input": "648583102513043 648583102513053", "output": "648583102513044 648583102513045 648583102513046" }, { "input": "266540997167959130 266540997167959131", "output": "-1" }, { "input": "267367244641009850 267367244641009850", "output": "-1" }, { "input": "268193483524125978 268193483524125979", "output": "-1" }, { "input": "269019726702209402 269019726702209402", "output": "-1" }, { "input": "269845965585325530 269845965585325530", "output": "-1" }, { "input": "270672213058376250 270672213058376254", "output": "270672213058376250 270672213058376251 270672213058376252" }, { "input": "271498451941492378 271498451941492379", "output": "-1" }, { "input": "272324690824608506 272324690824608508", "output": "272324690824608506 272324690824608507 272324690824608508" }, { "input": "273150934002691930 273150934002691931", "output": "-1" }, { "input": "996517375802030516 996517375802030518", "output": "996517375802030516 996517375802030517 996517375802030518" }, { "input": "997343614685146644 997343614685146644", "output": "-1" }, { "input": "2147483647 2147483649", "output": "-1" }, { "input": "3 5", "output": "-1" }, { "input": "1 7", "output": "2 3 4" }, { "input": "9 12", "output": "9 11 12" }, { "input": "4 4", "output": "-1" }, { "input": "11 13", "output": "-1" }, { "input": "2 2", "output": "-1" } ]
1,535,048,225
2,147,483,647
Python 3
OK
TESTS
42
124
0
l,r=map(int,input().split()); if l&1==1: l+=1; if l+2>r: print(-1); else: print(l,l+1,l+2); # Made By Mostafa_Khaled
Title: Counterexample Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one. Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime. You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=&lt;<=*b*<=&lt;<=*c*<=≤<=*r*. More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=&lt;<=*b*<=&lt;<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime. Input Specification: The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). Output Specification: Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order. If the counterexample does not exist, print the single number -1. Demo Input: ['2 4\n', '10 11\n', '900000000000000009 900000000000000029\n'] Demo Output: ['2 3 4\n', '-1\n', '900000000000000009 900000000000000010 900000000000000021\n'] Note: In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are. In the second sample you cannot form a group of three distinct integers, so the answer is -1. In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
```python l,r=map(int,input().split()); if l&1==1: l+=1; if l+2>r: print(-1); else: print(l,l+1,l+2); # Made By Mostafa_Khaled ```
3
624
A
Save Luke
PROGRAMMING
800
[ "math" ]
null
null
Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and *L*, and they move towards each other with speed *v*1 and *v*2, respectively. Luke has width *d* and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive.
The first line of the input contains four integers *d*, *L*, *v*1, *v*2 (1<=≤<=*d*,<=*L*,<=*v*1,<=*v*2<=≤<=10<=000,<=*d*<=&lt;<=*L*) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively.
Print a single real value — the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
[ "2 6 2 2\n", "1 9 1 2\n" ]
[ "1.00000000000000000000\n", "2.66666666666666650000\n" ]
In the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed. In the second sample he needs to occupy the position <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/71395c777960eaded59a9fdc428a9625f152605b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In this case both presses move to his edges at the same time.
500
[ { "input": "2 6 2 2", "output": "1.00000000000000000000" }, { "input": "1 9 1 2", "output": "2.66666666666666650000" }, { "input": "1 10000 1 1", "output": "4999.50000000000000000000" }, { "input": "9999 10000 10000 10000", "output": "0.00005000000000000000" }, { "input": "1023 2340 1029 3021", "output": "0.32518518518518519000" }, { "input": "2173 2176 10000 9989", "output": "0.00015008254539996998" }, { "input": "1 2 123 1", "output": "0.00806451612903225780" }, { "input": "123 1242 12 312", "output": "3.45370370370370370000" }, { "input": "2 9997 3 12", "output": "666.33333333333337000000" }, { "input": "1 10000 10000 10000", "output": "0.49995000000000001000" }, { "input": "3274 4728 888 4578", "output": "0.26600804976216613000" }, { "input": "4600 9696 5634 8248", "output": "0.36709407866301685000" }, { "input": "2255 7902 8891 429", "output": "0.60590128755364803000" }, { "input": "6745 9881 2149 9907", "output": "0.26011944260119441000" }, { "input": "4400 8021 6895 2089", "output": "0.40304986642920748000" }, { "input": "5726 9082 7448 3054", "output": "0.31955817939440107000" }, { "input": "3381 9769 4898 2532", "output": "0.85975773889636609000" }, { "input": "1036 6259 5451 4713", "output": "0.51387249114521838000" }, { "input": "5526 6455 197 4191", "output": "0.21171376481312670000" }, { "input": "1196 4082 4071 9971", "output": "0.20552627830793335000" }, { "input": "8850 9921 8816 9449", "output": "0.05863673692855187600" }, { "input": "3341 7299 2074 8927", "output": "0.35978547404781386000" }, { "input": "7831 8609 6820 2596", "output": "0.08262531860662701600" }, { "input": "2322 7212 77 4778", "output": "1.00720906282183310000" }, { "input": "9976 9996 4823 4255", "output": "0.00220312844238819110" }, { "input": "7631 9769 5377 6437", "output": "0.18097172845776197000" }, { "input": "8957 9525 8634 107", "output": "0.06498112344125385500" }, { "input": "6612 9565 3380 2288", "output": "0.52099505998588569000" }, { "input": "1103 6256 3934 9062", "output": "0.39650661742074483000" }, { "input": "1854 3280 1481 2140", "output": "0.39381386357359843000" } ]
1,607,666,477
2,147,483,647
Python 3
OK
TESTS
30
109
0
d,L,v1,v2=map(int,input().split()) t=(L-d)/(v1+v2) print('{0:.9f}'.format(t))
Title: Save Luke Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and *L*, and they move towards each other with speed *v*1 and *v*2, respectively. Luke has width *d* and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive. Input Specification: The first line of the input contains four integers *d*, *L*, *v*1, *v*2 (1<=≤<=*d*,<=*L*,<=*v*1,<=*v*2<=≤<=10<=000,<=*d*<=&lt;<=*L*) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively. Output Specification: Print a single real value — the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . Demo Input: ['2 6 2 2\n', '1 9 1 2\n'] Demo Output: ['1.00000000000000000000\n', '2.66666666666666650000\n'] Note: In the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed. In the second sample he needs to occupy the position <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/71395c777960eaded59a9fdc428a9625f152605b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In this case both presses move to his edges at the same time.
```python d,L,v1,v2=map(int,input().split()) t=(L-d)/(v1+v2) print('{0:.9f}'.format(t)) ```
3
0
none
none
none
0
[ "none" ]
D. Falling Anvils
2
256
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all. Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you! It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models. Let the height *p* of the potential victim vary in the range [0;*a*] and the direction of the wind *q* vary in the range [<=-<=*b*;*b*]. *p* and *q* could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root: Determine the probability with which an aim can be successfully hit by an anvil. You can assume that the *p* and *q* coefficients are chosen equiprobably and independently in their ranges.
The first line contains integer *t* (1<=≤<=*t*<=≤<=10000) — amount of testcases. Each of the following *t* lines contain two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=106). Pretests contain all the tests with 0<=&lt;<=*a*<=&lt;<=10,<=0<=≤<=*b*<=&lt;<=10.
Print *t* lines — the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10<=-<=6.
[ "2\n4 2\n1 2\n" ]
[ "0.6250000000\n0.5312500000\n" ]
none
0
[]
1,541,945,725
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
1
404
1,024,000
def calArea(a, b): if a <= 4 * b: return a * min(b, a / 4) / 2 return b * b * 2 + (a - 4 * b) * b for _ in range(int(input())): a, b = map(int, input().split()) print("{:.8f}".format(calArea(a, b) / (2 * a * b) + 0.5))
Title: none Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all. Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you! It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models. Let the height *p* of the potential victim vary in the range [0;*a*] and the direction of the wind *q* vary in the range [<=-<=*b*;*b*]. *p* and *q* could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root: Determine the probability with which an aim can be successfully hit by an anvil. You can assume that the *p* and *q* coefficients are chosen equiprobably and independently in their ranges. Input Specification: The first line contains integer *t* (1<=≤<=*t*<=≤<=10000) — amount of testcases. Each of the following *t* lines contain two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=106). Pretests contain all the tests with 0<=&lt;<=*a*<=&lt;<=10,<=0<=≤<=*b*<=&lt;<=10. Output Specification: Print *t* lines — the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10<=-<=6. Demo Input: ['2\n4 2\n1 2\n'] Demo Output: ['0.6250000000\n0.5312500000\n'] Note: none
```python def calArea(a, b): if a <= 4 * b: return a * min(b, a / 4) / 2 return b * b * 2 + (a - 4 * b) * b for _ in range(int(input())): a, b = map(int, input().split()) print("{:.8f}".format(calArea(a, b) / (2 * a * b) + 0.5)) ```
-1
7
A
Kalevitch and Chess
PROGRAMMING
1,100
[ "brute force", "constructive algorithms" ]
A. Kalevitch and Chess
2
64
A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards. As before, the chessboard is a square-checkered board with the squares arranged in a 8<=×<=8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke. Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements. It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task.
The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black. It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row).
Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements.
[ "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n", "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n" ]
[ "3\n", "1\n" ]
none
0
[ { "input": "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW", "output": "3" }, { "input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "output": "1" }, { "input": "WWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "output": "0" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "8" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBW", "output": "14" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBWB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "14" }, { "input": "BBBBBBBB\nWBBBWBBW\nBBBBBBBB\nWBBBWBBW\nWBBBWBBW\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW", "output": "9" }, { "input": "BBBBBBBB\nWBBWWWBB\nBBBBBBBB\nWBBWWWBB\nBBBBBBBB\nBBBBBBBB\nWBBWWWBB\nBBBBBBBB", "output": "9" }, { "input": "BBBBBWWB\nBBBBBBBB\nBBBBBBBB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB\nBBBBBWWB", "output": "8" }, { "input": "WWWWBBBB\nWWWWBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWBBBB\nWWWWBBBB\nBBBBBBBB\nBBBBBBBB", "output": "8" }, { "input": "BBBBBBBB\nWBWWBBBW\nBBBBBBBB\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nBBBBBBBB", "output": "7" }, { "input": "WBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWBWWBBBW\nWBWWBBBW", "output": "9" }, { "input": "BBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBWWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "11" }, { "input": "WWBWBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB\nBBBBBBBB\nWWBWBBBB\nBBBBBBBB", "output": "10" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB\nWWBWBBBB\nBBBBBBBB\nBBBBBBBB\nWWBWBBBB", "output": "10" }, { "input": "WBBWBBBW\nWBBWBBBW\nWBBWBBBW\nWBBWBBBW\nWBBWBBBW\nBBBBBBBB\nWBBWBBBW\nWBBWBBBW", "output": "6" }, { "input": "BBBWBBBW\nBBBWBBBW\nBBBWBBBW\nBBBBBBBB\nBBBBBBBB\nBBBWBBBW\nBBBBBBBB\nBBBBBBBB", "output": "10" }, { "input": "BBBBBBBB\nBBBWBBBB\nBBBWBBBB\nBBBWBBBB\nBBBBBBBB\nBBBWBBBB\nBBBWBBBB\nBBBWBBBB", "output": "9" }, { "input": "BBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "9" }, { "input": "WBBBBBWB\nBBBBBBBB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nWBBBBBWB\nBBBBBBBB", "output": "8" }, { "input": "WBBBWWBW\nWBBBWWBW\nBBBBBBBB\nWBBBWWBW\nBBBBBBBB\nWBBBWWBW\nWBBBWWBW\nWBBBWWBW", "output": "6" }, { "input": "WBBBBWBB\nBBBBBBBB\nBBBBBBBB\nWBBBBWBB\nWBBBBWBB\nBBBBBBBB\nWBBBBWBB\nBBBBBBBB", "output": "10" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW\nBBBBBBBB\nBBBBBBBB\nWBBBWBBW\nBBBBBBBB", "output": "11" }, { "input": "BBBBBBBB\nBWBBBBBW\nBWBBBBBW\nBBBBBBBB\nBWBBBBBW\nBWBBBBBW\nBBBBBBBB\nBWBBBBBW", "output": "9" }, { "input": "BBBBBBBB\nBBBBBBBB\nWBBBWWWW\nBBBBBBBB\nBBBBBBBB\nWBBBWWWW\nBBBBBBBB\nBBBBBBBB", "output": "9" }, { "input": "BWBBBWWB\nBWBBBWWB\nBBBBBBBB\nBBBBBBBB\nBWBBBWWB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB", "output": "10" }, { "input": "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWBWB", "output": "12" }, { "input": "BWBBBBWW\nBWBBBBWW\nBWBBBBWW\nBWBBBBWW\nBBBBBBBB\nBWBBBBWW\nBWBBBBWW\nBBBBBBBB", "output": "7" }, { "input": "WWBBWWBB\nBBBBBBBB\nWWBBWWBB\nWWBBWWBB\nWWBBWWBB\nBBBBBBBB\nWWBBWWBB\nWWBBWWBB", "output": "6" }, { "input": "BWBBWWWW\nBWBBWWWW\nBWBBWWWW\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWWWW\nBBBBBBBB", "output": "7" } ]
1,662,899,187
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
ij = input() lst = [] for a in ij.split('\n'): lst.append(list(a)) k = 0 for j in range(8): if lst[0][j] == "B": k += 1 if k == 8: k = 1 if k == 1: for i in range(1, 8): if lst[i][0] == "B": k += 1 else: for i in range(8): if lst[i][0] == "B": k += 1 print(k)
Title: Kalevitch and Chess Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards. As before, the chessboard is a square-checkered board with the squares arranged in a 8<=×<=8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke. Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements. It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task. Input Specification: The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black. It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row). Output Specification: Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements. Demo Input: ['WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n', 'WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n'] Demo Output: ['3\n', '1\n'] Note: none
```python ij = input() lst = [] for a in ij.split('\n'): lst.append(list(a)) k = 0 for j in range(8): if lst[0][j] == "B": k += 1 if k == 8: k = 1 if k == 1: for i in range(1, 8): if lst[i][0] == "B": k += 1 else: for i in range(8): if lst[i][0] == "B": k += 1 print(k) ```
-1
88
A
Chord
PROGRAMMING
1,200
[ "brute force", "implementation" ]
A. Chord
2
256
Vasya studies music. He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor. Let's define a major triad. Let the triad consist of notes *X*, *Y* and *Z*. If we can order the notes so as the distance along the musical scale between *X* and *Y* equals 4 semitones and the distance between *Y* and *Z* is 3 semitones, then the triad is major. The distance between *X* and *Z*, accordingly, equals 7 semitones. A minor triad is different in that the distance between *X* and *Y* should be 3 semitones and between *Y* and *Z* — 4 semitones. For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones. Help Vasya classify the triad the teacher has given to him.
The only line contains 3 space-separated notes in the above-given notation.
Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.
[ "C E G\n", "C# B F\n", "A B H\n" ]
[ "major\n", "minor\n", "strange\n" ]
none
500
[ { "input": "C E G", "output": "major" }, { "input": "C# B F", "output": "minor" }, { "input": "A B H", "output": "strange" }, { "input": "G H E", "output": "minor" }, { "input": "D# B G", "output": "major" }, { "input": "D# B F#", "output": "minor" }, { "input": "F H E", "output": "strange" }, { "input": "B F# G", "output": "strange" }, { "input": "F# H C", "output": "strange" }, { "input": "C# F C", "output": "strange" }, { "input": "G# C# E", "output": "minor" }, { "input": "D# H G#", "output": "minor" }, { "input": "C F A", "output": "major" }, { "input": "H E G#", "output": "major" }, { "input": "G D# B", "output": "major" }, { "input": "E C G", "output": "major" }, { "input": "G# C# F", "output": "major" }, { "input": "D# C G#", "output": "major" }, { "input": "C# F B", "output": "minor" }, { "input": "D# C G", "output": "minor" }, { "input": "A D F", "output": "minor" }, { "input": "F# H D", "output": "minor" }, { "input": "D A F", "output": "minor" }, { "input": "D A F#", "output": "major" }, { "input": "C# B F", "output": "minor" }, { "input": "A C F", "output": "major" }, { "input": "D F# H", "output": "minor" }, { "input": "H G# D#", "output": "minor" }, { "input": "A D F#", "output": "major" }, { "input": "H E G#", "output": "major" }, { "input": "D# B F#", "output": "minor" }, { "input": "D# H F#", "output": "major" }, { "input": "A D F#", "output": "major" }, { "input": "B G D#", "output": "major" }, { "input": "E A C#", "output": "major" }, { "input": "D H G", "output": "major" }, { "input": "H D F#", "output": "minor" }, { "input": "G D# C", "output": "minor" }, { "input": "H D G", "output": "major" }, { "input": "E C G", "output": "major" }, { "input": "D# A E", "output": "strange" }, { "input": "A F E", "output": "strange" }, { "input": "C E F", "output": "strange" }, { "input": "A B C", "output": "strange" }, { "input": "E F D#", "output": "strange" }, { "input": "C G# G#", "output": "strange" }, { "input": "F D# G#", "output": "strange" }, { "input": "B G D#", "output": "major" }, { "input": "E E G#", "output": "strange" }, { "input": "A G H", "output": "strange" }, { "input": "F E A", "output": "strange" }, { "input": "D B E", "output": "strange" }, { "input": "G# C# D", "output": "strange" }, { "input": "D# D# F#", "output": "strange" }, { "input": "H B G", "output": "strange" }, { "input": "D C B", "output": "strange" }, { "input": "D B B", "output": "strange" }, { "input": "C A H", "output": "strange" }, { "input": "F# H F#", "output": "strange" }, { "input": "A F F#", "output": "strange" }, { "input": "C D C", "output": "strange" }, { "input": "G F# A", "output": "strange" }, { "input": "C C# D", "output": "strange" }, { "input": "C A E", "output": "minor" }, { "input": "A H B", "output": "strange" }, { "input": "B E F#", "output": "strange" }, { "input": "G# G# A", "output": "strange" }, { "input": "B C# C#", "output": "strange" }, { "input": "C G D#", "output": "minor" }, { "input": "C B D#", "output": "strange" }, { "input": "F H F", "output": "strange" }, { "input": "E G# C", "output": "strange" }, { "input": "F# F# F#", "output": "strange" }, { "input": "F C F", "output": "strange" }, { "input": "A F D", "output": "minor" } ]
1,564,336,445
2,147,483,647
Python 3
OK
TESTS
75
248
0
acords = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'B', 'H'] lst = sorted(acords.index(x) for x in input().split()) dif = (lst[1] - lst[0], lst[2] - lst[1]) if dif in ((4, 3), (3, 5), (5, 4)): print('major') elif dif in ((3, 4), (4, 5), (5, 3)): print('minor') else: print('strange')
Title: Chord Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya studies music. He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitones Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor. Let's define a major triad. Let the triad consist of notes *X*, *Y* and *Z*. If we can order the notes so as the distance along the musical scale between *X* and *Y* equals 4 semitones and the distance between *Y* and *Z* is 3 semitones, then the triad is major. The distance between *X* and *Z*, accordingly, equals 7 semitones. A minor triad is different in that the distance between *X* and *Y* should be 3 semitones and between *Y* and *Z* — 4 semitones. For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones. Help Vasya classify the triad the teacher has given to him. Input Specification: The only line contains 3 space-separated notes in the above-given notation. Output Specification: Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously. Demo Input: ['C E G\n', 'C# B F\n', 'A B H\n'] Demo Output: ['major\n', 'minor\n', 'strange\n'] Note: none
```python acords = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'B', 'H'] lst = sorted(acords.index(x) for x in input().split()) dif = (lst[1] - lst[0], lst[2] - lst[1]) if dif in ((4, 3), (3, 5), (5, 4)): print('major') elif dif in ((3, 4), (4, 5), (5, 3)): print('minor') else: print('strange') ```
3.938
120
B
Quiz League
PROGRAMMING
1,100
[ "implementation" ]
null
null
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number *k*.
The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=1000 and 1<=≤<=*k*<=≤<=*n*) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains *n* numbers: *a**i*<==<=0 if the question from sector *i* has already been asked and *a**i*<==<=1 if the question from sector *i* hasn't been asked yet (1<=≤<=*i*<=≤<=*n*). The sectors are given in the clockwise order, the first sector follows after the *n*-th one.
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
[ "5 5\n0 1 0 1 0\n", "2 1\n1 1\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "5 5\n0 1 0 1 0", "output": "2" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "3 2\n1 0 0", "output": "1" }, { "input": "3 3\n0 1 0", "output": "2" }, { "input": "1 1\n1", "output": "1" }, { "input": "6 3\n0 0 1 1 0 1", "output": "3" }, { "input": "3 1\n0 1 0", "output": "2" }, { "input": "3 3\n1 0 1", "output": "3" }, { "input": "4 4\n1 0 1 0", "output": "1" }, { "input": "5 3\n0 1 0 1 1", "output": "4" }, { "input": "6 4\n1 0 0 0 0 1", "output": "6" }, { "input": "7 5\n1 0 0 0 0 0 1", "output": "7" }, { "input": "101 81\n1 0 1 1 1 1 0 0 1 1 1 1 1 0 0 1 0 1 0 1 1 1 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 1 0 1 1 0 0 1 0 0 1 0 0 0 0 0 0 1 1 0 1 1 0 1 0 0 0 0 1 0 0 1 1 0 0 1 0 1 0 0 0 1 0", "output": "82" }, { "input": "200 31\n1 0 0 1 1 1 0 0 0 0 0 1 1 1 0 1 1 0 0 1 0 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 1 1 1 0 1 0 1 0 1 0 0 1 1 1 0 0 0 1 0 0 0 1 1 0 0 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 0 0 0 0 1 0 1 1 1 0 1 1 0 0 1 1 1 1 1 0 1 0 1 1 0 1 0 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 1 1 0 1 1 1 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 0 1 1 1 1 1 0 1 0 0 0 0 1 1 0 1 0 1 1 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 0 1 0", "output": "33" }, { "input": "17 13\n0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 1 1", "output": "13" }, { "input": "102 9\n0 0 0 0 1 1 0 1 0 1 1 1 1 0 1 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 1 0 1 1 0 1 0 0 0 0 0 0 0 1 1 0 0 1 1", "output": "10" } ]
1,586,351,394
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
0
n,k = map(int,input().split()) l = list(map(int,input().split())) k = k - 1 while(1): if(l[k] == 0): k = k + 1 k = k % n if(l[k] == 1): break print(k+1)
Title: Quiz League Time Limit: None seconds Memory Limit: None megabytes Problem Description: A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number *k*. Input Specification: The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=1000 and 1<=≤<=*k*<=≤<=*n*) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains *n* numbers: *a**i*<==<=0 if the question from sector *i* has already been asked and *a**i*<==<=1 if the question from sector *i* hasn't been asked yet (1<=≤<=*i*<=≤<=*n*). The sectors are given in the clockwise order, the first sector follows after the *n*-th one. Output Specification: Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. Demo Input: ['5 5\n0 1 0 1 0\n', '2 1\n1 1\n'] Demo Output: ['2\n', '1\n'] Note: none
```python n,k = map(int,input().split()) l = list(map(int,input().split())) k = k - 1 while(1): if(l[k] == 0): k = k + 1 k = k % n if(l[k] == 1): break print(k+1) ```
-1
843
A
Sorting by Subsequences
PROGRAMMING
1,400
[ "dfs and similar", "dsu", "implementation", "math", "sortings" ]
null
null
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order. Sorting integers in a subsequence is a process such that the numbers included in a subsequence are ordered in increasing order, and the numbers which are not included in a subsequence don't change their places. Every element of the sequence must appear in exactly one subsequence.
The first line of input data contains integer *n* (1<=≤<=*n*<=≤<=105) — the length of the sequence. The second line of input data contains *n* different integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the elements of the sequence. It is guaranteed that all elements of the sequence are distinct.
In the first line print the maximum number of subsequences *k*, which the original sequence can be split into while fulfilling the requirements. In the next *k* lines print the description of subsequences in the following format: the number of elements in subsequence *c**i* (0<=&lt;<=*c**i*<=≤<=*n*), then *c**i* integers *l*1,<=*l*2,<=...,<=*l**c**i* (1<=≤<=*l**j*<=≤<=*n*) — indices of these elements in the original sequence. Indices could be printed in any order. Every index from 1 to *n* must appear in output exactly once. If there are several possible answers, print any of them.
[ "6\n3 2 1 6 5 4\n", "6\n83 -75 -49 11 37 62\n" ]
[ "4\n2 1 3\n1 2\n2 4 6\n1 5\n", "1\n6 1 2 3 4 5 6\n" ]
In the first sample output: After sorting the first subsequence we will get sequence 1 2 3 6 5 4. Sorting the second subsequence changes nothing. After sorting the third subsequence we will get sequence 1 2 3 4 5 6. Sorting the last subsequence changes nothing.
500
[ { "input": "6\n3 2 1 6 5 4", "output": "4\n2 1 3\n1 2\n2 4 6\n1 5" }, { "input": "6\n83 -75 -49 11 37 62", "output": "1\n6 1 2 3 4 5 6" }, { "input": "1\n1", "output": "1\n1 1" }, { "input": "2\n1 2", "output": "2\n1 1\n1 2" }, { "input": "2\n2 1", "output": "1\n2 1 2" }, { "input": "3\n1 2 3", "output": "3\n1 1\n1 2\n1 3" }, { "input": "3\n3 2 1", "output": "2\n2 1 3\n1 2" }, { "input": "3\n3 1 2", "output": "1\n3 1 2 3" }, { "input": "10\n3 7 10 1 9 5 4 8 6 2", "output": "3\n6 1 4 7 2 10 3\n3 5 6 9\n1 8" }, { "input": "20\n363756450 -204491568 95834122 -840249197 -49687658 470958158 -445130206 189801569 802780784 -790013317 -192321079 586260100 -751917965 -354684803 418379342 -253230108 193944314 712662868 853829789 735867677", "output": "3\n7 1 4 7 2 10 3 13\n11 5 14 15 6 16 12 17 18 20 19 9\n2 8 11" }, { "input": "50\n39 7 45 25 31 26 50 11 19 37 8 16 22 33 14 6 12 46 49 48 29 27 41 15 34 24 3 13 20 47 9 36 5 43 40 21 2 38 35 42 23 28 1 32 10 17 30 18 44 4", "output": "6\n20 1 43 34 25 4 50 7 2 37 10 45 3 27 22 13 28 42 40 35 39\n23 5 33 14 15 24 26 6 16 12 17 46 18 48 20 29 21 36 32 44 49 19 9 31\n2 8 11\n2 23 41\n2 30 47\n1 38" }, { "input": "100\n39 77 67 25 81 26 50 11 73 95 86 16 90 33 14 79 12 100 68 64 60 27 41 15 34 24 3 61 83 47 57 65 99 43 40 21 94 72 82 85 23 71 76 32 10 17 30 18 44 59 35 89 6 63 7 69 62 70 4 29 92 87 31 48 36 28 45 97 93 98 56 38 58 80 8 1 74 91 53 55 54 51 96 5 42 52 9 22 78 88 75 13 66 2 37 20 49 19 84 46", "output": "6\n41 1 76 43 34 25 4 59 50 7 55 80 74 77 2 94 37 95 10 45 67 3 27 22 88 90 13 92 61 28 66 93 69 56 71 42 85 40 35 51 82 39\n45 5 84 99 33 14 15 24 26 6 53 79 16 12 17 46 100 18 48 64 20 96 83 29 60 21 36 65 32 44 49 97 68 19 98 70 58 73 9 87 62 57 31 63 54 81\n8 8 75 91 78 89 52 86 11\n2 23 41\n2 30 47\n2 38 72" } ]
1,503,593,046
546
Python 3
OK
TESTS
71
857
19,251,200
n = int(input()) a = list(map(int, input().split())) x = sorted([(a[i], i) for i in range(n)]) cycles = [] was = [False for i in range(n)] for i in range(n): if was[i]: continue cur = i cyc = [] while not was[cur]: was[cur] = True cyc.append(cur + 1) cur = x[cur][1] cycles.append(cyc) print(len(cycles)) for cyc in cycles: print(len(cyc), ' '.join(map(str, cyc)))
Title: Sorting by Subsequences Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order. Sorting integers in a subsequence is a process such that the numbers included in a subsequence are ordered in increasing order, and the numbers which are not included in a subsequence don't change their places. Every element of the sequence must appear in exactly one subsequence. Input Specification: The first line of input data contains integer *n* (1<=≤<=*n*<=≤<=105) — the length of the sequence. The second line of input data contains *n* different integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the elements of the sequence. It is guaranteed that all elements of the sequence are distinct. Output Specification: In the first line print the maximum number of subsequences *k*, which the original sequence can be split into while fulfilling the requirements. In the next *k* lines print the description of subsequences in the following format: the number of elements in subsequence *c**i* (0<=&lt;<=*c**i*<=≤<=*n*), then *c**i* integers *l*1,<=*l*2,<=...,<=*l**c**i* (1<=≤<=*l**j*<=≤<=*n*) — indices of these elements in the original sequence. Indices could be printed in any order. Every index from 1 to *n* must appear in output exactly once. If there are several possible answers, print any of them. Demo Input: ['6\n3 2 1 6 5 4\n', '6\n83 -75 -49 11 37 62\n'] Demo Output: ['4\n2 1 3\n1 2\n2 4 6\n1 5\n', '1\n6 1 2 3 4 5 6\n'] Note: In the first sample output: After sorting the first subsequence we will get sequence 1 2 3 6 5 4. Sorting the second subsequence changes nothing. After sorting the third subsequence we will get sequence 1 2 3 4 5 6. Sorting the last subsequence changes nothing.
```python n = int(input()) a = list(map(int, input().split())) x = sorted([(a[i], i) for i in range(n)]) cycles = [] was = [False for i in range(n)] for i in range(n): if was[i]: continue cur = i cyc = [] while not was[cur]: was[cur] = True cyc.append(cur + 1) cur = x[cur][1] cycles.append(cyc) print(len(cycles)) for cyc in cycles: print(len(cyc), ' '.join(map(str, cyc))) ```
3
6
B
President's Office
PROGRAMMING
1,100
[ "implementation" ]
B. President's Office
2
64
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length. The office-room plan can be viewed as a matrix with *n* rows and *m* columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Print the only number — the amount of President's deputies.
[ "3 4 R\nG.B.\n.RR.\nTTT.\n", "3 3 Z\n...\n.H.\n..Z\n" ]
[ "2\n", "0\n" ]
none
0
[ { "input": "3 4 R\nG.B.\n.RR.\nTTT.", "output": "2" }, { "input": "3 3 Z\n...\n.H.\n..Z", "output": "0" }, { "input": "1 1 C\nC", "output": "0" }, { "input": "2 2 W\nKW\nKW", "output": "1" }, { "input": "1 10 H\n....DDHHHH", "output": "1" }, { "input": "3 2 W\nOO\nWW\nWW", "output": "1" }, { "input": "3 3 U\nUOO\nUVV\nUVV", "output": "2" }, { "input": "4 5 Z\n...ZZ\nUU.ZZ\nUUTT.\n..TT.", "output": "1" }, { "input": "4 4 X\nT..R\nTJJJ\nDJJJ\nXJJJ", "output": "2" }, { "input": "5 5 O\nCQGAV\nIHTUD\nRFPZO\nMYSKX\nJEWBN", "output": "3" }, { "input": "5 4 O\n.O.J\nWOBJ\nWOBJ\nDDBJ\nDD.J", "output": "3" }, { "input": "7 7 Q\n....RRR\nUUUURRR\nUUUUSS.\n....SSB\nPPP.OIB\n.MMTTIB\nQQQTTIB", "output": "2" }, { "input": "8 10 B\n..BBBBEEEE\n..BBBBEEEE\n..BBBBEEEE\n..BBBBEEEE\nJJJJYYYY..\nJJJJYYYY..\nJJJJYYYY..\nJJJJYYYY..", "output": "3" }, { "input": "7 13 G\n....GGGGGGXXX\nSSSSGGGGGGXXX\nSSSSJJFFFFFFF\nRRR.JJFFFFFFF\nRRRYYYYYYYAAA\nRRRYYYYYYYAAA\nRRR.......AAA", "output": "4" }, { "input": "10 10 T\nCCEEEKKKHJ\nCCRRRRRRHJ\nCC..XFFOOO\nZZZZZFFOOO\n..PTTFFOOO\nAAATTFFOOO\nAAATTYYYYY\nAAATTYYYYY\nAAAMMYYYYY\nAAA..YYYYY", "output": "6" }, { "input": "15 12 M\n............\n.....L..QQQQ\nNNN..L..QQQQ\nNNN..LJJJJJ.\nNNNEEEEEEEE.\nNNNEEEEEEEE.\nNNNMMMMM.AAA\nNNNMMMMM.AAA\n.RRMMMMM.AAA\n.RRMMMMMYAAA\n.RRMMMMMYAAA\n.RRMMMMMYAAA\nZRRMMMMMYAAA\nZRRMMMMM.AAA\nZRRMMMMM.AAA", "output": "4" } ]
1,673,354,182
2,147,483,647
Python 3
OK
TESTS
32
77
0
n,m,c=input().split() n=int(n) m=int(m) mat=[""]*n for i in range(n): mat[i]=input() ans=set() for i in range(n): for j in range(m): if mat[i][j]==c: for x,y in (i-1,j),(i+1,j),(i,j-1),(i,j+1): if x in range(n) and y in range(m) and mat[x][y]!='.': ans.add(mat[x][y]) print(len(ans-{c}))
Title: President's Office Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length. The office-room plan can be viewed as a matrix with *n* rows and *m* columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell. Input Specification: The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters. Output Specification: Print the only number — the amount of President's deputies. Demo Input: ['3 4 R\nG.B.\n.RR.\nTTT.\n', '3 3 Z\n...\n.H.\n..Z\n'] Demo Output: ['2\n', '0\n'] Note: none
```python n,m,c=input().split() n=int(n) m=int(m) mat=[""]*n for i in range(n): mat[i]=input() ans=set() for i in range(n): for j in range(m): if mat[i][j]==c: for x,y in (i-1,j),(i+1,j),(i,j-1),(i,j+1): if x in range(n) and y in range(m) and mat[x][y]!='.': ans.add(mat[x][y]) print(len(ans-{c})) ```
3.98075
459
B
Pashmak and Flowers
PROGRAMMING
1,300
[ "combinatorics", "implementation", "sortings" ]
null
null
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible! Your task is to write a program which calculates two things: 1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.
The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
[ "2\n1 2\n", "3\n1 4 5\n", "5\n3 1 2 3 1\n" ]
[ "1 1", "4 1", "2 4" ]
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers.
500
[ { "input": "2\n1 2", "output": "1 1" }, { "input": "3\n1 4 5", "output": "4 1" }, { "input": "5\n3 1 2 3 1", "output": "2 4" }, { "input": "2\n1 1", "output": "0 1" }, { "input": "3\n1 1 1", "output": "0 3" }, { "input": "4\n1 1 1 1", "output": "0 6" }, { "input": "5\n1 1 1 1 1", "output": "0 10" }, { "input": "5\n2 2 2 2 2", "output": "0 10" }, { "input": "10\n2 2 2 2 2 2 2 2 2 2", "output": "0 45" }, { "input": "3\n2 2 2", "output": "0 3" }, { "input": "3\n3 3 3", "output": "0 3" }, { "input": "2\n10000000 100000000", "output": "90000000 1" }, { "input": "5\n5 5 5 5 5", "output": "0 10" }, { "input": "5\n3 3 3 3 3", "output": "0 10" }, { "input": "6\n1 1 1 1 1 1", "output": "0 15" }, { "input": "2\n5 6", "output": "1 1" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "0 45" }, { "input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "0 45" }, { "input": "4\n4 4 4 4", "output": "0 6" }, { "input": "7\n1 1 1 1 1 1 1", "output": "0 21" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "0 55" }, { "input": "8\n8 8 8 8 8 8 8 8", "output": "0 28" }, { "input": "2\n3 2", "output": "1 1" } ]
1,663,707,893
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
124
24,268,800
from collections import Counter n=int(input()) arr=list(map(int,input().split())) mx,mn=max(arr),min(arr) f=Counter(arr) print(mx-mn,f.get(mx)*f.get(mn))
Title: Pashmak and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible! Your task is to write a program which calculates two things: 1. The maximum beauty difference of flowers that Pashmak can give to Parmida. 1. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way. Input Specification: The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). Output Specification: The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. Demo Input: ['2\n1 2\n', '3\n1 4 5\n', '5\n3 1 2 3 1\n'] Demo Output: ['1 1', '4 1', '2 4'] Note: In the third sample the maximum beauty difference is 2 and there are 4 ways to do this: 1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers.
```python from collections import Counter n=int(input()) arr=list(map(int,input().split())) mx,mn=max(arr),min(arr) f=Counter(arr) print(mx-mn,f.get(mx)*f.get(mn)) ```
0
954
A
Diagonal Walking
PROGRAMMING
800
[ "implementation" ]
null
null
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left. Your problem is to print the minimum possible length of the sequence of moves after the replacements.
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R.
Print the minimum possible length of the sequence of moves after all replacements are done.
[ "5\nRUURU\n", "17\nUUURRRRRUUURURUUU\n" ]
[ "3\n", "13\n" ]
In the first test the shortened sequence of moves may be DUD (its length is 3). In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).
0
[ { "input": "5\nRUURU", "output": "3" }, { "input": "17\nUUURRRRRUUURURUUU", "output": "13" }, { "input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", "output": "100" }, { "input": "100\nRRURRUUUURURRRURRRRURRRRRRURRUURRRUUURUURURRURUURUURRUURUURRURURUUUUURUUUUUURRUUURRRURRURRRUURRUUUUR", "output": "67" }, { "input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURUUUUUUUUUUUUUUUUUUUUU", "output": "99" }, { "input": "3\nRUR", "output": "2" }, { "input": "1\nR", "output": "1" }, { "input": "5\nRURUU", "output": "3" }, { "input": "1\nU", "output": "1" }, { "input": "2\nUR", "output": "1" }, { "input": "23\nUUUUUUUUUUUUUUUUUUUUUUU", "output": "23" } ]
1,637,777,138
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
31
0
a=int(input()) b=input() c=b.replace("RU","D") d=c.replace("UR","D") print(len(d))
Title: Diagonal Walking Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left. Your problem is to print the minimum possible length of the sequence of moves after the replacements. Input Specification: The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. Output Specification: Print the minimum possible length of the sequence of moves after all replacements are done. Demo Input: ['5\nRUURU\n', '17\nUUURRRRRUUURURUUU\n'] Demo Output: ['3\n', '13\n'] Note: In the first test the shortened sequence of moves may be DUD (its length is 3). In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).
```python a=int(input()) b=input() c=b.replace("RU","D") d=c.replace("UR","D") print(len(d)) ```
0
659
C
Tanya and Toys
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles. Tania has managed to collect *n* different types of toys *a*1,<=*a*2,<=...,<=*a**n* from the new collection. Today is Tanya's birthday, and her mother decided to spend no more than *m* bourles on the gift to the daughter. Tanya will choose several different types of toys from the new collection as a gift. Of course, she does not want to get a type of toy which she already has. Tanya wants to have as many distinct types of toys in her collection as possible as the result. The new collection is too diverse, and Tanya is too little, so she asks you to help her in this.
The first line contains two integers *n* (1<=≤<=*n*<=≤<=100<=000) and *m* (1<=≤<=*m*<=≤<=109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys. The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the types of toys that Tanya already has.
In the first line print a single integer *k* — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed *m*. In the second line print *k* distinct space-separated integers *t*1,<=*t*2,<=...,<=*t**k* (1<=≤<=*t**i*<=≤<=109) — the types of toys that Tanya should choose. If there are multiple answers, you may print any of them. Values of *t**i* can be printed in any order.
[ "3 7\n1 3 4\n", "4 14\n4 6 12 8\n" ]
[ "2\n2 5 \n", "4\n7 2 3 1\n" ]
In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys.
1,000
[ { "input": "3 7\n1 3 4", "output": "2\n2 5 " }, { "input": "4 14\n4 6 12 8", "output": "4\n1 2 3 5 " }, { "input": "5 6\n97746 64770 31551 96547 65684", "output": "3\n1 2 3 " }, { "input": "10 10\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656", "output": "4\n1 2 3 4 " }, { "input": "30 38\n9560 64176 75619 53112 54160 68775 12655 13118 99502 89757 78434 42521 19210 1927 34097 5416 56110 44786 59126 44266 79240 65567 54602 25325 37171 2879 89291 89121 39568 28162", "output": "8\n1 2 3 4 5 6 7 8 " }, { "input": "1 999999298\n85187", "output": "44720\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..." }, { "input": "1 999999119\n34421", "output": "44720\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..." }, { "input": "1 1000000000\n1", "output": "44719\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..." }, { "input": "1 1000000000\n44720", "output": "44720\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..." }, { "input": "1 1000000000\n44719", "output": "44720\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..." }, { "input": "1 1000000000\n44721", "output": "44720\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..." }, { "input": "3 1000000000\n123456789 234567891 345678912", "output": "44720\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..." }, { "input": "2 5\n999999999 1000000000", "output": "2\n1 2 " }, { "input": "2 1000000000\n1 1000000000", "output": "44719\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15..." }, { "input": "3 100000\n1000000000 100000000 1", "output": "445\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 ..." }, { "input": "5 5\n100000000 200000000 300000000 400000000 1000000000", "output": "2\n1 2 " }, { "input": "6 3\n1 2 3 4 5 6", "output": "0" }, { "input": "2 1\n1 2", "output": "0" }, { "input": "1 1000000000\n1000000000", "output": "44720\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..." }, { "input": "5 1000000\n1000000000 100000000 10000000 99999999 123456789", "output": "1413\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..." }, { "input": "2 10000000\n1234567 123456", "output": "4471\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..." }, { "input": "1 1\n1000000000", "output": "1\n1 " }, { "input": "1 1000000000\n9999999", "output": "44720\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 ..." }, { "input": "5 10000\n1000000000 888888888 777777777 666666666 959595959", "output": "140\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 " }, { "input": "3 1\n1000000000 999999999 999999998", "output": "1\n1 " }, { "input": "5 100000000\n100000000 999999999 1 2 3", "output": "14138\n4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 15..." }, { "input": "3 55\n100000000 1000000000 999999999", "output": "10\n1 2 3 4 5 6 7 8 9 10 " }, { "input": "2 10\n5 10000009", "output": "4\n1 2 3 4 " }, { "input": "3 10000000\n999999999 999999998 999999997", "output": "4471\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1..." }, { "input": "1 1100\n1000000000", "output": "46\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 " }, { "input": "1 40\n1000000000", "output": "8\n1 2 3 4 5 6 7 8 " } ]
1,493,517,034
2,147,483,647
Python 3
OK
TESTS
61
171
13,926,400
t,m=map(int,input().split()) x=sorted(list(map(int,input().split()))) pos=0 buys=[] i=1 while True: if pos<t and i==x[pos]: pos+=1 else: if i>m:break else: m-=i buys.append(i) i+=1 print(len(buys)) print(' '.join(list(map(str,buys))))
Title: Tanya and Toys Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles. Tania has managed to collect *n* different types of toys *a*1,<=*a*2,<=...,<=*a**n* from the new collection. Today is Tanya's birthday, and her mother decided to spend no more than *m* bourles on the gift to the daughter. Tanya will choose several different types of toys from the new collection as a gift. Of course, she does not want to get a type of toy which she already has. Tanya wants to have as many distinct types of toys in her collection as possible as the result. The new collection is too diverse, and Tanya is too little, so she asks you to help her in this. Input Specification: The first line contains two integers *n* (1<=≤<=*n*<=≤<=100<=000) and *m* (1<=≤<=*m*<=≤<=109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys. The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the types of toys that Tanya already has. Output Specification: In the first line print a single integer *k* — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed *m*. In the second line print *k* distinct space-separated integers *t*1,<=*t*2,<=...,<=*t**k* (1<=≤<=*t**i*<=≤<=109) — the types of toys that Tanya should choose. If there are multiple answers, you may print any of them. Values of *t**i* can be printed in any order. Demo Input: ['3 7\n1 3 4\n', '4 14\n4 6 12 8\n'] Demo Output: ['2\n2 5 \n', '4\n7 2 3 1\n'] Note: In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys.
```python t,m=map(int,input().split()) x=sorted(list(map(int,input().split()))) pos=0 buys=[] i=1 while True: if pos<t and i==x[pos]: pos+=1 else: if i>m:break else: m-=i buys.append(i) i+=1 print(len(buys)) print(' '.join(list(map(str,buys)))) ```
3
474
B
Worms
PROGRAMMING
1,200
[ "binary search", "implementation" ]
null
null
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled with numbers *a*1<=+<=1 to *a*1<=+<=*a*2 and so on. See the example for a better understanding. Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained. Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile. The third line contains single integer *m* (1<=≤<=*m*<=≤<=105), the number of juicy worms said by Marmot. The fourth line contains *m* integers *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*), the labels of the juicy worms.
Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is.
[ "5\n2 7 3 4 9\n3\n1 25 11\n" ]
[ "1\n5\n3\n" ]
For the sample input: - The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the fifth pile.
1,000
[ { "input": "5\n2 7 3 4 9\n3\n1 25 11", "output": "1\n5\n3" } ]
1,689,990,743
2,147,483,647
Python 3
OK
TESTS
38
904
14,643,200
n = int(input()) ls = list(map(int,input().split())) q = int(input()) la = list(map(int,input().split())) for i in range(1,len(ls)): ls[i] = ls[i]+ls[i-1] for i in range(len(la)): low = 0 high = len(ls) flag= True while low<=high: mid = (low+high)//2 if ls[mid]<la[i]: low = mid+1 elif mid == 0 and ls[mid]>=la[i] and 0<la[i]: print(mid+1) flag=False break elif mid!=0 and ls[mid]>=la[i] and ls[mid-1]<la[i]: print(mid+1) flag=False break else: high = mid-1
Title: Worms Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled with numbers *a*1<=+<=1 to *a*1<=+<=*a*2 and so on. See the example for a better understanding. Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained. Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile. The third line contains single integer *m* (1<=≤<=*m*<=≤<=105), the number of juicy worms said by Marmot. The fourth line contains *m* integers *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*), the labels of the juicy worms. Output Specification: Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. Demo Input: ['5\n2 7 3 4 9\n3\n1 25 11\n'] Demo Output: ['1\n5\n3\n'] Note: For the sample input: - The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the fifth pile.
```python n = int(input()) ls = list(map(int,input().split())) q = int(input()) la = list(map(int,input().split())) for i in range(1,len(ls)): ls[i] = ls[i]+ls[i-1] for i in range(len(la)): low = 0 high = len(ls) flag= True while low<=high: mid = (low+high)//2 if ls[mid]<la[i]: low = mid+1 elif mid == 0 and ls[mid]>=la[i] and 0<la[i]: print(mid+1) flag=False break elif mid!=0 and ls[mid]>=la[i] and ls[mid-1]<la[i]: print(mid+1) flag=False break else: high = mid-1 ```
3
557
C
Arthur and Table
PROGRAMMING
1,900
[ "brute force", "data structures", "dp", "greedy", "math", "sortings" ]
null
null
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has *n* legs, the length of the *i*-th leg is *l**i*. Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number *d**i* — the amount of energy that he spends to remove the *i*-th leg. A table with *k* legs is assumed to be stable if there are more than half legs of the maximum length. For example, to make a table with 5 legs stable, you need to make sure it has at least three (out of these five) legs of the maximum length. Also, a table with one leg is always stable and a table with two legs is stable if and only if they have the same lengths. Your task is to help Arthur and count the minimum number of energy units Arthur should spend on making the table stable.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the initial number of legs in the table Arthur bought. The second line of the input contains a sequence of *n* integers *l**i* (1<=≤<=*l**i*<=≤<=105), where *l**i* is equal to the length of the *i*-th leg of the table. The third line of the input contains a sequence of *n* integers *d**i* (1<=≤<=*d**i*<=≤<=200), where *d**i* is the number of energy units that Arthur spends on removing the *i*-th leg off the table.
Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable.
[ "2\n1 5\n3 2\n", "3\n2 4 4\n1 1 1\n", "6\n2 2 1 1 3 3\n4 3 5 5 2 1\n" ]
[ "2\n", "0\n", "8\n" ]
none
1,500
[ { "input": "2\n1 5\n3 2", "output": "2" }, { "input": "3\n2 4 4\n1 1 1", "output": "0" }, { "input": "6\n2 2 1 1 3 3\n4 3 5 5 2 1", "output": "8" }, { "input": "10\n20 1 15 17 11 2 15 3 16 3\n129 114 183 94 169 16 18 104 49 146", "output": "652" }, { "input": "10\n15 16 19 5 14 19 6 17 7 19\n140 183 186 195 67 25 70 56 54 132", "output": "387" }, { "input": "20\n24 15 7 18 6 18 11 22 18 20 28 8 23 17 22 22 23 23 30 23\n24 137 173 189 43 164 2 11 142 153 16 200 53 58 150 199 169 172 38 78", "output": "1111" }, { "input": "30\n20 27 26 17 29 9 25 13 6 21 15 1 14 22 26 2 15 18 20 23 27 9 15 29 11 2 19 23 14 12\n133 199 22 151 9 134 196 119 197 189 117 84 156 6 61 195 98 197 145 75 142 85 187 24 159 3 60 138 156 161", "output": "2804" }, { "input": "5\n1 1 2 2 3\n2 2 2 2 3", "output": "5" }, { "input": "5\n1 1 2 2 3\n2 2 2 2 7", "output": "8" }, { "input": "10\n1 1 3 4 5 6 7 8 9 10\n10 10 4 2 3 4 2 2 2 2", "output": "21" }, { "input": "1\n5\n4", "output": "0" }, { "input": "2\n3 3\n4 5", "output": "0" }, { "input": "2\n4 5\n3 3", "output": "3" }, { "input": "3\n3 3 3\n1 2 3", "output": "0" }, { "input": "3\n1 2 3\n3 3 3", "output": "6" } ]
1,580,278,694
2,147,483,647
PyPy 3
OK
TESTS
45
685
13,312,000
MAX_D = 201 n = int(input()) l = list(map(int, input().split())) d = list(map(int, input().split())) legs = sorted(list(zip(l, d))) d_suffix = [legs[0][1]] for i in range(1, n): d_suffix.append(d_suffix[-1] + legs[i][1]) ans = d_suffix[-1] cnt = {} left = 0 right = 0 while left < n: while right < n and legs[left][0] == legs[right][0]: right += 1 to_remove = left - (right - left - 1) curr_d = d_suffix[-1] - d_suffix[right - 1] for i in range(1, MAX_D): if to_remove <= 0: break used = min(to_remove, cnt.get(i, 0)) to_remove -= used curr_d += used * i ans = min(ans, curr_d) while left < right: cnt[legs[left][1]] = cnt.get(legs[left][1], 0) + 1 left += 1 print(ans)
Title: Arthur and Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has *n* legs, the length of the *i*-th leg is *l**i*. Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number *d**i* — the amount of energy that he spends to remove the *i*-th leg. A table with *k* legs is assumed to be stable if there are more than half legs of the maximum length. For example, to make a table with 5 legs stable, you need to make sure it has at least three (out of these five) legs of the maximum length. Also, a table with one leg is always stable and a table with two legs is stable if and only if they have the same lengths. Your task is to help Arthur and count the minimum number of energy units Arthur should spend on making the table stable. Input Specification: The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the initial number of legs in the table Arthur bought. The second line of the input contains a sequence of *n* integers *l**i* (1<=≤<=*l**i*<=≤<=105), where *l**i* is equal to the length of the *i*-th leg of the table. The third line of the input contains a sequence of *n* integers *d**i* (1<=≤<=*d**i*<=≤<=200), where *d**i* is the number of energy units that Arthur spends on removing the *i*-th leg off the table. Output Specification: Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable. Demo Input: ['2\n1 5\n3 2\n', '3\n2 4 4\n1 1 1\n', '6\n2 2 1 1 3 3\n4 3 5 5 2 1\n'] Demo Output: ['2\n', '0\n', '8\n'] Note: none
```python MAX_D = 201 n = int(input()) l = list(map(int, input().split())) d = list(map(int, input().split())) legs = sorted(list(zip(l, d))) d_suffix = [legs[0][1]] for i in range(1, n): d_suffix.append(d_suffix[-1] + legs[i][1]) ans = d_suffix[-1] cnt = {} left = 0 right = 0 while left < n: while right < n and legs[left][0] == legs[right][0]: right += 1 to_remove = left - (right - left - 1) curr_d = d_suffix[-1] - d_suffix[right - 1] for i in range(1, MAX_D): if to_remove <= 0: break used = min(to_remove, cnt.get(i, 0)) to_remove -= used curr_d += used * i ans = min(ans, curr_d) while left < right: cnt[legs[left][1]] = cnt.get(legs[left][1], 0) + 1 left += 1 print(ans) ```
3
810
A
Straight <<A>>
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to *k*. The worst mark is 1, the best is *k*. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8. For instance, if Noora has marks [8,<=9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,<=8,<=9], Noora will have graduation certificate with 8. To graduate with «A» certificate, Noora has to have mark *k*. Noora got *n* marks in register this year. However, she is afraid that her marks are not enough to get final mark *k*. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to *k*. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to *k*.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack.
Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*.
[ "2 10\n8 9\n", "3 5\n4 4 4\n" ]
[ "4", "3" ]
Consider the first example testcase. Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1b961585522f76271546da990a6228e7c666277f.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Consequently, new final mark is 10. Less number of marks won't fix the situation. In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.
500
[ { "input": "2 10\n8 9", "output": "4" }, { "input": "3 5\n4 4 4", "output": "3" }, { "input": "3 10\n10 8 9", "output": "3" }, { "input": "2 23\n21 23", "output": "2" }, { "input": "5 10\n5 10 10 9 10", "output": "7" }, { "input": "12 50\n18 10 26 22 22 23 14 21 27 18 25 12", "output": "712" }, { "input": "38 12\n2 7 10 8 5 3 5 6 3 6 5 1 9 7 7 8 3 4 4 4 5 2 3 6 6 1 6 7 4 4 8 7 4 5 3 6 6 6", "output": "482" }, { "input": "63 86\n32 31 36 29 36 26 28 38 39 32 29 26 33 38 36 38 36 28 43 48 28 33 25 39 39 27 34 25 37 28 40 26 30 31 42 32 36 44 29 36 30 35 48 40 26 34 30 33 33 46 42 24 36 38 33 51 33 41 38 29 29 32 28", "output": "6469" }, { "input": "100 38\n30 24 38 31 31 33 32 32 29 34 29 22 27 23 34 25 32 30 30 26 16 27 38 33 38 38 37 34 32 27 33 23 33 32 24 24 30 36 29 30 33 30 29 30 36 33 33 35 28 24 30 32 38 29 30 36 31 30 27 38 31 36 15 37 32 27 29 24 38 33 28 29 34 21 37 35 32 31 27 25 27 28 31 31 36 38 35 35 36 29 35 22 38 31 38 28 31 27 34 31", "output": "1340" }, { "input": "33 69\n60 69 68 69 69 60 64 60 62 59 54 47 60 62 69 69 69 58 67 69 62 69 68 53 69 69 66 66 57 58 65 69 61", "output": "329" }, { "input": "39 92\n19 17 16 19 15 30 21 25 14 17 19 19 23 16 14 15 17 19 29 15 11 25 19 14 18 20 10 16 11 15 18 20 20 17 18 16 12 17 16", "output": "5753" }, { "input": "68 29\n29 29 29 29 29 28 29 29 29 27 29 29 29 29 29 29 29 23 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 22 29 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 29 29", "output": "0" }, { "input": "75 30\n22 18 21 26 23 18 28 30 24 24 19 25 28 30 23 29 18 23 23 30 26 30 17 30 18 19 25 26 26 15 27 23 30 21 19 26 25 30 25 28 20 22 22 21 26 17 23 23 24 15 25 19 18 22 30 30 29 21 30 28 28 30 27 25 24 15 22 19 30 21 20 30 18 20 25", "output": "851" }, { "input": "78 43\n2 7 6 5 5 6 4 5 3 4 6 8 4 5 5 4 3 1 2 4 4 6 5 6 4 4 6 4 8 4 6 5 6 1 4 5 6 3 2 5 2 5 3 4 8 8 3 3 4 4 6 6 5 4 5 5 7 9 3 9 6 4 7 3 6 9 6 5 1 7 2 5 6 3 6 2 5 4", "output": "5884" }, { "input": "82 88\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1", "output": "14170" }, { "input": "84 77\n28 26 36 38 37 44 48 34 40 22 42 35 40 37 30 31 33 35 36 55 47 36 33 47 40 38 27 38 36 33 35 31 47 33 30 38 38 47 49 24 38 37 28 43 39 36 34 33 29 38 36 43 48 38 36 34 33 34 35 31 26 33 39 37 37 37 35 52 47 30 24 46 38 26 43 46 41 50 33 40 36 41 37 30", "output": "6650" }, { "input": "94 80\n21 19 15 16 27 16 20 18 19 19 15 15 20 19 19 21 20 19 13 17 15 9 17 15 23 15 12 18 12 13 15 12 14 13 14 17 20 20 14 21 15 6 10 23 24 8 18 18 13 23 17 22 17 19 19 18 17 24 8 16 18 20 24 19 10 19 15 10 13 14 19 15 16 19 20 15 14 21 16 16 14 14 22 19 12 11 14 13 19 32 16 16 13 20", "output": "11786" }, { "input": "96 41\n13 32 27 34 28 34 30 26 21 24 29 20 25 34 25 16 27 15 22 22 34 22 25 19 23 17 17 22 26 24 23 20 21 27 19 33 13 24 22 18 30 30 27 14 26 24 20 20 22 11 19 31 19 29 18 28 30 22 17 15 28 32 17 24 17 24 24 19 26 23 22 29 18 22 23 29 19 32 26 23 22 22 24 23 27 30 24 25 21 21 33 19 35 27 34 28", "output": "3182" }, { "input": "1 26\n26", "output": "0" }, { "input": "99 39\n25 28 30 28 32 34 31 28 29 28 29 30 33 19 33 31 27 33 29 24 27 30 25 38 28 34 35 31 34 37 30 22 21 24 34 27 34 33 34 33 26 26 36 19 30 22 35 30 21 28 23 35 33 29 21 22 36 31 34 32 34 32 30 32 27 33 38 25 35 26 39 27 29 29 19 33 28 29 34 38 26 30 36 26 29 30 26 34 22 32 29 38 25 27 24 17 25 28 26", "output": "1807" }, { "input": "100 12\n7 6 6 3 5 5 9 8 7 7 4 7 12 6 9 5 6 3 4 7 9 10 7 7 5 3 9 6 9 9 6 7 4 10 4 8 8 6 9 8 6 5 7 4 10 7 5 6 8 9 3 4 8 5 4 8 6 10 5 8 7 5 9 8 5 8 5 6 9 11 4 9 5 5 11 4 6 6 7 3 8 9 6 7 10 4 7 6 9 4 8 11 5 4 10 8 5 10 11 4", "output": "946" }, { "input": "100 18\n1 2 2 2 2 2 1 1 1 2 3 1 3 1 1 4 2 4 1 2 1 2 1 3 2 1 2 1 1 1 2 1 2 2 1 1 4 3 1 1 2 1 3 3 2 1 2 2 1 1 1 1 3 1 1 2 2 1 1 1 5 1 2 1 3 2 2 1 4 2 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 1 1 3 1 1 2 1 1 2", "output": "3164" }, { "input": "100 27\n16 20 21 10 16 17 18 25 19 18 20 12 11 21 21 23 20 26 20 21 27 16 25 18 25 21 27 12 20 27 18 17 27 13 21 26 12 22 15 21 25 21 18 27 24 15 16 18 23 21 24 27 19 17 24 14 21 16 24 26 13 14 25 18 27 26 22 16 27 27 17 25 17 12 22 10 19 27 19 20 23 22 25 23 17 25 14 20 22 10 22 27 21 20 15 26 24 27 12 16", "output": "1262" }, { "input": "100 29\n20 18 23 24 14 14 16 23 22 17 18 22 21 21 19 19 14 11 18 19 16 22 25 20 14 13 21 24 18 16 18 29 17 25 12 10 18 28 11 16 17 14 15 20 17 20 18 22 10 16 16 20 18 19 29 18 25 27 17 19 24 15 24 25 16 23 19 16 16 20 19 15 12 21 20 13 21 15 15 23 16 23 17 13 17 21 13 18 17 18 18 20 16 12 19 15 27 14 11 18", "output": "2024" }, { "input": "100 30\n16 10 20 11 14 27 15 17 22 26 24 17 15 18 19 22 22 15 21 22 14 21 22 22 21 22 15 17 17 22 18 19 26 18 22 20 22 25 18 18 17 23 18 18 20 13 19 30 17 24 22 19 29 20 20 21 17 18 26 25 22 19 15 18 18 20 19 19 18 18 24 16 19 17 12 21 20 16 23 21 16 17 26 23 25 28 22 20 9 21 17 24 15 19 17 21 29 13 18 15", "output": "1984" }, { "input": "100 59\n56 58 53 59 59 48 59 54 46 59 59 58 48 59 55 59 59 50 59 56 59 59 59 59 59 59 59 57 59 53 45 53 50 59 50 55 58 54 59 56 54 59 59 59 59 48 56 59 59 57 59 59 48 43 55 57 39 59 46 55 55 52 58 57 51 59 59 59 59 53 59 43 51 54 46 59 57 43 50 59 47 58 59 59 59 55 46 56 55 59 56 47 56 56 46 51 47 48 59 55", "output": "740" }, { "input": "100 81\n6 7 6 6 7 6 6 6 3 9 4 5 4 3 4 6 6 6 1 3 9 5 2 3 8 5 6 9 6 6 6 5 4 4 7 7 3 6 11 7 6 4 8 7 12 6 4 10 2 4 9 11 7 4 7 7 8 8 6 7 9 8 4 5 8 13 6 6 6 8 6 2 5 6 7 5 4 4 4 4 2 6 4 8 3 4 7 7 6 7 7 10 5 10 6 7 4 11 8 4", "output": "14888" }, { "input": "100 100\n30 35 23 43 28 49 31 32 30 44 32 37 33 34 38 28 43 32 33 32 50 32 41 38 33 20 40 36 29 21 42 25 23 34 43 32 37 31 30 27 36 32 45 37 33 29 38 34 35 33 28 19 37 33 28 41 31 29 41 27 32 39 30 34 37 40 33 38 35 32 32 34 35 34 28 39 28 34 40 45 31 25 42 28 29 31 33 21 36 33 34 37 40 42 39 30 36 34 34 40", "output": "13118" }, { "input": "100 100\n71 87 100 85 89 98 90 90 71 65 76 75 85 100 81 100 91 80 73 89 86 78 82 89 77 92 78 90 100 81 85 89 73 100 66 60 72 88 91 73 93 76 88 81 86 78 83 77 74 93 97 94 85 78 82 78 91 91 100 78 89 76 78 82 81 78 83 88 87 83 78 98 85 97 98 89 88 75 76 86 74 81 70 76 86 84 99 100 89 94 72 84 82 88 83 89 78 99 87 76", "output": "3030" }, { "input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "19700" }, { "input": "100 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": "0" }, { "input": "100 100\n1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "19696" }, { "input": "100 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 99", "output": "0" }, { "input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 98 100 100 100 100 98 100 100 100 100 100 100 99 98 100 100 93 100 100 98 100 100 100 100 93 100 96 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 95 88 100 100 100 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": "0" }, { "input": "100 100\n95 100 100 100 100 100 100 100 100 100 100 100 100 100 87 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 90 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 96 100 98 100 100 100 100 100 96 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 100", "output": "2" }, { "input": "100 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", "output": "0" }, { "input": "100 2\n2 1 1 2 1 1 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 2 2 1 1 1 1 2 2 2 1 2 2 2 2 1 2 2 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 2 1 1 1 2 2 1 2 1 1 1 2 1 2 2 1 1 1 2 2 1 1 2 1 1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 2 1 1", "output": "16" }, { "input": "3 5\n5 5 5", "output": "0" }, { "input": "7 7\n1 1 1 1 1 1 1", "output": "77" }, { "input": "1 1\n1", "output": "0" }, { "input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "19700" }, { "input": "4 10\n10 10 10 10", "output": "0" }, { "input": "1 10\n10", "output": "0" }, { "input": "10 1\n1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "3 10\n10 10 10", "output": "0" }, { "input": "2 4\n3 4", "output": "0" }, { "input": "1 2\n2", "output": "0" }, { "input": "3 4\n4 4 4", "output": "0" }, { "input": "3 2\n2 2 1", "output": "0" }, { "input": "5 5\n5 5 5 5 5", "output": "0" }, { "input": "3 3\n3 3 3", "output": "0" }, { "input": "2 9\n8 9", "output": "0" }, { "input": "3 10\n9 10 10", "output": "0" }, { "input": "1 3\n3", "output": "0" }, { "input": "2 2\n1 2", "output": "0" }, { "input": "2 10\n10 10", "output": "0" }, { "input": "23 14\n7 11 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14", "output": "0" }, { "input": "2 10\n9 10", "output": "0" }, { "input": "2 2\n2 2", "output": "0" }, { "input": "10 5\n5 5 5 5 5 5 5 5 5 4", "output": "0" }, { "input": "3 5\n4 5 5", "output": "0" }, { "input": "5 4\n4 4 4 4 4", "output": "0" }, { "input": "2 10\n10 9", "output": "0" }, { "input": "4 5\n3 5 5 5", "output": "0" }, { "input": "10 5\n5 5 5 5 5 5 5 5 5 5", "output": "0" }, { "input": "3 10\n10 10 9", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "0" }, { "input": "2 1\n1 1", "output": "0" }, { "input": "4 10\n9 10 10 10", "output": "0" }, { "input": "5 2\n2 2 2 2 2", "output": "0" }, { "input": "2 5\n4 5", "output": "0" }, { "input": "5 10\n10 10 10 10 10", "output": "0" }, { "input": "2 6\n6 6", "output": "0" }, { "input": "2 9\n9 9", "output": "0" }, { "input": "3 10\n10 9 10", "output": "0" }, { "input": "4 40\n39 40 40 40", "output": "0" }, { "input": "3 4\n3 4 4", "output": "0" }, { "input": "9 9\n9 9 9 9 9 9 9 9 9", "output": "0" }, { "input": "1 4\n4", "output": "0" }, { "input": "4 7\n1 1 1 1", "output": "44" }, { "input": "1 5\n5", "output": "0" }, { "input": "3 1\n1 1 1", "output": "0" }, { "input": "1 100\n100", "output": "0" }, { "input": "2 7\n3 5", "output": "10" }, { "input": "3 6\n6 6 6", "output": "0" }, { "input": "4 2\n1 2 2 2", "output": "0" }, { "input": "4 5\n4 5 5 5", "output": "0" }, { "input": "5 5\n1 1 1 1 1", "output": "35" }, { "input": "66 2\n1 2 2 2 2 1 1 2 1 2 2 2 2 2 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 2 1 2 2 1 1 2 1 2 2 1 1 1 2 1 2 1 2 1 2 1 2 2 2 2 1 2 2 1 2 1 1 1 2 2 1", "output": "0" }, { "input": "2 2\n2 1", "output": "0" }, { "input": "5 5\n5 5 5 4 5", "output": "0" }, { "input": "3 7\n1 1 1", "output": "33" }, { "input": "2 5\n5 5", "output": "0" }, { "input": "1 7\n1", "output": "11" }, { "input": "6 7\n1 1 1 1 1 1", "output": "66" }, { "input": "99 97\n15 80 78 69 12 84 36 51 89 77 88 10 1 19 67 85 6 36 8 70 14 45 88 97 22 13 75 57 83 27 13 97 9 90 68 51 76 37 5 2 16 92 11 48 13 77 35 19 15 74 22 29 21 12 28 42 56 5 32 41 62 75 71 71 68 72 24 77 11 28 78 27 53 88 74 66 1 42 18 16 18 39 75 38 81 5 13 39 40 75 13 36 53 83 9 54 57 63 64", "output": "10077" }, { "input": "8 7\n1 1 1 1 1 1 1 1", "output": "88" }, { "input": "3 2\n2 2 2", "output": "0" }, { "input": "6 5\n5 5 5 5 5 5", "output": "0" }, { "input": "10 5\n5 5 5 5 5 5 5 4 1 1", "output": "8" }, { "input": "1 5\n1", "output": "7" }, { "input": "10 10\n10 10 10 10 10 10 10 10 10 10", "output": "0" }, { "input": "2 3\n2 3", "output": "0" }, { "input": "1 9\n9", "output": "0" }, { "input": "74 2\n2 2 2 2 1 2 2 1 1 1 2 2 1 2 2 2 2 1 2 1 1 1 2 1 1 2 2 1 2 1 1 2 1 1 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 1 1 2 1 1 1 1 1 1 2 2 2 1 1 1 1 1 2 2 2 2 2 2 1 2", "output": "0" }, { "input": "5 5\n5 5 5 5 4", "output": "0" } ]
1,495,523,510
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
62
0
import math n,k=map(int,input().split()) marks=list(map(int,input().split())) count=0 for j in marks: count+=j avg=count/n if math.floor(avg+1/2)==k: print(0) else: num=1 while(math.floor(avg+1/2)!=k): avg=(avg*(n+num-1)+k)/(n+num) num+=1 print(num-1)
Title: Straight <<A>> Time Limit: None seconds Memory Limit: None megabytes Problem Description: Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to *k*. The worst mark is 1, the best is *k*. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8. For instance, if Noora has marks [8,<=9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,<=8,<=9], Noora will have graduation certificate with 8. To graduate with «A» certificate, Noora has to have mark *k*. Noora got *n* marks in register this year. However, she is afraid that her marks are not enough to get final mark *k*. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to *k*. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to *k*. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack. Output Specification: Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. Demo Input: ['2 10\n8 9\n', '3 5\n4 4 4\n'] Demo Output: ['4', '3'] Note: Consider the first example testcase. Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1b961585522f76271546da990a6228e7c666277f.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Consequently, new final mark is 10. Less number of marks won't fix the situation. In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.
```python import math n,k=map(int,input().split()) marks=list(map(int,input().split())) count=0 for j in marks: count+=j avg=count/n if math.floor(avg+1/2)==k: print(0) else: num=1 while(math.floor(avg+1/2)!=k): avg=(avg*(n+num-1)+k)/(n+num) num+=1 print(num-1) ```
0
7
B
Memory Manager
PROGRAMMING
1,600
[ "implementation" ]
B. Memory Manager
1
64
There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations: - alloc n — to allocate *n* bytes of the memory and return the allocated block's identifier *x*; - erase x — to erase the block with the identifier *x*; - defragment — to defragment the free memory, bringing all the blocks as close to the beginning of the memory as possible and preserving their respective order; The memory model in this case is very simple. It is a sequence of *m* bytes, numbered for convenience from the first to the *m*-th. The first operation alloc n takes as the only parameter the size of the memory block that is to be allocated. While processing this operation, a free block of *n* successive bytes is being allocated in the memory. If the amount of such blocks is more than one, the block closest to the beginning of the memory (i.e. to the first byte) is prefered. All these bytes are marked as not free, and the memory manager returns a 32-bit integer numerical token that is the identifier of this block. If it is impossible to allocate a free block of this size, the function returns NULL. The second operation erase x takes as its parameter the identifier of some block. This operation frees the system memory, marking the bytes of this block as free for further use. In the case when this identifier does not point to the previously allocated block, which has not been erased yet, the function returns ILLEGAL_ERASE_ARGUMENT. The last operation defragment does not have any arguments and simply brings the occupied memory sections closer to the beginning of the memory without changing their respective order. In the current implementation you are to use successive integers, starting with 1, as identifiers. Each successful alloc operation procession should return following number. Unsuccessful alloc operations do not affect numeration. You are to write the implementation of the memory manager. You should output the returned value for each alloc command. You should also output ILLEGAL_ERASE_ARGUMENT for all the failed erase commands.
The first line of the input data contains two positive integers *t* and *m* (1<=≤<=*t*<=≤<=100;1<=≤<=*m*<=≤<=100), where *t* — the amount of operations given to the memory manager for processing, and *m* — the available memory size in bytes. Then there follow *t* lines where the operations themselves are given. The first operation is alloc n (1<=≤<=*n*<=≤<=100), where *n* is an integer. The second one is erase x, where *x* is an arbitrary 32-bit integer numerical token. The third operation is defragment.
Output the sequence of lines. Each line should contain either the result of alloc operation procession , or ILLEGAL_ERASE_ARGUMENT as a result of failed erase operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of alloc operation should return integers, starting with 1, as the identifiers of the allocated blocks.
[ "6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n" ]
[ "1\n2\nNULL\n3\n" ]
none
0
[ { "input": "6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6", "output": "1\n2\nNULL\n3" }, { "input": "6 1\ndefragment\nalloc 10\nalloc 1\nerase -1\nerase 1\nerase 1", "output": "NULL\n1\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT" }, { "input": "14 100\nalloc 99\nalloc 1\nalloc 1\nerase 2\nalloc 1\nerase 4\nerase 1\nalloc 100\nalloc 1\nalloc 99\ndefragment\nerase 4\nalloc 100\nalloc 99", "output": "1\n2\nNULL\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\n4\nNULL\nNULL\nNULL" }, { "input": "26 25\ndefragment\nerase 1\nerase -1560200883\nalloc 44\ndefragment\nalloc 75\nalloc 22\ndefragment\nerase 4\ndefragment\nalloc 57\nalloc 53\nerase 4\nerase -1639632026\nerase -2121605039\nerase 3\nalloc 51\nalloc 65\ndefragment\nerase 2\nerase 4\nalloc 52\nerase 3\ndefragment\nerase -1842529282\nerase 3", "output": "ILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\n1\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT" }, { "input": "22 9\nerase 1\nalloc 6\nalloc 65\nerase 1\nalloc 87\nerase -1638927047\nalloc 5\nerase 2\nalloc 70\ndefragment\nalloc 20\nalloc 48\nerase -69401977\nalloc 20\ndefragment\nerase 7\ndefragment\nerase 9\nerase 7\nerase 4\ndefragment\nalloc 66", "output": "ILLEGAL_ERASE_ARGUMENT\n1\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\n2\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL" }, { "input": "12 40\nerase 1\nalloc 21\nalloc 5\nalloc 7\ndefragment\ndefragment\nerase 2\nalloc 83\nerase 4\ndefragment\nalloc 59\ndefragment", "output": "ILLEGAL_ERASE_ARGUMENT\n1\n2\n3\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL" }, { "input": "38 18\nalloc 72\nerase 2\nalloc 50\ndefragment\nerase 3\ndefragment\nalloc 43\nalloc 41\ndefragment\ndefragment\nalloc 26\nalloc 46\nalloc 16\nalloc 15\ndefragment\ndefragment\nalloc 95\nerase 7\nerase 7\nerase 5\nerase 2\nerase 9\nerase 7\nalloc 43\ndefragment\nerase 7\ndefragment\nalloc 48\nalloc 77\nerase 10\nerase 11\nalloc 16\nalloc 84\nerase 1\ndefragment\nalloc 86\ndefragment\nerase 13", "output": "NULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nNULL\n1\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT" }, { "input": "37 74\nalloc 11\ndefragment\nerase 1\ndefragment\nerase 2\ndefragment\nalloc 90\nerase 3\nerase 2\nerase 3\nerase 1\nerase 1\nalloc 38\nalloc 19\nerase 1\nerase 3\ndefragment\nalloc 93\nerase 5\nerase 4\nalloc 66\nalloc 71\nerase 5\ndefragment\ndefragment\ndefragment\ndefragment\nerase 7\nalloc 47\nerase -95616683\nerase 2\nalloc 28\nalloc 32\nerase 11\nalloc 50\ndefragment\ndefragment", "output": "1\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n2\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\n4\n5\nILLEGAL_ERASE_ARGUMENT\nNULL" }, { "input": "16 49\nerase -751005193\ndefragment\nalloc 37\nalloc 82\nerase 3\nerase 1\nalloc 80\nalloc 51\ndefragment\nalloc 74\nerase 1\nalloc 91\ndefragment\ndefragment\nalloc 98\ndefragment", "output": "ILLEGAL_ERASE_ARGUMENT\n1\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL" }, { "input": "42 98\ndefragment\ndefragment\ndefragment\ndefragment\ndefragment\nalloc 5\nalloc 66\ndefragment\nerase 3\nalloc 53\ndefragment\nerase 4\nerase 2\nalloc 70\nerase 3\ndefragment\ndefragment\nerase 2\nerase 3\nerase -1327931832\nalloc 93\nalloc 64\nerase 7\nerase 6\nerase 3\nalloc 61\nalloc 12\nalloc 65\nerase 2\nalloc 46\nerase 11\nerase 9\nerase 9\nerase 6\nalloc 2\nalloc 78\ndefragment\nerase 13\nerase 6\nerase 10\nalloc 53\nalloc 46", "output": "1\n2\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\n3\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n4\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL" }, { "input": "19 46\nalloc 21\nerase 2\nerase 1\ndefragment\nalloc 4\ndefragment\ndefragment\nalloc 40\nerase 1\ndefragment\ndefragment\nalloc 68\nerase -388966015\nalloc 85\nalloc 53\nerase 4\ndefragment\nalloc 49\nalloc 88", "output": "1\nILLEGAL_ERASE_ARGUMENT\n2\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL" }, { "input": "44 46\nalloc 28\nalloc 36\ndefragment\nerase -937404236\nalloc 71\ndefragment\nalloc 81\nalloc 51\nerase 3\ndefragment\nalloc 48\nerase 1\ndefragment\nalloc 36\ndefragment\ndefragment\nerase 1\ndefragment\ndefragment\nerase -1173350787\nalloc 94\nerase 5\ndefragment\nerase 9\nalloc 98\nerase 7\ndefragment\nerase 5\nerase 1\ndefragment\nerase 2\ndefragment\nerase 4\ndefragment\nerase 9\nalloc 8\ndefragment\nerase 9\ndefragment\ndefragment\ndefragment\nerase 1\nalloc 70\nerase 9", "output": "1\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\n2\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n3\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT" }, { "input": "47 43\nerase 1\nalloc 95\nalloc 53\nerase 2\ndefragment\nalloc 100\nerase 4\nerase 2\nerase -849472053\ndefragment\nerase -638355221\nalloc 90\nerase 3\nerase 2\ndefragment\nalloc 17\nerase 5\ndefragment\nerase 6\ndefragment\nerase 3\ndefragment\ndefragment\nalloc 99\nalloc 69\nalloc 80\nerase 9\nerase 5\ndefragment\nerase 7\ndefragment\nalloc 93\ndefragment\ndefragment\nalloc 25\ndefragment\nalloc 14\nerase 8\nerase 4\ndefragment\ndefragment\nalloc 96\nerase 9\nalloc 63\nerase 8\ndefragment\nerase 10", "output": "ILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n1\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\n2\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL..." }, { "input": "26 25\nalloc 25\nerase 1\nalloc 24\nerase 2\nalloc 23\nerase 3\nalloc 24\nerase 4\nalloc 24\nerase 5\nalloc 21\nerase 6\nalloc 24\nerase 7\nalloc 25\nerase 8\nalloc 25\nerase 9\nalloc 24\nerase 10\nalloc 25\nerase 11\nalloc 25\nerase 12\nalloc 25\nerase 13", "output": "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13" }, { "input": "22 9\nalloc 9\nerase 1\nalloc 9\nerase 2\nalloc 9\nerase 3\nalloc 9\nerase 4\nalloc 9\nerase 5\nalloc 9\nerase 6\nalloc 9\nerase 7\nalloc 9\nerase 8\nalloc 9\nerase 9\nalloc 9\nerase 10\nalloc 9\nerase 11", "output": "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11" }, { "input": "7 6\nalloc 1\nalloc 2\nalloc 3\nerase 1\ndefragment\nerase 3\nalloc 4", "output": "1\n2\n3\n4" }, { "input": "3 1\nerase -1\nerase 0\nerase -2147483648", "output": "ILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT" }, { "input": "7 100\nalloc 100\nerase 2147483647\nerase 1\nalloc 50\nalloc 50\nerase 3\nerase -2147483648", "output": "1\nILLEGAL_ERASE_ARGUMENT\n2\n3\nILLEGAL_ERASE_ARGUMENT" }, { "input": "12 10\nalloc 6\nalloc 2\nerase 1\nalloc 4\nalloc 2\nerase 3\nalloc 2\nalloc 3\nalloc 1\nalloc 1\nalloc 1\nalloc 1", "output": "1\n2\n3\n4\n5\nNULL\n6\n7\n8\n9" }, { "input": "8 50\nalloc 51\ndefragment\nalloc 100\ndefragment\nerase 1\nalloc 50\ndefragment\nalloc 50", "output": "NULL\nNULL\nILLEGAL_ERASE_ARGUMENT\n1\nNULL" }, { "input": "10 10\nalloc 10\nerase -1\nerase 1\nalloc 5\nerase -1\nalloc 5\nerase 0\nalloc 5\nerase 0\nalloc 5", "output": "1\nILLEGAL_ERASE_ARGUMENT\n2\nILLEGAL_ERASE_ARGUMENT\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL" }, { "input": "16 10\nalloc 10\ndefragment\ndefragment\ndefragment\nalloc 10\nerase 1\nerase 2\nalloc 6\ndefragment\ndefragment\nalloc 4\ndefragment\ndefragment\nerase 3\ndefragment\nalloc 6", "output": "1\nNULL\nILLEGAL_ERASE_ARGUMENT\n2\n3\nNULL" }, { "input": "16 10\nalloc 10\ndefragment\ndefragment\ndefragment\nalloc 10\nerase 1\nerase 2\nalloc 6\ndefragment\ndefragment\nalloc 4\ndefragment\ndefragment\nerase 2\ndefragment\nalloc 6", "output": "1\nNULL\nILLEGAL_ERASE_ARGUMENT\n2\n3\n4" } ]
1,641,422,376
2,147,483,647
Python 3
OK
TESTS
48
92
0
# Codeforces Beta Round #7 # B. Memory Manager t, m = map(int, input().split()) # Store memory as a string, where 0 means free and 1 means occupied. This # allows us to search for free memory by finding the first index of "00..0" mem = "0" * m alloc_counter = 0 # Map of index -> (start, size) of used memory blocks blocks = {} for _ in range(t): command = input().split() if command[0] == "alloc": size = int(command[1]) # Try to find a free block, if it doesn't exist, continue if "0" * size not in mem: print("NULL") continue # Find the index, and set the block to all 1's start = mem.find("0" * size) mem = mem[:start] + "1" * size + mem[size + start:] # Update the list of blocks alloc_counter += 1 blocks[alloc_counter] = (start, size) print(alloc_counter) elif command[0] == "erase": index = int(command[1]) # If the index doesn't exist, continue if index not in blocks: print("ILLEGAL_ERASE_ARGUMENT") continue # Erase the block and fill the memory with 0's start, size = blocks[index] del blocks[index] mem = mem[:start] + "0" * size + mem[size + start:] else: # First store blocks as (start, size, index), and sort by start new_blocks = sorted([ (blocks[index][0], blocks[index][1], index) for index in blocks ]) # Compress them, then update blocks and memory compressed = {} p = 0 for start, size, index in new_blocks: compressed[index] = (p, size) p += size blocks = compressed mem = "1" * p + "0" * (m - p)
Title: Memory Manager Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations: - alloc n — to allocate *n* bytes of the memory and return the allocated block's identifier *x*; - erase x — to erase the block with the identifier *x*; - defragment — to defragment the free memory, bringing all the blocks as close to the beginning of the memory as possible and preserving their respective order; The memory model in this case is very simple. It is a sequence of *m* bytes, numbered for convenience from the first to the *m*-th. The first operation alloc n takes as the only parameter the size of the memory block that is to be allocated. While processing this operation, a free block of *n* successive bytes is being allocated in the memory. If the amount of such blocks is more than one, the block closest to the beginning of the memory (i.e. to the first byte) is prefered. All these bytes are marked as not free, and the memory manager returns a 32-bit integer numerical token that is the identifier of this block. If it is impossible to allocate a free block of this size, the function returns NULL. The second operation erase x takes as its parameter the identifier of some block. This operation frees the system memory, marking the bytes of this block as free for further use. In the case when this identifier does not point to the previously allocated block, which has not been erased yet, the function returns ILLEGAL_ERASE_ARGUMENT. The last operation defragment does not have any arguments and simply brings the occupied memory sections closer to the beginning of the memory without changing their respective order. In the current implementation you are to use successive integers, starting with 1, as identifiers. Each successful alloc operation procession should return following number. Unsuccessful alloc operations do not affect numeration. You are to write the implementation of the memory manager. You should output the returned value for each alloc command. You should also output ILLEGAL_ERASE_ARGUMENT for all the failed erase commands. Input Specification: The first line of the input data contains two positive integers *t* and *m* (1<=≤<=*t*<=≤<=100;1<=≤<=*m*<=≤<=100), where *t* — the amount of operations given to the memory manager for processing, and *m* — the available memory size in bytes. Then there follow *t* lines where the operations themselves are given. The first operation is alloc n (1<=≤<=*n*<=≤<=100), where *n* is an integer. The second one is erase x, where *x* is an arbitrary 32-bit integer numerical token. The third operation is defragment. Output Specification: Output the sequence of lines. Each line should contain either the result of alloc operation procession , or ILLEGAL_ERASE_ARGUMENT as a result of failed erase operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of alloc operation should return integers, starting with 1, as the identifiers of the allocated blocks. Demo Input: ['6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n'] Demo Output: ['1\n2\nNULL\n3\n'] Note: none
```python # Codeforces Beta Round #7 # B. Memory Manager t, m = map(int, input().split()) # Store memory as a string, where 0 means free and 1 means occupied. This # allows us to search for free memory by finding the first index of "00..0" mem = "0" * m alloc_counter = 0 # Map of index -> (start, size) of used memory blocks blocks = {} for _ in range(t): command = input().split() if command[0] == "alloc": size = int(command[1]) # Try to find a free block, if it doesn't exist, continue if "0" * size not in mem: print("NULL") continue # Find the index, and set the block to all 1's start = mem.find("0" * size) mem = mem[:start] + "1" * size + mem[size + start:] # Update the list of blocks alloc_counter += 1 blocks[alloc_counter] = (start, size) print(alloc_counter) elif command[0] == "erase": index = int(command[1]) # If the index doesn't exist, continue if index not in blocks: print("ILLEGAL_ERASE_ARGUMENT") continue # Erase the block and fill the memory with 0's start, size = blocks[index] del blocks[index] mem = mem[:start] + "0" * size + mem[size + start:] else: # First store blocks as (start, size, index), and sort by start new_blocks = sorted([ (blocks[index][0], blocks[index][1], index) for index in blocks ]) # Compress them, then update blocks and memory compressed = {} p = 0 for start, size, index in new_blocks: compressed[index] = (p, size) p += size blocks = compressed mem = "1" * p + "0" * (m - p) ```
3.954
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "6" }, { "input": "5 1\n998 997 985 937 998", "output": "0" }, { "input": "2 2\n-742 -187", "output": "929" }, { "input": "3 3\n522 597 384", "output": "0" }, { "input": "4 2\n-215 -620 192 647", "output": "835" }, { "input": "10 6\n557 605 685 231 910 633 130 838 -564 -85", "output": "649" }, { "input": "20 14\n932 442 960 943 624 624 955 998 631 910 850 517 715 123 1000 155 -10 961 966 59", "output": "10" }, { "input": "30 5\n991 997 996 967 977 999 991 986 1000 965 984 997 998 1000 958 983 974 1000 991 999 1000 978 961 992 990 998 998 978 998 1000", "output": "0" }, { "input": "50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -799 -886", "output": "19441" }, { "input": "88 64\n999 999 1000 1000 999 996 995 1000 1000 999 1000 997 998 1000 999 1000 997 1000 993 998 994 999 998 996 1000 997 1000 1000 1000 997 1000 998 997 1000 1000 998 1000 998 999 1000 996 999 999 999 996 995 999 1000 998 999 1000 999 999 1000 1000 1000 996 1000 1000 1000 997 1000 1000 997 999 1000 1000 1000 1000 1000 999 999 1000 1000 996 999 1000 1000 995 999 1000 996 1000 998 999 999 1000 999", "output": "0" }, { "input": "99 17\n-993 -994 -959 -989 -991 -995 -976 -997 -990 -1000 -996 -994 -999 -995 -1000 -983 -979 -1000 -989 -968 -994 -992 -962 -993 -999 -983 -991 -979 -995 -993 -973 -999 -995 -995 -999 -993 -995 -992 -947 -1000 -999 -998 -982 -988 -979 -993 -963 -988 -980 -990 -979 -976 -995 -999 -981 -988 -998 -999 -970 -1000 -983 -994 -943 -975 -998 -977 -973 -997 -959 -999 -983 -985 -950 -977 -977 -991 -998 -973 -987 -985 -985 -986 -984 -994 -978 -998 -989 -989 -988 -970 -985 -974 -997 -981 -962 -972 -995 -988 -993", "output": "16984" }, { "input": "100 37\n205 19 -501 404 912 -435 -322 -469 -655 880 -804 -470 793 312 -108 586 -642 -928 906 605 -353 -800 745 -440 -207 752 -50 -28 498 -800 -62 -195 602 -833 489 352 536 404 -775 23 145 -512 524 759 651 -461 -427 -557 684 -366 62 592 -563 -811 64 418 -881 -308 591 -318 -145 -261 -321 -216 -18 595 -202 960 -4 219 226 -238 -882 -963 425 970 -434 -160 243 -672 -4 873 8 -633 904 -298 -151 -377 -61 -72 -677 -66 197 -716 3 -870 -30 152 -469 981", "output": "21743" }, { "input": "100 99\n-931 -806 -830 -828 -916 -962 -660 -867 -952 -966 -820 -906 -724 -982 -680 -717 -488 -741 -897 -613 -986 -797 -964 -939 -808 -932 -810 -860 -641 -916 -858 -628 -821 -929 -917 -976 -664 -985 -778 -665 -624 -928 -940 -958 -884 -757 -878 -896 -634 -526 -514 -873 -990 -919 -988 -878 -650 -973 -774 -783 -733 -648 -756 -895 -833 -974 -832 -725 -841 -748 -806 -613 -924 -867 -881 -943 -864 -991 -809 -926 -777 -817 -998 -682 -910 -996 -241 -722 -964 -904 -821 -920 -835 -699 -805 -632 -779 -317 -915 -654", "output": "81283" }, { "input": "100 14\n995 994 745 684 510 737 984 690 979 977 542 933 871 603 758 653 962 997 747 974 773 766 975 770 527 960 841 989 963 865 974 967 950 984 757 685 986 809 982 959 931 880 978 867 805 562 970 900 834 782 616 885 910 608 974 918 576 700 871 980 656 941 978 759 767 840 573 859 841 928 693 853 716 927 976 851 962 962 627 797 707 873 869 988 993 533 665 887 962 880 929 980 877 887 572 790 721 883 848 782", "output": "0" }, { "input": "100 84\n768 946 998 752 931 912 826 1000 991 910 875 962 901 952 958 733 959 908 872 840 923 826 952 980 974 980 947 955 959 822 997 963 966 933 829 923 971 999 926 932 865 984 974 858 994 855 949 941 992 861 951 949 991 711 763 728 935 485 716 907 869 952 960 859 909 963 978 942 968 933 923 909 997 962 687 764 924 774 875 1000 961 951 987 974 848 921 966 859 995 997 974 931 886 941 974 986 906 978 998 823", "output": "0" }, { "input": "100 80\n-795 -994 -833 -930 -974 -980 -950 -940 -788 -927 -583 -956 -945 -949 -809 -974 -957 -736 -967 -908 -975 -961 -986 -983 -963 -771 -952 -847 -751 -741 -982 -959 -925 -931 -839 -937 -880 -914 -858 -998 -812 -911 -862 -965 -943 -984 -738 -920 -950 -998 -909 -998 -781 -901 -677 -940 -985 -951 -675 -952 -967 -949 -882 -641 -969 -937 -975 -993 -913 -941 -807 -851 -832 -960 -939 -943 -895 -929 -528 -880 -823 -930 -888 -862 -948 -966 -962 -857 -799 -969 -833 -998 -952 -878 -946 -971 -976 -974 -723 -992", "output": "75068" }, { "input": "1 1\n0", "output": "0" }, { "input": "1 1\n1", "output": "0" }, { "input": "1 1\n555", "output": "0" }, { "input": "1 1\n-1", "output": "1" }, { "input": "1 1\n-24", "output": "24" } ]
1,689,443,388
2,147,483,647
PyPy 3-64
OK
TESTS
25
154
0
import math def readint(): return int(input()) def readarray(typ): return list(map(typ, input().split())) n, m = readarray(int) tvs = readarray(int) tvs.sort() i = 0 bellar = 0 while m > 0 and tvs[i] < 0: bellar -= tvs[i] i += 1 m -= 1 print(bellar)
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. Input Specification: The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. Output Specification: Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. Demo Input: ['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n'] Demo Output: ['8\n', '7\n'] Note: none
```python import math def readint(): return int(input()) def readarray(typ): return list(map(typ, input().split())) n, m = readarray(int) tvs = readarray(int) tvs.sort() i = 0 bellar = 0 while m > 0 and tvs[i] < 0: bellar -= tvs[i] i += 1 m -= 1 print(bellar) ```
3.9615
476
A
Dreamoon and Stairs
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*. What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition?
The single line contains two space separated integers *n*, *m* (0<=&lt;<=*n*<=≤<=10000,<=1<=&lt;<=*m*<=≤<=10).
Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead.
[ "10 2\n", "3 5\n" ]
[ "6\n", "-1\n" ]
For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}. For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5.
500
[ { "input": "10 2", "output": "6" }, { "input": "3 5", "output": "-1" }, { "input": "29 7", "output": "21" }, { "input": "2 2", "output": "2" }, { "input": "1 2", "output": "-1" }, { "input": "10000 2", "output": "5000" }, { "input": "10000 3", "output": "5001" }, { "input": "10000 10", "output": "5000" }, { "input": "9999 3", "output": "5001" }, { "input": "9999 2", "output": "5000" }, { "input": "9999 10", "output": "5000" }, { "input": "9999 9", "output": "5004" }, { "input": "18 10", "output": "10" }, { "input": "19 10", "output": "10" }, { "input": "20 10", "output": "10" }, { "input": "21 10", "output": "20" }, { "input": "7688 5", "output": "3845" }, { "input": "4608 5", "output": "2305" }, { "input": "3979 2", "output": "1990" }, { "input": "9985 6", "output": "4998" }, { "input": "3230 8", "output": "1616" }, { "input": "24 9", "output": "18" }, { "input": "3275 8", "output": "1640" }, { "input": "6240 7", "output": "3122" }, { "input": "5227 4", "output": "2616" }, { "input": "3832 6", "output": "1920" }, { "input": "4 2", "output": "2" }, { "input": "6 3", "output": "3" }, { "input": "10 5", "output": "5" }, { "input": "3 2", "output": "2" }, { "input": "6 4", "output": "4" }, { "input": "5 2", "output": "4" }, { "input": "8 2", "output": "4" }, { "input": "9 9", "output": "9" }, { "input": "4 5", "output": "-1" } ]
1,694,937,250
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
62
0
n, m = map(int, input().split()) # n = number of steps # can climb 1 or 2 steps each move # m = number of moves to be a multiple of # The minimal number of moves, being a multiple of m. min_steps = n // 2 + n % 2 max_steps = n closest_multiple = ((min_steps + m - 1) // m) * m found = False if min_steps < closest_multiple < max_steps: print(closest_multiple) else: print(-1)
Title: Dreamoon and Stairs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*. What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? Input Specification: The single line contains two space separated integers *n*, *m* (0<=&lt;<=*n*<=≤<=10000,<=1<=&lt;<=*m*<=≤<=10). Output Specification: Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead. Demo Input: ['10 2\n', '3 5\n'] Demo Output: ['6\n', '-1\n'] Note: For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}. For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5.
```python n, m = map(int, input().split()) # n = number of steps # can climb 1 or 2 steps each move # m = number of moves to be a multiple of # The minimal number of moves, being a multiple of m. min_steps = n // 2 + n % 2 max_steps = n closest_multiple = ((min_steps + m - 1) // m) * m found = False if min_steps < closest_multiple < max_steps: print(closest_multiple) else: print(-1) ```
0
465
B
Inbox (100500)
PROGRAMMING
1,000
[ "implementation" ]
null
null
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread. Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: - Move from the list of letters to the content of any single letter.- Return to the list of letters from single letter viewing mode.- In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one. The program cannot delete the letters from the list or rearrange them. Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox. The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read.
Print a single number — the minimum number of operations needed to make all the letters read.
[ "5\n0 1 0 1 0\n", "5\n1 1 0 0 1\n", "2\n0 0\n" ]
[ "3\n", "4\n", "0\n" ]
In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one. In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter. In the third sample all letters are already read.
1,000
[ { "input": "5\n0 1 0 1 0", "output": "3" }, { "input": "5\n1 1 0 0 1", "output": "4" }, { "input": "2\n0 0", "output": "0" }, { "input": "9\n1 0 1 0 1 0 1 0 1", "output": "9" }, { "input": "5\n1 1 1 1 1", "output": "5" }, { "input": "14\n0 0 1 1 1 0 1 1 1 0 1 1 1 0", "output": "11" }, { "input": "23\n1 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1", "output": "23" }, { "input": "27\n0 1 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", "output": "25" }, { "input": "10\n1 0 0 0 0 1 0 0 0 1", "output": "5" }, { "input": "10\n1 0 0 1 0 0 1 1 0 1", "output": "8" }, { "input": "27\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", "output": "0" }, { "input": "39\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1", "output": "39" }, { "input": "48\n1 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1", "output": "39" }, { "input": "71\n0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0", "output": "59" }, { "input": "99\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1", "output": "99" }, { "input": "99\n1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1", "output": "99" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100" }, { "input": "100\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 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "99" }, { "input": "193\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "1" }, { "input": "213\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 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 1 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "5" }, { "input": "2\n1 0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "1\n0", "output": "0" }, { "input": "5\n0 0 0 0 1", "output": "1" }, { "input": "12\n0 1 1 0 1 1 0 1 1 0 0 0", "output": "8" }, { "input": "3\n1 0 0", "output": "1" }, { "input": "5\n0 0 1 0 0", "output": "1" }, { "input": "3\n0 1 0", "output": "1" }, { "input": "6\n1 1 0 0 0 0", "output": "2" }, { "input": "4\n0 1 0 0", "output": "1" }, { "input": "5\n1 1 1 0 0", "output": "3" }, { "input": "4\n1 0 0 0", "output": "1" }, { "input": "6\n1 1 1 1 0 0", "output": "4" } ]
1,679,772,709
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
n = int(input()) letters = input().split() n = n + 1 x = 0 letters_list = [int(n) for n in letters] for n in letters_list: if n == 0: x += 1 print(x)
Title: Inbox (100500) Time Limit: None seconds Memory Limit: None megabytes Problem Description: Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread. Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: - Move from the list of letters to the content of any single letter.- Return to the list of letters from single letter viewing mode.- In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one. The program cannot delete the letters from the list or rearrange them. Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox. The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read. Output Specification: Print a single number — the minimum number of operations needed to make all the letters read. Demo Input: ['5\n0 1 0 1 0\n', '5\n1 1 0 0 1\n', '2\n0 0\n'] Demo Output: ['3\n', '4\n', '0\n'] Note: In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one. In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter. In the third sample all letters are already read.
```python n = int(input()) letters = input().split() n = n + 1 x = 0 letters_list = [int(n) for n in letters] for n in letters_list: if n == 0: x += 1 print(x) ```
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,693,512,248
2,147,483,647
Python 3
OK
TESTS
20
31
0
n= int(input()) for i in range(n): # TODO: write code... word = input() if(len(word)>10): print(word[0],(len(word)-2),word[len(word)-1],sep="") else: print(word)
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()) for i in range(n): # TODO: write code... word = input() if(len(word)>10): print(word[0],(len(word)-2),word[len(word)-1],sep="") else: print(word) ```
3.9845
776
A
A Serial Killer
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern.
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days. Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters.
Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
[ "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n", "icm codeforces\n1\ncodeforces technex\n" ]
[ "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n", "icm codeforces\nicm technex\n" ]
In first example, the killer starts with ross and rachel. - After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
500
[ { "input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler" }, { "input": "icm codeforces\n1\ncodeforces technex", "output": "icm codeforces\nicm technex" }, { "input": "a b\n3\na c\nb d\nd e", "output": "a b\nc b\nc d\nc e" }, { "input": "ze udggmyop\n4\nze szhrbmft\nudggmyop mjorab\nszhrbmft ojdtfnzxj\nojdtfnzxj yjlkg", "output": "ze udggmyop\nszhrbmft udggmyop\nszhrbmft mjorab\nojdtfnzxj mjorab\nyjlkg mjorab" }, { "input": "q s\n10\nq b\nb j\ns g\nj f\nf m\ng c\nc a\nm d\nd z\nz o", "output": "q s\nb s\nj s\nj g\nf g\nm g\nm c\nm a\nd a\nz a\no a" }, { "input": "iii iiiiii\n7\niii iiiiiiiiii\niiiiiiiiii iiii\niiii i\niiiiii iiiiiiii\niiiiiiii iiiiiiiii\ni iiiii\niiiii ii", "output": "iii iiiiii\niiiiiiiiii iiiiii\niiii iiiiii\ni iiiiii\ni iiiiiiii\ni iiiiiiiii\niiiii iiiiiiiii\nii iiiiiiiii" }, { "input": "bwyplnjn zkms\n26\nzkms nzmcsytxh\nnzmcsytxh yujsb\nbwyplnjn gtbzhudpb\ngtbzhudpb hpk\nyujsb xvy\nhpk wrwnfokml\nwrwnfokml ndouuikw\nndouuikw ucgrja\nucgrja tgfmpldz\nxvy nycrfphn\nnycrfphn quvs\nquvs htdy\nhtdy k\ntgfmpldz xtdpkxm\nxtdpkxm suwqxs\nk fv\nsuwqxs qckllwy\nqckllwy diun\nfv lefa\nlefa gdoqjysx\ndiun dhpz\ngdoqjysx bdmqdyt\ndhpz dgz\ndgz v\nbdmqdyt aswy\naswy ydkayhlrnm", "output": "bwyplnjn zkms\nbwyplnjn nzmcsytxh\nbwyplnjn yujsb\ngtbzhudpb yujsb\nhpk yujsb\nhpk xvy\nwrwnfokml xvy\nndouuikw xvy\nucgrja xvy\ntgfmpldz xvy\ntgfmpldz nycrfphn\ntgfmpldz quvs\ntgfmpldz htdy\ntgfmpldz k\nxtdpkxm k\nsuwqxs k\nsuwqxs fv\nqckllwy fv\ndiun fv\ndiun lefa\ndiun gdoqjysx\ndhpz gdoqjysx\ndhpz bdmqdyt\ndgz bdmqdyt\nv bdmqdyt\nv aswy\nv ydkayhlrnm" }, { "input": "wxz hbeqwqp\n7\nhbeqwqp cpieghnszh\ncpieghnszh tlqrpd\ntlqrpd ttwrtio\nttwrtio xapvds\nxapvds zk\nwxz yryk\nzk b", "output": "wxz hbeqwqp\nwxz cpieghnszh\nwxz tlqrpd\nwxz ttwrtio\nwxz xapvds\nwxz zk\nyryk zk\nyryk b" }, { "input": "wced gnsgv\n23\ngnsgv japawpaf\njapawpaf nnvpeu\nnnvpeu a\na ddupputljq\nddupputljq qyhnvbh\nqyhnvbh pqwijl\nwced khuvs\nkhuvs bjkh\npqwijl ysacmboc\nbjkh srf\nsrf jknoz\njknoz hodf\nysacmboc xqtkoyh\nhodf rfp\nxqtkoyh bivgnwqvoe\nbivgnwqvoe nknf\nnknf wuig\nrfp e\ne bqqknq\nwuig sznhhhu\nbqqknq dhrtdld\ndhrtdld n\nsznhhhu bguylf", "output": "wced gnsgv\nwced japawpaf\nwced nnvpeu\nwced a\nwced ddupputljq\nwced qyhnvbh\nwced pqwijl\nkhuvs pqwijl\nbjkh pqwijl\nbjkh ysacmboc\nsrf ysacmboc\njknoz ysacmboc\nhodf ysacmboc\nhodf xqtkoyh\nrfp xqtkoyh\nrfp bivgnwqvoe\nrfp nknf\nrfp wuig\ne wuig\nbqqknq wuig\nbqqknq sznhhhu\ndhrtdld sznhhhu\nn sznhhhu\nn bguylf" }, { "input": "qqqqqqqqqq qqqqqqqq\n3\nqqqqqqqq qqqqqqqqq\nqqqqqqqqq qqqqq\nqqqqq q", "output": "qqqqqqqqqq qqqqqqqq\nqqqqqqqqqq qqqqqqqqq\nqqqqqqqqqq qqqqq\nqqqqqqqqqq q" }, { "input": "wwwww w\n8\nwwwww wwwwwwww\nwwwwwwww wwwwwwwww\nwwwwwwwww wwwwwwwwww\nw www\nwwwwwwwwww wwww\nwwww ww\nwww wwwwww\nwwwwww wwwwwww", "output": "wwwww w\nwwwwwwww w\nwwwwwwwww w\nwwwwwwwwww w\nwwwwwwwwww www\nwwww www\nww www\nww wwwwww\nww wwwwwww" }, { "input": "k d\n17\nk l\nd v\nv z\nl r\nz i\nr s\ns p\np w\nw j\nj h\ni c\nh m\nm q\nc o\no g\nq x\nx n", "output": "k d\nl d\nl v\nl z\nr z\nr i\ns i\np i\nw i\nj i\nh i\nh c\nm c\nq c\nq o\nq g\nx g\nn g" } ]
1,563,865,976
2,147,483,647
Python 3
OK
TESTS
57
139
0
a, b = map(str, input().split()) print(a, b, sep=' ') n = int(input()) for i in range(n): c, d = map(str, input().split()) if c == a: a = d if c == b: b = d print(a, b, sep=' ') # CodeForcesian # ♥ # زبل
Title: A Serial Killer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input Specification: First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days. Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Specification: Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Demo Input: ['ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n', 'icm codeforces\n1\ncodeforces technex\n'] Demo Output: ['ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n', 'icm codeforces\nicm technex\n'] Note: In first example, the killer starts with ross and rachel. - After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
```python a, b = map(str, input().split()) print(a, b, sep=' ') n = int(input()) for i in range(n): c, d = map(str, input().split()) if c == a: a = d if c == b: b = d print(a, b, sep=' ') # CodeForcesian # ♥ # زبل ```
3
765
C
Table Tennis Game 2
PROGRAMMING
1,200
[ "math" ]
null
null
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins. Across all the sets Misha scored *a* points in total, and Vanya scored *b* points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible. Note that the game consisted of several complete sets.
The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=&gt;<=0).
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
[ "11 11 5\n", "11 2 3\n" ]
[ "1\n", "-1\n" ]
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
1,250
[ { "input": "11 11 5", "output": "1" }, { "input": "11 2 3", "output": "-1" }, { "input": "1 5 9", "output": "14" }, { "input": "2 3 3", "output": "2" }, { "input": "1 1000000000 1000000000", "output": "2000000000" }, { "input": "2 3 5", "output": "3" }, { "input": "1000000000 1000000000 1000000000", "output": "2" }, { "input": "1 0 1", "output": "1" }, { "input": "101 99 97", "output": "-1" }, { "input": "1000000000 0 1", "output": "-1" }, { "input": "137 137 136", "output": "1" }, { "input": "255 255 255", "output": "2" }, { "input": "1 0 1000000000", "output": "1000000000" }, { "input": "123 456 789", "output": "9" }, { "input": "666666 6666666 666665", "output": "-1" }, { "input": "1000000000 999999999 999999999", "output": "-1" }, { "input": "100000000 100000001 99999999", "output": "-1" }, { "input": "3 2 1000000000", "output": "-1" }, { "input": "999999999 1000000000 999999998", "output": "-1" }, { "input": "12938621 192872393 102739134", "output": "21" }, { "input": "666666666 1230983 666666666", "output": "1" }, { "input": "123456789 123456789 123456787", "output": "1" }, { "input": "5 6 0", "output": "-1" }, { "input": "11 0 12", "output": "-1" }, { "input": "2 11 0", "output": "-1" }, { "input": "2 1 0", "output": "-1" }, { "input": "10 11 12", "output": "2" }, { "input": "11 12 5", "output": "-1" }, { "input": "11 12 3", "output": "-1" }, { "input": "11 15 4", "output": "-1" }, { "input": "2 3 1", "output": "-1" }, { "input": "11 12 0", "output": "-1" }, { "input": "11 13 2", "output": "-1" }, { "input": "11 23 22", "output": "4" }, { "input": "10 21 0", "output": "-1" }, { "input": "11 23 1", "output": "-1" }, { "input": "11 10 12", "output": "-1" }, { "input": "11 1 12", "output": "-1" }, { "input": "11 5 12", "output": "-1" }, { "input": "11 8 12", "output": "-1" }, { "input": "11 12 1", "output": "-1" }, { "input": "5 4 6", "output": "-1" }, { "input": "10 1 22", "output": "-1" }, { "input": "2 3 0", "output": "-1" }, { "input": "11 23 2", "output": "-1" }, { "input": "2 1000000000 1000000000", "output": "1000000000" }, { "input": "11 0 15", "output": "-1" }, { "input": "11 5 0", "output": "-1" }, { "input": "11 5 15", "output": "-1" }, { "input": "10 0 13", "output": "-1" }, { "input": "4 7 0", "output": "-1" }, { "input": "10 2 8", "output": "-1" }, { "input": "11 5 22", "output": "2" }, { "input": "11 13 0", "output": "-1" }, { "input": "2 0 3", "output": "-1" }, { "input": "10 10 0", "output": "1" }, { "input": "10 11 10", "output": "2" }, { "input": "3 5 4", "output": "2" }, { "input": "11 22 3", "output": "2" }, { "input": "11 12 10", "output": "-1" }, { "input": "10 2 13", "output": "-1" }, { "input": "5 6 1", "output": "-1" }, { "input": "10 21 5", "output": "-1" }, { "input": "10 11 9", "output": "-1" }, { "input": "10 17 7", "output": "-1" }, { "input": "3 4 1", "output": "-1" }, { "input": "4 5 3", "output": "-1" }, { "input": "11 3 23", "output": "-1" }, { "input": "11 3 12", "output": "-1" }, { "input": "2 5 0", "output": "-1" }, { "input": "10 21 2", "output": "-1" }, { "input": "5 1 6", "output": "-1" }, { "input": "10 11 0", "output": "-1" }, { "input": "10 9 11", "output": "-1" }, { "input": "7 10 5", "output": "-1" }, { "input": "5 7 2", "output": "-1" }, { "input": "6 5 7", "output": "-1" }, { "input": "11 16 2", "output": "-1" }, { "input": "11 1000000000 10", "output": "-1" }, { "input": "10 2 21", "output": "-1" }, { "input": "10 15 1", "output": "-1" }, { "input": "5 2 8", "output": "-1" }, { "input": "11 10000000 10", "output": "-1" }, { "input": "10 1 101", "output": "-1" }, { "input": "20 24 2", "output": "-1" }, { "input": "11 24 0", "output": "-1" }, { "input": "11 17 4", "output": "-1" }, { "input": "11 13 1", "output": "-1" }, { "input": "10 11 2", "output": "-1" }, { "input": "11 23 3", "output": "-1" }, { "input": "10 99 0", "output": "-1" }, { "input": "6 7 4", "output": "-1" }, { "input": "11 1 22", "output": "2" }, { "input": "11 2 13", "output": "-1" }, { "input": "2 1 3", "output": "-1" }, { "input": "11 6 18", "output": "-1" }, { "input": "11 122 4", "output": "-1" }, { "input": "11 21 10", "output": "-1" }, { "input": "3 2 4", "output": "-1" }, { "input": "9 11 2", "output": "-1" }, { "input": "11 0 7", "output": "-1" }, { "input": "5 9 4", "output": "-1" }, { "input": "100 105 5", "output": "-1" }, { "input": "11 15 0", "output": "-1" }, { "input": "5 6 4", "output": "-1" }, { "input": "3 4 2", "output": "-1" }, { "input": "2 9 0", "output": "-1" }, { "input": "11 13 11", "output": "2" }, { "input": "11 15 5", "output": "-1" }, { "input": "11 4 15", "output": "-1" }, { "input": "10 1 0", "output": "-1" }, { "input": "11 16 8", "output": "-1" }, { "input": "10 43 0", "output": "-1" }, { "input": "11 13 5", "output": "-1" }, { "input": "11 22 0", "output": "2" }, { "input": "5 6 3", "output": "-1" }, { "input": "2 1 11", "output": "-1" }, { "input": "4 5 1", "output": "-1" }, { "input": "11 23 0", "output": "-1" }, { "input": "11 4 12", "output": "-1" }, { "input": "12 13 1", "output": "-1" }, { "input": "10 19 9", "output": "-1" }, { "input": "3 7 2", "output": "-1" }, { "input": "12 18 0", "output": "-1" }, { "input": "11 25 3", "output": "-1" }, { "input": "11 23 5", "output": "-1" }, { "input": "2 1 5", "output": "-1" }, { "input": "2 0 5", "output": "-1" }, { "input": "11 24 1", "output": "-1" }, { "input": "10 11 4", "output": "-1" }, { "input": "2 0 1", "output": "-1" }, { "input": "10 0 21", "output": "-1" }, { "input": "3 0 7", "output": "-1" }, { "input": "18 11 21", "output": "-1" }, { "input": "3 7 0", "output": "-1" }, { "input": "5 11 0", "output": "-1" }, { "input": "11 5 13", "output": "-1" }, { "input": "11 9 34", "output": "-1" }, { "input": "11 13 9", "output": "-1" }, { "input": "10 0 22", "output": "-1" }, { "input": "5 1 12", "output": "-1" }, { "input": "11 2 12", "output": "-1" }, { "input": "11 9 12", "output": "-1" }, { "input": "11 24 2", "output": "-1" }, { "input": "11 23 6", "output": "-1" }, { "input": "11 20 4", "output": "-1" }, { "input": "2 5 1", "output": "-1" }, { "input": "120 132 133", "output": "2" }, { "input": "11 111 4", "output": "-1" }, { "input": "10 7 11", "output": "-1" }, { "input": "6 13 0", "output": "-1" }, { "input": "5 11 1", "output": "-1" }, { "input": "11 5 27", "output": "-1" }, { "input": "11 15 3", "output": "-1" }, { "input": "11 0 13", "output": "-1" }, { "input": "11 13 10", "output": "-1" }, { "input": "11 25 5", "output": "-1" }, { "input": "4 3 5", "output": "-1" }, { "input": "100 199 100", "output": "2" }, { "input": "11 2 22", "output": "2" }, { "input": "10 20 2", "output": "2" }, { "input": "5 5 0", "output": "1" }, { "input": "10 11 1", "output": "-1" }, { "input": "11 12 2", "output": "-1" }, { "input": "5 16 3", "output": "-1" }, { "input": "12 14 1", "output": "-1" }, { "input": "10 22 2", "output": "-1" }, { "input": "2 4 0", "output": "2" }, { "input": "11 34 7", "output": "-1" }, { "input": "6 13 1", "output": "-1" }, { "input": "11 0 23", "output": "-1" }, { "input": "20 21 19", "output": "-1" }, { "input": "11 33 22", "output": "5" }, { "input": "10 4 41", "output": "-1" }, { "input": "3 4 0", "output": "-1" }, { "input": "11 15 7", "output": "-1" }, { "input": "5 0 6", "output": "-1" }, { "input": "11 3 22", "output": "2" }, { "input": "2 6 0", "output": "3" }, { "input": "10 11 11", "output": "2" }, { "input": "11 33 0", "output": "3" }, { "input": "4 6 2", "output": "-1" }, { "input": "11 76 2", "output": "-1" }, { "input": "7 9 4", "output": "-1" }, { "input": "10 43 1", "output": "-1" }, { "input": "22 25 5", "output": "-1" }, { "input": "3 5 2", "output": "-1" }, { "input": "11 1 24", "output": "-1" }, { "input": "12 25 3", "output": "-1" }, { "input": "11 0 22", "output": "2" }, { "input": "4 2 5", "output": "-1" }, { "input": "11 13 3", "output": "-1" }, { "input": "11 12 9", "output": "-1" }, { "input": "11 35 1", "output": "-1" }, { "input": "5 3 6", "output": "-1" }, { "input": "5 11 4", "output": "-1" }, { "input": "12 8 14", "output": "-1" }, { "input": "10 12 9", "output": "-1" }, { "input": "11 12 13", "output": "2" }, { "input": "11 15 2", "output": "-1" }, { "input": "11 23 4", "output": "-1" }, { "input": "5 3 11", "output": "-1" }, { "input": "6 13 2", "output": "-1" }, { "input": "4 1 0", "output": "-1" }, { "input": "11 32 10", "output": "-1" }, { "input": "2 11 1", "output": "-1" }, { "input": "10 11 7", "output": "-1" }, { "input": "11 26 0", "output": "-1" }, { "input": "100 205 5", "output": "-1" }, { "input": "4 0 2", "output": "-1" }, { "input": "10 11 8", "output": "-1" }, { "input": "11 22 5", "output": "2" }, { "input": "4 0 5", "output": "-1" }, { "input": "11 87 22", "output": "9" }, { "input": "4 8 0", "output": "2" }, { "input": "9 8 17", "output": "-1" }, { "input": "10 20 0", "output": "2" }, { "input": "10 9 19", "output": "-1" }, { "input": "12 2 13", "output": "-1" }, { "input": "11 24 5", "output": "-1" }, { "input": "10 1 11", "output": "-1" }, { "input": "4 0 9", "output": "-1" }, { "input": "3 0 1", "output": "-1" }, { "input": "11 12 4", "output": "-1" }, { "input": "3 8 2", "output": "-1" }, { "input": "11 17 10", "output": "-1" }, { "input": "6 1 13", "output": "-1" }, { "input": "11 25 0", "output": "-1" }, { "input": "12 0 13", "output": "-1" }, { "input": "10 5 20", "output": "2" }, { "input": "11 89 2", "output": "-1" }, { "input": "2 4 1", "output": "2" }, { "input": "10 31 0", "output": "-1" }, { "input": "11 34 1", "output": "-1" }, { "input": "999 6693 8331", "output": "14" }, { "input": "10 55 1", "output": "-1" }, { "input": "11 12 8", "output": "-1" }, { "input": "1 9 22", "output": "31" }, { "input": "7572 9186 895", "output": "-1" }, { "input": "3 2 11", "output": "-1" }, { "input": "2 1 4", "output": "2" }, { "input": "11 10 19", "output": "-1" }, { "input": "100 199 99", "output": "-1" }, { "input": "2537 8926 1523", "output": "-1" }, { "input": "11 0 5", "output": "-1" }, { "input": "5 1 11", "output": "-1" }, { "input": "12 13 5", "output": "-1" }, { "input": "10 12 0", "output": "-1" }, { "input": "5 4 7", "output": "-1" }, { "input": "12 25 1", "output": "-1" }, { "input": "7 9 0", "output": "-1" }, { "input": "4 15 0", "output": "-1" }, { "input": "5 11 2", "output": "-1" }, { "input": "11 58 3", "output": "-1" }, { "input": "10 11 5", "output": "-1" }, { "input": "10 3 1003", "output": "-1" }, { "input": "11 14 0", "output": "-1" }, { "input": "11 8 23", "output": "-1" }, { "input": "11 22 4", "output": "2" }, { "input": "5 2 0", "output": "-1" }, { "input": "11 1 35", "output": "-1" }, { "input": "12 25 5", "output": "-1" }, { "input": "11 37 4", "output": "-1" }, { "input": "20 42 3", "output": "-1" }, { "input": "10 12 2", "output": "-1" }, { "input": "4 1 5", "output": "-1" }, { "input": "5 16 0", "output": "-1" }, { "input": "11 13 7", "output": "-1" }, { "input": "5 0 3", "output": "-1" }, { "input": "11 2 11", "output": "1" }, { "input": "3 2 2000", "output": "-1" }, { "input": "3 0 4241", "output": "-1" }, { "input": "2 12 11", "output": "11" }, { "input": "10 2 82", "output": "-1" }, { "input": "11 0 11", "output": "1" }, { "input": "11 20 20", "output": "2" }, { "input": "5 0 10", "output": "2" }, { "input": "11 1 0", "output": "-1" }, { "input": "11 13 13", "output": "2" } ]
1,680,288,593
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int a, b, k; cin >> k >> a >> b; if (a + b < k){ cout << "-1\n"; return 0; } int x = a/k, y = b/k; if (y == 0 && a % k){ cout << "-1\n"; return 0; } if (x == 0 && b % k){ cout << "-1\n"; return 0; } cout << x+y << endl; return 0; }
Title: Table Tennis Game 2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins. Across all the sets Misha scored *a* points in total, and Vanya scored *b* points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible. Note that the game consisted of several complete sets. Input Specification: The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=&gt;<=0). Output Specification: If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets. Demo Input: ['11 11 5\n', '11 2 3\n'] Demo Output: ['1\n', '-1\n'] Note: Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
```python #include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int a, b, k; cin >> k >> a >> b; if (a + b < k){ cout << "-1\n"; return 0; } int x = a/k, y = b/k; if (y == 0 && a % k){ cout << "-1\n"; return 0; } if (x == 0 && b % k){ cout << "-1\n"; return 0; } cout << x+y << endl; return 0; } ```
-1
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,607,250,095
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
[m,n] = list(map(int,for i in input().split())) out = (m//2)*n + (n//2)*(m%2) print(out)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python [m,n] = list(map(int,for i in input().split())) out = (m//2)*n + (n//2)*(m%2) print(out) ```
-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,592,127,621
2,147,483,647
PyPy 3
OK
TESTS
21
140
0
a, b, c=map(int, input().split()) if(a+b+c<=2*(a+b) and a+b+c<=2*(b+c) and a+b+c<=2*(a+c)): print(a+b+c) elif(2*(a+b)<=2*(b+c) and 2*(a+b)<=2*(a+c)): print(2*(a+b)) elif(2*(b+c)<=2*(a+c)): print(2*(b+c)) else: print(2*(a+c))
Title: Patrick and Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled. Input Specification: The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops. Output Specification: Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. Demo Input: ['10 20 30\n', '1 1 5\n'] Demo Output: ['60\n', '4\n'] Note: The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
```python a, b, c=map(int, input().split()) if(a+b+c<=2*(a+b) and a+b+c<=2*(b+c) and a+b+c<=2*(a+c)): print(a+b+c) elif(2*(a+b)<=2*(b+c) and 2*(a+b)<=2*(a+c)): print(2*(a+b)) elif(2*(b+c)<=2*(a+c)): print(2*(b+c)) else: print(2*(a+c)) ```
3