contestId
int64 0
1.01k
| index
stringclasses 57
values | name
stringlengths 2
58
| type
stringclasses 2
values | rating
int64 0
3.5k
| tags
sequencelengths 0
11
| title
stringclasses 522
values | time-limit
stringclasses 8
values | memory-limit
stringclasses 8
values | problem-description
stringlengths 0
7.15k
| input-specification
stringlengths 0
2.05k
| output-specification
stringlengths 0
1.5k
| demo-input
sequencelengths 0
7
| demo-output
sequencelengths 0
7
| note
stringlengths 0
5.24k
| points
float64 0
425k
| test_cases
listlengths 0
402
| creationTimeSeconds
int64 1.37B
1.7B
| relativeTimeSeconds
int64 8
2.15B
| programmingLanguage
stringclasses 3
values | verdict
stringclasses 14
values | testset
stringclasses 12
values | passedTestCount
int64 0
1k
| timeConsumedMillis
int64 0
15k
| memoryConsumedBytes
int64 0
805M
| code
stringlengths 3
65.5k
| prompt
stringlengths 262
8.2k
| response
stringlengths 17
65.5k
| score
float64 -1
3.99
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
805 | B | 3-palindrome | PROGRAMMING | 1,000 | [
"constructive algorithms"
] | null | null | In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. | Print the string that satisfies all the constraints.
If there are multiple answers, print any of them. | [
"2\n",
"3\n"
] | [
"aa\n",
"bba\n"
] | A palindrome is a sequence of characters which reads the same backward and forward. | 1,000 | [
{
"input": "2",
"output": "aa"
},
{
"input": "3",
"output": "aab"
},
{
"input": "38",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "47",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "59",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "67",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "77",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "89",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "98",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "109",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "117",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "1",
"output": "a"
},
{
"input": "200000",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "100000",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "143670",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "104217",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "17879",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "131809",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "140873",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "77859",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "153022",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "179227",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "182801",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "5188",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "86539",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "12802",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "120289",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "132866",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "133377",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "31775",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "160397",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "161415",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "163623",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "22942",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "134767",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "52257",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "64905",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "183758",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "60131",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "146883",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "6",
"output": "aabbaa"
},
{
"input": "4",
"output": "aabb"
}
] | 1,572,766,471 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 109 | 409,600 | n = int(input())
s = 'abba'
print(n // 4 * s + s[:n % 4])
| Title: 3-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string.
Output Specification:
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Demo Input:
['2\n', '3\n']
Demo Output:
['aa\n', 'bba\n']
Note:
A palindrome is a sequence of characters which reads the same backward and forward. | ```python
n = int(input())
s = 'abba'
print(n // 4 * s + s[:n % 4])
``` | 3 |
|
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
},
{
"input": "859 453892 543",
"output": "126416972"
},
{
"input": "1000 1000000000 1000",
"output": "0"
},
{
"input": "1000 500500000 1000",
"output": "0"
},
{
"input": "1000 500500001 1000",
"output": "0"
},
{
"input": "1000 500499999 1000",
"output": "1"
},
{
"input": "634 87973 214",
"output": "14497197"
},
{
"input": "432 10000 241",
"output": "12587552"
},
{
"input": "111 111111111 111",
"output": "0"
},
{
"input": "20 43 3",
"output": "77"
}
] | 1,699,716,328 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 46 | 0 | k, n, w = map(int, input().split())
tot = (w * (w + 1)) // 2
req = tot * k
print(max(req - n, 0))
| Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
Input Specification:
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output Specification:
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Demo Input:
['3 17 4\n']
Demo Output:
['13']
Note:
none | ```python
k, n, w = map(int, input().split())
tot = (w * (w + 1)) // 2
req = tot * k
print(max(req - n, 0))
``` | 3 |
|
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter.
Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva.
You are given an encoding *s* of some word, your task is to decode it. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva.
In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same.
In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba. | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"input": "1\nw",
"output": "w"
},
{
"input": "2\ncb",
"output": "cb"
},
{
"input": "3\nqok",
"output": "oqk"
},
{
"input": "4\naegi",
"output": "gaei"
},
{
"input": "5\noqquy",
"output": "uqoqy"
},
{
"input": "6\nulhpnm",
"output": "nhulpm"
},
{
"input": "7\nijvxljt",
"output": "jxjivlt"
},
{
"input": "8\nwwmiwkeo",
"output": "ewmwwiko"
},
{
"input": "9\ngmwqmpfow",
"output": "opqmgwmfw"
},
{
"input": "10\nhncmexsslh",
"output": "lsechnmxsh"
},
{
"input": "20\nrtcjbjlbtjfmvzdqutuw",
"output": "uudvftlbcrtjjbjmzqtw"
},
{
"input": "21\ngjyiqoebcnpsdegxnsauh",
"output": "usxesnboijgyqecpdgnah"
},
{
"input": "30\nudotcwvcwxajkadxqvxvwgmwmnqrby",
"output": "bqmmwxqdkawvcoudtwcxjaxvvgwnry"
},
{
"input": "31\nipgfrxxcgckksfgexlicjvtnhvrfbmb",
"output": "mfvnvclefkccxfpigrxgksgxijthrbb"
},
{
"input": "50\nwobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy",
"output": "vsolrruoeqehviaqtycivhrbwoevvkhujmhagaholrmsatdjjy"
},
{
"input": "200\nhvayscqiwpcfykibwyudkzuzdkgqqvbnrfeupjefevlvojngmlcjwzijrkzbsaovabkvvwmjgoonyhuiphwmqdoiuueuyqtychbsklflnvghipdgaxhuhiiqlqocpvhldgvnsrtcwxpidrjffwvwcirluyyxzxrglheczeuouklzkvnyubsvgvmdbrylimztotdbmjph",
"output": "pmdoziybmgsunkluuzelrzyurcvfjdpwtsvdhpolihhadignfkbctyeuoqwpuyogmvkaoszriwcmnoleeperbqgdukuwiycwqsahvycipfkbydzzkqvnfujfvvjgljzjkbavbvwjonhihmdiuuqyhsllvhpgxuiqqcvlgnrcxirfwwilyxxghceokzvybvvdrlmttbjh"
},
{
"input": "201\nrpkghhfibtmlkpdiklegblbuyshfirheatjkfoqkfayfbxeeqijwqdwkkrkbdxlhzkhyiifemsghwovorlqedngldskfbhmwrnzmtjuckxoqdszmsdnbuqnlqzswdfhagasmfswanifrjjcuwdsplytvmnfarchgqteedgfpumkssindxndliozojzlpznwedodzwrrus",
"output": "urzoenpzoolndismpgetgcanvypdujriasmaafwzlqbdmsqxcjmnwhfslneloohseiykhxbrkdwiexfakokterfsulglipltihgprkhfbmkdkebbyhihajfqfybeqjqwkkdlzhifmgwvrqdgdkbmrztukodzsnunqsdhgsfwnfjcwsltmfrhqedfuksnxdizjlzwddwrs"
},
{
"input": "500\naopxumqciwxewxvlxzebsztskjvjzwyewjztqrsuvamtvklhqrbodtncqdchjrlpywvmtgnkkwtvpggktewdgvnhydkexwoxkgltaesrtifbwpciqsvrgjtqrdnyqkgqwrryacluaqmgdwxinqieiblolyekcbzahlhxdwqcgieyfgmicvgbbitbzhejkshjunzjteyyfngigjwyqqndtjrdykzrnrpinkwtrlchhxvycrhstpecadszilicrqdeyyidohqvzfnsqfyuemigacysxvtrgxyjcvejkjstsnatfqlkeytxgsksgpcooypsmqgcluzwofaupegxppbupvtumjerohdteuenwcmqaoazohkilgpkjavcrjcslhzkyjcgfzxxzjfufichxcodcawonkxhbqgfimmlycswdzwbnmjwhbwihfoftpcqplncavmbxuwnsabiyvpcrhfgtqyaguoaigknushbqjwqmmyvsxwabrub",
"output": "ubwsymwqhukiogytfrpybswxmanpctohwhjnwdsymigbxnwcoxcffzxfcyzlcrvjplkoaamweedoemtpbpgpaozlgmpocgkgtelfasskecygtxyaieyqnzqoiydriisaethcvhcrwnpnzyrtnqwggfytzuhkeztbgcmfegqdhhzcelliinxdmalarwgqnrtgvqcwftsalkoxkyngwtgptkntvyljcqndbqlvmvsqzwyzvktsexvwxiqupaoxmcwexlzbzsjjwejtruatkhrotcdhrpwmgkwvgkedvhdewxgteribpisrjqdykqrycuqgwiqeboykbalxwciygivbibhjsjnjeynijyqdjdkrriktlhxyrspcdzlcqeydhvfsfumgcsvrxjvjjtntqkyxsspoysqcuwfuexpuvujrhtuncqozhigkacjshkjgzxjuihcdaokhqfmlcwzbmwbiffpqlcvbunaivchgqauagnsbjqmvxarb"
},
{
"input": "501\noilesjbgowlnayckhpoaitijewsyhgavnthycaecwnvzpxgjqfjyxnjcjknvvsmjbjwtcoyfbegmnnheeamvtfjkigqoanhvgdfrjchdqgowrstlmrjmcsuuwvvoeucfyhnxivosrxblfoqwikfxjnnyejdiihpenfcahtjwcnzwvxxseicvdfgqhtvefswznuyohmmljlnxubhevywpmnitnkhecsgccpstxkmdzabsnwxkokdfsogzbpnfvgudvqlstxojzfzugxbfrozveaiofrzksegdelxsdhcjlqwqlgjcqiujptoenxozhkqhcpkarretqzfkwuvbmfdcdoqliyzmlfrfhzrnkbhofuctkpeacqejwvdrlyvepudrlzncbhwrgmxrczphsoymvtuzqjscvbtqpymogupgzctepccravjcrfsadueyraqvwasravkubebojqspdntewnjohvccamvoxdauyakvehjhabpdyzyme",
"output": "mzdbhhvaudomcvonenpqoeuvravayuafcvrcecguoyqbcjztmohzrmrhczrueyrvjqaptuobnzffmylocfbukztraphkzxetjicgqqjhsldekroavofxufjxsqdgfpzofkkwsadktpcsektnpyebxllmouzsetqfvisxwnwtafehijynxkwolxsvxhfuovusmrlswgdcrdvnogkfvaenmefotjjsvkcnyfjxzncaytvgywjtapkynwgjeiolsbolachoiieshanhcewvpgqjxjjnvmbwcybgnhemtjiqahgfjhqortmjcuwvecyniorbfqifjnedipnchjczvxecdghvfwnyhmjnuhvwminhcgcsxmzbnxodsgbnvuvltozzgbrzeifzsgexdclwljquponohqckreqfwvmddqizlrhrkhfckecewdlvpdlnbwgxcpsyvuqsvtpmgpztpcajrsderqwsakbbjsdtwjhcavxaykejapyye"
}
] | 1,632,131,343 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 109 | 22,835,200 | n = int(input())
s = input()
nach = []
con = []
if n % 2 == 0:
for i in range(n):
if i == 0 or i % 2 == 0:
nach.append(s[i])
else:
con.append(s[i])
else:
for i in range(n):
if i == 0 or i % 2 == 0:
con.append(s[i])
else:
nach.append(s[i])
for i in range(len(nach)):
print(nach[-(i + 1)], end='')
for i in range(len(con)):
print(con[i], end='')
| Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter.
Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva.
You are given an encoding *s* of some word, your task is to decode it.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding.
Output Specification:
Print the word that Polycarp encoded.
Demo Input:
['5\nlogva\n', '2\nno\n', '4\nabba\n']
Demo Output:
['volga\n', 'no\n', 'baba\n']
Note:
In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva.
In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same.
In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba. | ```python
n = int(input())
s = input()
nach = []
con = []
if n % 2 == 0:
for i in range(n):
if i == 0 or i % 2 == 0:
nach.append(s[i])
else:
con.append(s[i])
else:
for i in range(n):
if i == 0 or i % 2 == 0:
con.append(s[i])
else:
nach.append(s[i])
for i in range(len(nach)):
print(nach[-(i + 1)], end='')
for i in range(len(con)):
print(con[i], end='')
``` | 3 |
|
525 | B | Pasha and String | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"math",
"strings"
] | null | null | Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha spent *m* days performing the following transformations on his string — each day he chose integer *a**i* and reversed a piece of string (a segment) from position *a**i* to position |*s*|<=-<=*a**i*<=+<=1. It is guaranteed that 2·*a**i*<=≤<=|*s*|.
You face the following task: determine what Pasha's string will look like after *m* days. | The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters.
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of days when Pasha changed his string.
The third line contains *m* space-separated elements *a**i* (1<=≤<=*a**i*; 2·*a**i*<=≤<=|*s*|) — the position from which Pasha started transforming the string on the *i*-th day. | In the first line of the output print what Pasha's string *s* will look like after *m* days. | [
"abcdef\n1\n2\n",
"vwxyz\n2\n2 2\n",
"abcdef\n3\n1 2 3\n"
] | [
"aedcbf\n",
"vwxyz\n",
"fbdcea\n"
] | none | 750 | [
{
"input": "abcdef\n1\n2",
"output": "aedcbf"
},
{
"input": "vwxyz\n2\n2 2",
"output": "vwxyz"
},
{
"input": "abcdef\n3\n1 2 3",
"output": "fbdcea"
},
{
"input": "jc\n5\n1 1 1 1 1",
"output": "cj"
},
{
"input": "wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3",
"output": "wyjldgqxlc"
},
{
"input": "keicnqmuqinhsmtudqcilocxkbqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlphhboycfavs\n2\n5 12",
"output": "keiccyobhhphsmtudqcilocxkbqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlniqumqnfavs"
},
{
"input": "xwcxggxvfqbdklewbxkjzibmufnaywuxsqvwakefxbbkfandvigasbhbatsxyqxicrosatfsfybedklsaztyyiuurfbrzmwumujy\n100\n14 43 30 13 8 19 33 7 8 14 15 35 5 18 44 1 35 1 18 7 50 47 9 49 28 29 39 37 27 17 19 12 5 24 37 42 37 23 35 31 10 26 5 38 40 34 42 47 2 40 43 34 16 25 14 45 35 38 46 48 49 27 49 38 10 49 5 7 3 3 41 25 24 34 37 33 17 50 48 11 40 43 48 10 9 50 18 39 32 13 26 40 37 16 45 50 27 3 7 31",
"output": "xjcxggxvfbbruliyyxkjzikdebnfyftxsorcaxqyxbtkfhbdvigasnababsxfekiwvqsauwsayfumblsaztbweukdfqrzmwumuwy"
}
] | 1,623,088,808 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 14,745,600 | s1=input()
d=int(input())
m=[int(x) for x in input().split(' ')]
l=len(s1)
s=''
s+=s1
for i in m:
t1=s[:i-1]
t2=s[i-1:l-i+1]
t2=t2[::-1]
t3=s[l-i+1:]
s=t1+t2+t3
print(s) | Title: Pasha and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha spent *m* days performing the following transformations on his string — each day he chose integer *a**i* and reversed a piece of string (a segment) from position *a**i* to position |*s*|<=-<=*a**i*<=+<=1. It is guaranteed that 2·*a**i*<=≤<=|*s*|.
You face the following task: determine what Pasha's string will look like after *m* days.
Input Specification:
The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters.
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of days when Pasha changed his string.
The third line contains *m* space-separated elements *a**i* (1<=≤<=*a**i*; 2·*a**i*<=≤<=|*s*|) — the position from which Pasha started transforming the string on the *i*-th day.
Output Specification:
In the first line of the output print what Pasha's string *s* will look like after *m* days.
Demo Input:
['abcdef\n1\n2\n', 'vwxyz\n2\n2 2\n', 'abcdef\n3\n1 2 3\n']
Demo Output:
['aedcbf\n', 'vwxyz\n', 'fbdcea\n']
Note:
none | ```python
s1=input()
d=int(input())
m=[int(x) for x in input().split(' ')]
l=len(s1)
s=''
s+=s1
for i in m:
t1=s[:i-1]
t2=s[i-1:l-i+1]
t2=t2[::-1]
t3=s[l-i+1:]
s=t1+t2+t3
print(s)
``` | 0 |
|
772 | A | Voltage Keepsake | PROGRAMMING | 1,800 | [
"binary search",
"math"
] | null | null | You have *n* devices that you want to use simultaneously.
The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-th device currently has *b**i* units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add *p* units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·*p* units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. | The first line contains two integers, *n* and *p* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*p*<=≤<=109) — the number of devices and the power of the charger.
This is followed by *n* lines which contain two integers each. Line *i* contains the integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100<=000) — the power of the device and the amount of power stored in the device in the beginning. | If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4.
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 1\n2 2\n2 1000\n",
"1 100\n1 1\n",
"3 5\n4 3\n5 2\n6 1\n"
] | [
"2.0000000000",
"-1\n",
"0.5000000000"
] | In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. | 500 | [
{
"input": "2 1\n2 2\n2 1000",
"output": "2.0000000000"
},
{
"input": "1 100\n1 1",
"output": "-1"
},
{
"input": "3 5\n4 3\n5 2\n6 1",
"output": "0.5000000000"
},
{
"input": "1 1\n1 87",
"output": "-1"
},
{
"input": "1 1\n100 77",
"output": "0.7777777778"
},
{
"input": "5 10\n3 81\n3 49\n1 20\n1 12\n1 30",
"output": "-1"
},
{
"input": "5 10\n4 3\n1 54\n2 57\n2 31\n1 99",
"output": "-1"
},
{
"input": "5 10\n2 81\n3 31\n4 49\n1 35\n1 67",
"output": "263.0000000000"
},
{
"input": "10 1\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92",
"output": "102.2222222222"
},
{
"input": "10 1\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16",
"output": "17.7777777778"
},
{
"input": "10 1\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40",
"output": "44.4444444444"
},
{
"input": "2 1\n1 10\n1 10",
"output": "20.0000000000"
},
{
"input": "20 16807\n75250 50074\n43659 8931\n11273 27545\n50879 77924\n37710 64441\n38166 84493\n43043 7988\n22504 82328\n31730 78841\n42613 44304\n33170 17710\n97158 29561\n70934 93100\n80279 51817\n95336 99098\n7827 13513\n29268 23811\n77634 80980\n79150 36580\n58822 11968",
"output": "0.2244225704"
}
] | 1,503,236,816 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 108 | 0 | def valid(i:float):
global n, p, l
temp_p = float(p*i)
for j in range (n):
if i*l[j][0]<=l[j][0]:
continue
elif i*l[j][0] <=l[j][0]+temp_p:
temp_p =max(0.0,abs(i*l[j][0]-l[j][0]))
else:
return False
return True
def Binary_Search(left:float, right:float, counter:int):
if counter>=100:
return left
mid = (right+left)/2.0
if valid(mid):
left=mid
else:
right=mid-0.0001
return Binary_Search(left, right, counter+1)
Max= 1e10
n, p = map (int, input().split())
l= [list(map(int,input().split())) for j in range(n)]
if valid(Max):
print(-1)
else:
print(Binary_Search(0.0, Max, 0))
| Title: Voltage Keepsake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *n* devices that you want to use simultaneously.
The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-th device currently has *b**i* units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add *p* units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·*p* units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input Specification:
The first line contains two integers, *n* and *p* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*p*<=≤<=109) — the number of devices and the power of the charger.
This is followed by *n* lines which contain two integers each. Line *i* contains the integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100<=000) — the power of the device and the amount of power stored in the device in the beginning.
Output Specification:
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4.
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 1\n2 2\n2 1000\n', '1 100\n1 1\n', '3 5\n4 3\n5 2\n6 1\n']
Demo Output:
['2.0000000000', '-1\n', '0.5000000000']
Note:
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. | ```python
def valid(i:float):
global n, p, l
temp_p = float(p*i)
for j in range (n):
if i*l[j][0]<=l[j][0]:
continue
elif i*l[j][0] <=l[j][0]+temp_p:
temp_p =max(0.0,abs(i*l[j][0]-l[j][0]))
else:
return False
return True
def Binary_Search(left:float, right:float, counter:int):
if counter>=100:
return left
mid = (right+left)/2.0
if valid(mid):
left=mid
else:
right=mid-0.0001
return Binary_Search(left, right, counter+1)
Max= 1e10
n, p = map (int, input().split())
l= [list(map(int,input().split())) for j in range(n)]
if valid(Max):
print(-1)
else:
print(Binary_Search(0.0, Max, 0))
``` | 0 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,521,873,112 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 186 | 7,065,600 | #!/usr/bin/env python3
#-*- coding: utf-8 -*-
from sys import stdin, stdout
num_of_coordinates_set = int(stdin.readline().rstrip())
coordinates_list = list()
for i in range(num_of_coordinates_set):
coordinates_list.append([int(n) for n in stdin.readline().rstrip().split()])
sumx = sumy = sumz = 0
for i in range(num_of_coordinates_set):
sumx += coordinates_list[i][0]
sumy += coordinates_list[i][1]
sumz += coordinates_list[i][2]
print('YES' if not (sumx or sumy or sumz) else 'NO')
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
from sys import stdin, stdout
num_of_coordinates_set = int(stdin.readline().rstrip())
coordinates_list = list()
for i in range(num_of_coordinates_set):
coordinates_list.append([int(n) for n in stdin.readline().rstrip().split()])
sumx = sumy = sumz = 0
for i in range(num_of_coordinates_set):
sumx += coordinates_list[i][0]
sumy += coordinates_list[i][1]
sumz += coordinates_list[i][2]
print('YES' if not (sumx or sumy or sumz) else 'NO')
``` | 3.940339 |
0 | none | none | none | 0 | [
"none"
] | null | null | This is an interactive problem. In the interaction section below you will see the information about flushing the output.
In this problem, you will be playing a game with Hongcow. How lucky of you!
Hongcow has a hidden *n* by *n* matrix *M*. Let *M**i*,<=*j* denote the entry *i*-th row and *j*-th column of the matrix. The rows and columns are labeled from 1 to *n*.
The matrix entries are between 0 and 109. In addition, *M**i*,<=*i*<==<=0 for all valid *i*. Your task is to find the minimum value along each row, excluding diagonal elements. Formally, for each *i*, you must find .
To do this, you can ask Hongcow some questions.
A question consists of giving Hongcow a subset of distinct indices {*w*1,<=*w*2,<=...,<=*w**k*}, with 1<=≤<=*k*<=≤<=*n*. Hongcow will respond with *n* integers. The *i*-th integer will contain the minimum value of *min*1<=≤<=*j*<=≤<=*k**M**i*,<=*w**j*.
You may only ask Hongcow at most 20 questions — he thinks you only need that many questions answered.
When you are ready to answer, print out a single integer <=-<=1 on its own line, then *n* integers on the next line. The *i*-th integer should be the minimum value in the *i*-th row of the matrix, excluding the *i*-th element. Do not forget to flush the final answer as well. Printing the answer does not count as asking a question.
You will get Wrong Answer verdict if
- Your question or answers are not in the format described in this statement. - You ask strictly more than 20 questions. - Your question contains duplicate indices. - The value of *k* in your question does not lie in the range from 1 to *n*, inclusive. - Your final answer is not correct. | The first line of input will contain a single integer *n* (2<=≤<=*n*<=≤<=1,<=000). | To print the final answer, print out the string -1 on its own line. Then, the next line should contain *n* integers. The *i*-th integer should be the minimum value of the *i*-th row of the matrix, excluding elements on the diagonal. Do not forget to flush your answer! | [
"3\n0 0 0\n2 7 0\n0 0 4\n3 0 8\n0 5 4",
"2\n0 0\n0 0"
] | [
"3\n1 2 3\n1\n3\n2\n1 2\n1\n2\n1\n1\n-1\n2 5 4\n",
"1\n2\n1\n1\n-1\n0 0"
] | In the first sample, Hongcow has the hidden matrix
Here is a more readable version demonstrating the interaction. The column on the left represents Hongcow, while the column on the right represents the contestant.
For the second sample, it is possible for off-diagonal elements of the matrix to be zero. | 0 | [] | 1,481,997,049 | 4,549 | Python 3 | WRONG_ANSWER | PRETESTS | 7 | 124 | 5,632,000 | from random import *
n = int(input())
res = [10 ** 10] * (n + 1)
my = [i for i in range(1, n + 1)]
for i in range(20):
shuffle(my)
ask = my[:n // 2]
print(n // 2)
print(' '.join(map(str, ask)))
ans = list(map(int, input().split()))
for i in range(1, n + 1):
if i not in ask:
res[i] = min(res[i], ans[i - 1])
print(-1)
print(' '.join(map(str, res[1:]))) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem. In the interaction section below you will see the information about flushing the output.
In this problem, you will be playing a game with Hongcow. How lucky of you!
Hongcow has a hidden *n* by *n* matrix *M*. Let *M**i*,<=*j* denote the entry *i*-th row and *j*-th column of the matrix. The rows and columns are labeled from 1 to *n*.
The matrix entries are between 0 and 109. In addition, *M**i*,<=*i*<==<=0 for all valid *i*. Your task is to find the minimum value along each row, excluding diagonal elements. Formally, for each *i*, you must find .
To do this, you can ask Hongcow some questions.
A question consists of giving Hongcow a subset of distinct indices {*w*1,<=*w*2,<=...,<=*w**k*}, with 1<=≤<=*k*<=≤<=*n*. Hongcow will respond with *n* integers. The *i*-th integer will contain the minimum value of *min*1<=≤<=*j*<=≤<=*k**M**i*,<=*w**j*.
You may only ask Hongcow at most 20 questions — he thinks you only need that many questions answered.
When you are ready to answer, print out a single integer <=-<=1 on its own line, then *n* integers on the next line. The *i*-th integer should be the minimum value in the *i*-th row of the matrix, excluding the *i*-th element. Do not forget to flush the final answer as well. Printing the answer does not count as asking a question.
You will get Wrong Answer verdict if
- Your question or answers are not in the format described in this statement. - You ask strictly more than 20 questions. - Your question contains duplicate indices. - The value of *k* in your question does not lie in the range from 1 to *n*, inclusive. - Your final answer is not correct.
Input Specification:
The first line of input will contain a single integer *n* (2<=≤<=*n*<=≤<=1,<=000).
Output Specification:
To print the final answer, print out the string -1 on its own line. Then, the next line should contain *n* integers. The *i*-th integer should be the minimum value of the *i*-th row of the matrix, excluding elements on the diagonal. Do not forget to flush your answer!
Demo Input:
['3\n0 0 0\n2 7 0\n0 0 4\n3 0 8\n0 5 4', '2\n0 0\n0 0']
Demo Output:
['3\n1 2 3\n1\n3\n2\n1 2\n1\n2\n1\n1\n-1\n2 5 4\n', '1\n2\n1\n1\n-1\n0 0']
Note:
In the first sample, Hongcow has the hidden matrix
Here is a more readable version demonstrating the interaction. The column on the left represents Hongcow, while the column on the right represents the contestant.
For the second sample, it is possible for off-diagonal elements of the matrix to be zero. | ```python
from random import *
n = int(input())
res = [10 ** 10] * (n + 1)
my = [i for i in range(1, n + 1)]
for i in range(20):
shuffle(my)
ask = my[:n // 2]
print(n // 2)
print(' '.join(map(str, ask)))
ans = list(map(int, input().split()))
for i in range(1, n + 1):
if i not in ask:
res[i] = min(res[i], ans[i - 1])
print(-1)
print(' '.join(map(str, res[1:])))
``` | 0 |
|
678 | C | Joty and Chocolate | PROGRAMMING | 1,600 | [
"implementation",
"math",
"number theory"
] | null | null | Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue.
After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue.
Note that she can paint tiles in any order she wants.
Given the required information, find the maximum number of chocolates Joty can get. | The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109). | Print the only integer *s* — the maximum number of chocolates Joty can get.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"5 2 3 12 15\n",
"20 2 3 3 5\n"
] | [
"39\n",
"51\n"
] | none | 0 | [
{
"input": "5 2 3 12 15",
"output": "39"
},
{
"input": "20 2 3 3 5",
"output": "51"
},
{
"input": "1 1 1 1 1",
"output": "1"
},
{
"input": "1 2 2 2 2",
"output": "0"
},
{
"input": "2 1 3 3 3",
"output": "6"
},
{
"input": "3 1 1 3 3",
"output": "9"
},
{
"input": "4 1 5 4 3",
"output": "16"
},
{
"input": "8 8 1 1 1",
"output": "8"
},
{
"input": "15 14 32 65 28",
"output": "65"
},
{
"input": "894 197 325 232 902",
"output": "2732"
},
{
"input": "8581 6058 3019 2151 4140",
"output": "10431"
},
{
"input": "41764 97259 54586 18013 75415",
"output": "0"
},
{
"input": "333625 453145 800800 907251 446081",
"output": "0"
},
{
"input": "4394826 2233224 609367 3364334 898489",
"output": "9653757"
},
{
"input": "13350712 76770926 61331309 8735000 9057368",
"output": "0"
},
{
"input": "142098087 687355301 987788392 75187408 868856364",
"output": "0"
},
{
"input": "1000000000 1 3 1000000000 999999999",
"output": "1000000000000000000"
},
{
"input": "6 6 2 8 2",
"output": "12"
},
{
"input": "500 8 4 4 5",
"output": "625"
},
{
"input": "20 4 6 2 3",
"output": "17"
},
{
"input": "10 3 9 1 2",
"output": "4"
},
{
"input": "120 18 6 3 5",
"output": "100"
},
{
"input": "30 4 6 2 2",
"output": "20"
},
{
"input": "1000000000 7171 2727 191 272",
"output": "125391842"
},
{
"input": "5 2 2 4 1",
"output": "8"
},
{
"input": "1000000000 2 2 3 3",
"output": "1500000000"
},
{
"input": "24 4 6 5 7",
"output": "48"
},
{
"input": "216 6 36 10 100",
"output": "900"
},
{
"input": "100 12 6 1 10",
"output": "160"
},
{
"input": "1000 4 8 3 5",
"output": "1000"
},
{
"input": "10 2 4 3 6",
"output": "21"
},
{
"input": "1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1000000000"
},
{
"input": "10 5 10 2 3",
"output": "5"
},
{
"input": "100000 3 9 1 2",
"output": "44444"
},
{
"input": "10 2 4 1 100",
"output": "203"
},
{
"input": "20 6 4 2 3",
"output": "19"
},
{
"input": "1200 4 16 2 3",
"output": "675"
},
{
"input": "7 2 4 7 9",
"output": "23"
},
{
"input": "24 6 4 15 10",
"output": "100"
},
{
"input": "50 2 8 15 13",
"output": "375"
},
{
"input": "100 4 6 12 15",
"output": "444"
},
{
"input": "56756 9 18 56 78",
"output": "422502"
},
{
"input": "10000 4 6 10 12",
"output": "36662"
},
{
"input": "20 2 4 3 5",
"output": "40"
},
{
"input": "24 4 6 10 100",
"output": "440"
},
{
"input": "12 2 4 5 6",
"output": "33"
},
{
"input": "100 2 4 1 100",
"output": "2525"
},
{
"input": "1000 4 6 50 50",
"output": "16650"
},
{
"input": "60 12 6 12 15",
"output": "150"
},
{
"input": "1000 2 4 5 6",
"output": "2750"
},
{
"input": "1000000000 1 1 9999 5555",
"output": "9999000000000"
},
{
"input": "50 2 2 4 5",
"output": "125"
},
{
"input": "14 4 2 2 3",
"output": "21"
},
{
"input": "100 3 9 1 2",
"output": "44"
},
{
"input": "1000000000 4 6 1 1000000000",
"output": "166666666166666667"
},
{
"input": "12 3 3 45 4",
"output": "180"
},
{
"input": "12 2 4 5 9",
"output": "42"
},
{
"input": "1000000000 2 2 1000000000 1000000000",
"output": "500000000000000000"
},
{
"input": "50 4 8 5 6",
"output": "66"
},
{
"input": "32 4 16 6 3",
"output": "48"
},
{
"input": "10000 2 4 1 1",
"output": "5000"
},
{
"input": "8 2 4 100 1",
"output": "400"
},
{
"input": "20 4 2 10 1",
"output": "55"
},
{
"input": "5 2 2 12 15",
"output": "30"
},
{
"input": "20 2 12 5 6",
"output": "51"
},
{
"input": "10 2 4 1 2",
"output": "7"
},
{
"input": "32 4 16 3 6",
"output": "30"
},
{
"input": "50 2 8 13 15",
"output": "337"
},
{
"input": "12 6 4 10 9",
"output": "38"
},
{
"input": "1000000000 999999998 999999999 999999998 999999999",
"output": "1999999997"
},
{
"input": "20 2 4 10 20",
"output": "150"
},
{
"input": "13 4 6 12 15",
"output": "54"
},
{
"input": "30 3 6 5 7",
"output": "60"
},
{
"input": "7 2 4 2 1",
"output": "6"
},
{
"input": "100000 32 16 2 3",
"output": "18750"
},
{
"input": "6 2 6 1 1",
"output": "3"
},
{
"input": "999999999 180 192 46642017 28801397",
"output": "399129078526502"
},
{
"input": "12 4 6 1 1",
"output": "4"
},
{
"input": "10 2 4 10 5",
"output": "50"
},
{
"input": "1000000 4 6 12 14",
"output": "4333328"
},
{
"input": "2000 20 30 3 5",
"output": "531"
},
{
"input": "1000000000 1 2 1 1",
"output": "1000000000"
},
{
"input": "30 3 15 10 3",
"output": "100"
},
{
"input": "1000 2 4 1 100",
"output": "25250"
},
{
"input": "6 3 3 12 15",
"output": "30"
},
{
"input": "24 4 6 1 1",
"output": "8"
},
{
"input": "20 2 12 4 5",
"output": "41"
},
{
"input": "1000000000 9 15 10 10",
"output": "1555555550"
},
{
"input": "16 2 4 1 2",
"output": "12"
},
{
"input": "100000 4 6 12 14",
"output": "433328"
},
{
"input": "24 6 4 1 1",
"output": "8"
},
{
"input": "1000000 4 6 12 15",
"output": "4499994"
},
{
"input": "100 2 4 5 6",
"output": "275"
},
{
"input": "10 3 9 12 15",
"output": "39"
},
{
"input": "1000000000 1 1 999999999 999999999",
"output": "999999999000000000"
},
{
"input": "6 2 4 2 3",
"output": "7"
},
{
"input": "2 2 2 2 2",
"output": "2"
},
{
"input": "6 6 2 1 1",
"output": "3"
},
{
"input": "100 2 4 3 7",
"output": "250"
},
{
"input": "1000000 32 16 2 5",
"output": "312500"
},
{
"input": "100 20 15 50 25",
"output": "375"
},
{
"input": "1000000000 100000007 100000013 10 3",
"output": "117"
},
{
"input": "1000000000 9999999 99999998 3 3",
"output": "330"
},
{
"input": "10077696 24 36 10 100",
"output": "30792960"
},
{
"input": "392852503 148746166 420198270 517065752 906699795",
"output": "1034131504"
},
{
"input": "536870912 60000 72000 271828 314159",
"output": "4369119072"
},
{
"input": "730114139 21550542 204644733 680083361 11353255",
"output": "22476810678"
},
{
"input": "538228881 766493289 791886544 468896052 600136703",
"output": "0"
},
{
"input": "190 20 50 84 172",
"output": "1188"
},
{
"input": "1000 5 10 80 90",
"output": "17000"
},
{
"input": "99999999 999999998 1 271828 314159",
"output": "31415899685841"
},
{
"input": "22 3 6 1243 1",
"output": "8701"
},
{
"input": "15 10 5 2 2",
"output": "6"
},
{
"input": "1000000000 1000000000 1 1000000000 1000000000",
"output": "1000000000000000000"
},
{
"input": "62 62 42 78 124",
"output": "202"
},
{
"input": "2 2 2 2 1",
"output": "2"
},
{
"input": "864351351 351 313 531 11",
"output": "1337898227"
},
{
"input": "26 3 6 1244 1",
"output": "9952"
},
{
"input": "1000 4 6 7 3",
"output": "1999"
},
{
"input": "134312 3 6 33333 1",
"output": "1492318410"
},
{
"input": "100 4 6 17 18",
"output": "577"
},
{
"input": "6 2 4 5 6",
"output": "16"
},
{
"input": "8 2 4 10 1",
"output": "40"
},
{
"input": "10 2 4 3 3",
"output": "15"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "1000"
},
{
"input": "123123 3 6 34312 2",
"output": "1408198792"
},
{
"input": "1000000000 25 5 999 999",
"output": "199800000000"
},
{
"input": "100 4 2 5 12",
"output": "600"
},
{
"input": "50 2 4 4 5",
"output": "112"
},
{
"input": "24 4 6 100 333",
"output": "1732"
},
{
"input": "216 24 36 10 100",
"output": "660"
},
{
"input": "50 6 4 3 8",
"output": "108"
},
{
"input": "146 76 2 178 192",
"output": "14016"
},
{
"input": "55 8 6 11 20",
"output": "224"
},
{
"input": "5 2 4 6 16",
"output": "22"
},
{
"input": "54 2 52 50 188",
"output": "1488"
},
{
"input": "536870912 60000000 72000000 271828 314159",
"output": "4101909"
},
{
"input": "1000000000 1000000000 1 1 100",
"output": "100000000000"
},
{
"input": "50 4 2 4 5",
"output": "125"
},
{
"input": "198 56 56 122 118",
"output": "366"
},
{
"input": "5 1000000000 1 12 15",
"output": "75"
},
{
"input": "1000 6 12 5 6",
"output": "913"
},
{
"input": "50 3 6 12 15",
"output": "216"
},
{
"input": "333 300 300 300 300",
"output": "300"
},
{
"input": "1 1000000000 1 1 2",
"output": "2"
},
{
"input": "188 110 110 200 78",
"output": "200"
},
{
"input": "100000 20 10 3 2",
"output": "25000"
},
{
"input": "100 2 4 1 10",
"output": "275"
},
{
"input": "1000000000 2 1000000000 1 1000000",
"output": "500999999"
},
{
"input": "20 3 6 5 7",
"output": "36"
},
{
"input": "50 4 6 4 5",
"output": "72"
},
{
"input": "96 46 4 174 156",
"output": "3936"
},
{
"input": "5 2 4 12 15",
"output": "27"
},
{
"input": "12 3 6 100 1",
"output": "400"
},
{
"input": "100 4 2 10 32",
"output": "1600"
},
{
"input": "1232 3 6 30000 3",
"output": "12300000"
},
{
"input": "20 3 6 5 4",
"output": "30"
},
{
"input": "100 6 15 11 29",
"output": "317"
},
{
"input": "10000000 4 8 100 200",
"output": "375000000"
},
{
"input": "1000000000 12 24 2 4",
"output": "249999998"
},
{
"input": "123 3 6 3000 1",
"output": "123000"
},
{
"input": "401523968 1536 2664 271828 314159",
"output": "117768531682"
},
{
"input": "9 2 4 3 5",
"output": "16"
},
{
"input": "999999999 724362018 772432019 46201854 20017479",
"output": "66219333"
},
{
"input": "100 2 4 1 1000",
"output": "25025"
},
{
"input": "50 2 4 1 1000",
"output": "12013"
},
{
"input": "1000000000 2 1 2 1",
"output": "1500000000"
},
{
"input": "1000000000 2005034 2005046 15 12",
"output": "13446"
},
{
"input": "1000000000 999999999 1000000000 1 1",
"output": "2"
},
{
"input": "999999999 500000000 1 100 1000",
"output": "999999999000"
},
{
"input": "50 8 6 3 4",
"output": "44"
},
{
"input": "1000000000 1 1 1000000000 1000000000",
"output": "1000000000000000000"
},
{
"input": "1000000000 999999862 999999818 15 12",
"output": "27"
},
{
"input": "1000000000 10000019 10000019 21 17",
"output": "2079"
},
{
"input": "20 6 4 8 2",
"output": "32"
},
{
"input": "1000000000 1000000000 1 1 1",
"output": "1000000000"
},
{
"input": "1000000000 12345678 123456789 1000000000 999999999",
"output": "88999999992"
},
{
"input": "1000000000 2 999999937 100000000 100000000",
"output": "50000000100000000"
},
{
"input": "1000000000 1 1 1000000000 999999999",
"output": "1000000000000000000"
},
{
"input": "1000000000 50001 100003 10 10",
"output": "299980"
},
{
"input": "1000000000 1000000000 3 1 1",
"output": "333333334"
},
{
"input": "10000 44 49 114 514",
"output": "130278"
},
{
"input": "30 5 15 2 1",
"output": "12"
},
{
"input": "20 2 4 1 1",
"output": "10"
},
{
"input": "100 8 12 5 6",
"output": "88"
}
] | 1,667,038,997 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 16 | 1,000 | 1,536,000 | import math
s = str(input()).split()
n = int(s[0])
a = int(s[1])
b = int(s[2])
p = int(s[3])
q = int(s[4])
ans = 0
for i in range(1, n+1):
if (i%a==0 and i%b==0):
if (p>q):
ans+=p
else:
ans+=q
elif i%a==0:
ans+=p
elif i%b==0:
ans+=q
print(ans)
| Title: Joty and Chocolate
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue.
After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue.
Note that she can paint tiles in any order she wants.
Given the required information, find the maximum number of chocolates Joty can get.
Input Specification:
The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109).
Output Specification:
Print the only integer *s* — the maximum number of chocolates Joty can get.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Demo Input:
['5 2 3 12 15\n', '20 2 3 3 5\n']
Demo Output:
['39\n', '51\n']
Note:
none | ```python
import math
s = str(input()).split()
n = int(s[0])
a = int(s[1])
b = int(s[2])
p = int(s[3])
q = int(s[4])
ans = 0
for i in range(1, n+1):
if (i%a==0 and i%b==0):
if (p>q):
ans+=p
else:
ans+=q
elif i%a==0:
ans+=p
elif i%b==0:
ans+=q
print(ans)
``` | 0 |
|
733 | A | Grasshopper And the String | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump.
Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability.
The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'. | The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100. | Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels. | [
"ABABBBACFEYUKOTT\n",
"AAA\n"
] | [
"4",
"1"
] | none | 500 | [
{
"input": "ABABBBACFEYUKOTT",
"output": "4"
},
{
"input": "AAA",
"output": "1"
},
{
"input": "A",
"output": "1"
},
{
"input": "B",
"output": "2"
},
{
"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU",
"output": "39"
},
{
"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIAEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOI",
"output": "1"
},
{
"input": "KMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVCKMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVC",
"output": "85"
},
{
"input": "QWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZ",
"output": "18"
},
{
"input": "PKLKBWTXVJ",
"output": "11"
},
{
"input": "CFHFPTGMOKXVLJJZJDQW",
"output": "12"
},
{
"input": "TXULTFSBUBFLRNQORMMULWNVLPWTYJXZBPBGAWNX",
"output": "9"
},
{
"input": "DAIUSEAUEUYUWEIOOEIOUYVYYOPEEWEBZOOOAOXUOIEUKYYOJOYAUYUUIYUXOUJLGIYEIIYUOCUAACRY",
"output": "4"
},
{
"input": "VRPHBNWNWVWBWMFJJDCTJQJDJBKSJRZLVQRVVFLTZFSGCGDXCWQVWWWMFVCQHPKXXVRKTGWGPSMQTPKNDQJHNSKLXPCXDJDQDZZD",
"output": "101"
},
{
"input": "SGDDFCDRDWGPNNFBBZZJSPXFYMZKPRXTCHVJSJJBWZXXQMDZBNKDHRGSRLGLRKPMWXNSXJPNJLDPXBSRCQMHJKPZNTPNTZXNPCJC",
"output": "76"
},
{
"input": "NVTQVNLGWFDBCBKSDLTBGWBMNQZWZQJWNGVCTCQBGWNTYJRDBPZJHXCXFMIXNRGSTXHQPCHNFQPCMDZWJGLJZWMRRFCVLBKDTDSC",
"output": "45"
},
{
"input": "SREZXQFVPQCLRCQGMKXCBRWKYZKWKRMZGXPMKWNMFZTRDPHJFCSXVPPXWKZMZTBFXGNLPLHZIPLFXNRRQFDTLFPKBGCXKTMCFKKT",
"output": "48"
},
{
"input": "ICKJKMVPDNZPLKDSLTPZNRLSQSGHQJQQPJJSNHNWVDLJRLZEJSXZDPHYXGGWXHLCTVQSKWNWGTLJMOZVJNZPVXGVPJKHFVZTGCCX",
"output": "47"
},
{
"input": "XXFPZDRPXLNHGDVCBDKJMKLGUQZXLLWYLOKFZVGXVNPJWZZZNRMQBRJCZTSDRHSNCVDMHKVXCXPCRBWSJCJWDRDPVZZLCZRTDRYA",
"output": "65"
},
{
"input": "HDDRZDKCHHHEDKHZMXQSNQGSGNNSCCPVJFGXGNCEKJMRKSGKAPQWPCWXXWHLSMRGSJWEHWQCSJJSGLQJXGVTBYALWMLKTTJMFPFS",
"output": "28"
},
{
"input": "PXVKJHXVDPWGLHWFWMJPMCCNHCKSHCPZXGIHHNMYNFQBUCKJJTXXJGKRNVRTQFDFMLLGPQKFOVNNLTNDIEXSARRJKGSCZKGGJCBW",
"output": "35"
},
{
"input": "EXNMTTFPJLDHXDQBJJRDRYBZVFFHUDCHCPNFZWXSMZXNFVJGHZWXVBRQFNUIDVLZOVPXQNVMFNBTJDSCKRLNGXPSADTGCAHCBJKL",
"output": "30"
},
{
"input": "NRNLSQQJGIJBCZFTNKJCXMGPARGWXPSHZXOBNSFOLDQVXTVAGJZNLXULHBRDGMNQKQGWMRRDPYCSNFVPUFTFBUBRXVJGNGSPJKLL",
"output": "19"
},
{
"input": "SRHOKCHQQMVZKTCVQXJJCFGYFXGMBZSZFNAFETXILZHPGHBWZRZQFMGSEYRUDVMCIQTXTBTSGFTHRRNGNTHHWWHCTDFHSVARMCMB",
"output": "30"
},
{
"input": "HBSVZHDKGNIRQUBYKYHUPJCEETGFMVBZJTHYHFQPFBVBSMQACYAVWZXSBGNKWXFNMQJFMSCHJVWBZXZGSNBRUHTHAJKVLEXFBOFB",
"output": "34"
},
{
"input": "NXKMUGOPTUQNSRYTKUKSCWCRQSZKKFPYUMDIBJAHJCEKZJVWZAWOLOEFBFXLQDDPNNZKCQHUPBFVDSXSUCVLMZXQROYQYIKPQPWR",
"output": "17"
},
{
"input": "TEHJDICFNOLQVQOAREVAGUAWODOCXJXIHYXFAEPEXRHPKEIIRCRIVASKNTVYUYDMUQKSTSSBYCDVZKDDHTSDWJWACPCLYYOXGCLT",
"output": "15"
},
{
"input": "LCJJUZZFEIUTMSEXEYNOOAIZMORQDOANAMUCYTFRARDCYHOYOPHGGYUNOGNXUAOYSEMXAZOOOFAVHQUBRNGORSPNQWZJYQQUNPEB",
"output": "9"
},
{
"input": "UUOKAOOJBXUTSMOLOOOOSUYYFTAVBNUXYFVOOGCGZYQEOYISIYOUULUAIJUYVVOENJDOCLHOSOHIHDEJOIGZNIXEMEGZACHUAQFW",
"output": "5"
},
{
"input": "OUUBEHXOOURMOAIAEHXCUOIYHUJEVAWYRCIIAGDRIPUIPAIUYAIWJEVYEYYUYBYOGVYESUJCFOJNUAHIOOKBUUHEJFEWPOEOUHYA",
"output": "4"
},
{
"input": "EMNOYEEUIOUHEWZITIAEZNCJUOUAOQEAUYEIHYUSUYUUUIAEDIOOERAEIRBOJIEVOMECOGAIAIUIYYUWYIHIOWVIJEYUEAFYULSE",
"output": "5"
},
{
"input": "BVOYEAYOIEYOREJUYEUOEOYIISYAEOUYAAOIOEOYOOOIEFUAEAAESUOOIIEUAAGAEISIAPYAHOOEYUJHUECGOYEIDAIRTBHOYOYA",
"output": "5"
},
{
"input": "GOIEOAYIEYYOOEOAIAEOOUWYEIOTNYAANAYOOXEEOEAVIOIAAIEOIAUIAIAAUEUAOIAEUOUUZYIYAIEUEGOOOOUEIYAEOSYAEYIO",
"output": "3"
},
{
"input": "AUEAOAYIAOYYIUIOAULIOEUEYAIEYYIUOEOEIEYRIYAYEYAEIIMMAAEAYAAAAEOUICAUAYOUIAOUIAIUOYEOEEYAEYEYAAEAOYIY",
"output": "3"
},
{
"input": "OAIIYEYYAOOEIUOEEIOUOIAEFIOAYETUYIOAAAEYYOYEYOEAUIIUEYAYYIIAOIEEYGYIEAAOOWYAIEYYYIAOUUOAIAYAYYOEUEOY",
"output": "2"
},
{
"input": "EEEAOEOEEIOUUUEUEAAOEOIUYJEYAIYIEIYYEAUOIIYIUOOEUCYEOOOYYYIUUAYIAOEUEIEAOUOIAACAOOUAUIYYEAAAOOUYIAAE",
"output": "2"
},
{
"input": "AYEYIIEUIYOYAYEUEIIIEUYUUAUEUIYAIAAUYONIEYIUIAEUUOUOYYOUUUIUIAEYEOUIIUOUUEOAIUUYAAEOAAEOYUUIYAYRAIII",
"output": "2"
},
{
"input": "YOOAAUUAAAYEUYIUIUYIUOUAEIEEIAUEOAUIIAAIUYEUUOYUIYEAYAAAYUEEOEEAEOEEYYOUAEUYEEAIIYEUEYJOIIYUIOIUOIEE",
"output": "2"
},
{
"input": "UYOIIIAYOOAIUUOOEEUYIOUAEOOEIOUIAIEYOAEAIOOEOOOIUYYUYIAAUIOUYYOOUAUIEYYUOAAUUEAAIEUIAUEUUIAUUOYOAYIU",
"output": "1"
},
{
"input": "ABBABBB",
"output": "4"
},
{
"input": "ABCD",
"output": "4"
},
{
"input": "XXYC",
"output": "3"
},
{
"input": "YYY",
"output": "1"
},
{
"input": "ABABBBBBBB",
"output": "8"
},
{
"input": "YYYY",
"output": "1"
},
{
"input": "YYYYY",
"output": "1"
},
{
"input": "AXXX",
"output": "4"
},
{
"input": "YYYYYYY",
"output": "1"
},
{
"input": "BYYBBB",
"output": "4"
},
{
"input": "YYYYYYYYY",
"output": "1"
},
{
"input": "CAAAAA",
"output": "2"
},
{
"input": "CCCACCCC",
"output": "5"
},
{
"input": "ABABBBACFEYUKOTTTT",
"output": "5"
},
{
"input": "AABBYYYYYYYY",
"output": "3"
},
{
"input": "BYBACYC",
"output": "2"
},
{
"input": "Y",
"output": "1"
},
{
"input": "ABBBBBB",
"output": "7"
},
{
"input": "BACDYDI",
"output": "3"
},
{
"input": "XEXXXXXXXXXXXXXXX",
"output": "16"
},
{
"input": "TTYTT",
"output": "3"
},
{
"input": "AAYBC",
"output": "3"
},
{
"input": "ABABBBACFEYUKOTTTTT",
"output": "6"
},
{
"input": "YYAYY",
"output": "1"
},
{
"input": "YZZY",
"output": "3"
},
{
"input": "YY",
"output": "1"
},
{
"input": "ZZYZZ",
"output": "3"
},
{
"input": "YBBBY",
"output": "4"
},
{
"input": "BBBACCCCCCC",
"output": "8"
},
{
"input": "YBBBBY",
"output": "5"
},
{
"input": "YYYYYYYYYY",
"output": "1"
},
{
"input": "ABABBBBBBBBBBBB",
"output": "13"
}
] | 1,654,269,194 | 2,147,483,647 | Python 3 | OK | TESTS | 70 | 46 | 0 | v = "AEIOUY"
s = "A" + input() + "A"
x = 0 #begin
y = 0
e = 0 #ans
for i in range(1, len(s)):
if s[i] in v:
x = i
te = x-y
y = x
if te > e:
e = te
print(e) | Title: Grasshopper And the String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump.
Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability.
The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.
Input Specification:
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
Output Specification:
Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
Demo Input:
['ABABBBACFEYUKOTT\n', 'AAA\n']
Demo Output:
['4', '1']
Note:
none | ```python
v = "AEIOUY"
s = "A" + input() + "A"
x = 0 #begin
y = 0
e = 0 #ans
for i in range(1, len(s)):
if s[i] in v:
x = i
te = x-y
y = x
if te > e:
e = te
print(e)
``` | 3 |
|
576 | A | Vasya and Petya's Game | PROGRAMMING | 1,500 | [
"math",
"number theory"
] | null | null | Vasya and Petya are playing a simple game. Vasya thought of number *x* between 1 and *n*, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number *y*?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of.
Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers *y**i*, he should ask the questions about. | A single line contains number *n* (1<=≤<=*n*<=≤<=103). | Print the length of the sequence of questions *k* (0<=≤<=*k*<=≤<=*n*), followed by *k* numbers — the questions *y**i* (1<=≤<=*y**i*<=≤<=*n*).
If there are several correct sequences of questions of the minimum length, you are allowed to print any of them. | [
"4\n",
"6\n"
] | [
"3\n2 4 3 \n",
"4\n2 4 3 5 \n"
] | The sequence from the answer to the first sample test is actually correct.
If the unknown number is not divisible by one of the sequence numbers, it is equal to 1.
If the unknown number is divisible by 4, it is 4.
If the unknown number is divisible by 3, then the unknown number is 3.
Otherwise, it is equal to 2. Therefore, the sequence of questions allows you to guess the unknown number. It can be shown that there is no correct sequence of questions of length 2 or shorter. | 500 | [
{
"input": "4",
"output": "3\n2 4 3 "
},
{
"input": "6",
"output": "4\n2 4 3 5 "
},
{
"input": "1",
"output": "0"
},
{
"input": "15",
"output": "9\n2 4 8 3 9 5 7 11 13 "
},
{
"input": "19",
"output": "12\n2 4 8 16 3 9 5 7 11 13 17 19 "
},
{
"input": "20",
"output": "12\n2 4 8 16 3 9 5 7 11 13 17 19 "
},
{
"input": "37",
"output": "19\n2 4 8 16 32 3 9 27 5 25 7 11 13 17 19 23 29 31 37 "
},
{
"input": "211",
"output": "61\n2 4 8 16 32 64 128 3 9 27 81 5 25 125 7 49 11 121 13 169 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 "
},
{
"input": "557",
"output": "123\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 5 25 125 7 49 343 11 121 13 169 17 289 19 361 23 529 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 "
},
{
"input": "907",
"output": "179\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 ..."
},
{
"input": "953",
"output": "186\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 ..."
},
{
"input": "289",
"output": "78\n2 4 8 16 32 64 128 256 3 9 27 81 243 5 25 125 7 49 11 121 13 169 17 289 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 "
},
{
"input": "400",
"output": "97\n2 4 8 16 32 64 128 256 3 9 27 81 243 5 25 125 7 49 343 11 121 13 169 17 289 19 361 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 "
},
{
"input": "900",
"output": "178\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 ..."
},
{
"input": "625",
"output": "136\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 "
},
{
"input": "729",
"output": "152\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 ..."
},
{
"input": "784",
"output": "160\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 ..."
},
{
"input": "31",
"output": "17\n2 4 8 16 3 9 27 5 25 7 11 13 17 19 23 29 31 "
},
{
"input": "44",
"output": "21\n2 4 8 16 32 3 9 27 5 25 7 11 13 17 19 23 29 31 37 41 43 "
},
{
"input": "160",
"output": "50\n2 4 8 16 32 64 128 3 9 27 81 5 25 125 7 49 11 121 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 "
},
{
"input": "322",
"output": "83\n2 4 8 16 32 64 128 256 3 9 27 81 243 5 25 125 7 49 11 121 13 169 17 289 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 "
},
{
"input": "894",
"output": "178\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 ..."
},
{
"input": "998",
"output": "193\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 961 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 ..."
},
{
"input": "1000",
"output": "193\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 961 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 ..."
},
{
"input": "1000",
"output": "193\n2 4 8 16 32 64 128 256 512 3 9 27 81 243 729 5 25 125 625 7 49 343 11 121 13 169 17 289 19 361 23 529 29 841 31 961 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 ..."
},
{
"input": "30",
"output": "16\n2 4 8 16 3 9 27 5 25 7 11 13 17 19 23 29 "
}
] | 1,579,202,772 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 140 | 1,228,800 | MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
l=[]
for i in range(2,10**3+1):
fg=0
for j in range(2,i):
if i%j==0:
fg=1
break
if fg==0:
l.append(i)
n=ii()
ans=[]
for i in l:
if i>=n:
break
if n%i==0:
x=i
while n%x==0:
ans.append(x)
x*=i
if x<=n:
ans.append(x)
else:
ans.append(i)
print(len(ans))
print(*ans) | Title: Vasya and Petya's Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya and Petya are playing a simple game. Vasya thought of number *x* between 1 and *n*, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number *y*?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of.
Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers *y**i*, he should ask the questions about.
Input Specification:
A single line contains number *n* (1<=≤<=*n*<=≤<=103).
Output Specification:
Print the length of the sequence of questions *k* (0<=≤<=*k*<=≤<=*n*), followed by *k* numbers — the questions *y**i* (1<=≤<=*y**i*<=≤<=*n*).
If there are several correct sequences of questions of the minimum length, you are allowed to print any of them.
Demo Input:
['4\n', '6\n']
Demo Output:
['3\n2 4 3 \n', '4\n2 4 3 5 \n']
Note:
The sequence from the answer to the first sample test is actually correct.
If the unknown number is not divisible by one of the sequence numbers, it is equal to 1.
If the unknown number is divisible by 4, it is 4.
If the unknown number is divisible by 3, then the unknown number is 3.
Otherwise, it is equal to 2. Therefore, the sequence of questions allows you to guess the unknown number. It can be shown that there is no correct sequence of questions of length 2 or shorter. | ```python
MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
l=[]
for i in range(2,10**3+1):
fg=0
for j in range(2,i):
if i%j==0:
fg=1
break
if fg==0:
l.append(i)
n=ii()
ans=[]
for i in l:
if i>=n:
break
if n%i==0:
x=i
while n%x==0:
ans.append(x)
x*=i
if x<=n:
ans.append(x)
else:
ans.append(i)
print(len(ans))
print(*ans)
``` | 0 |
|
592 | C | The Big Race | PROGRAMMING | 1,800 | [
"math"
] | null | null | Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While watching previous races the organizers have noticed that Willman can perform only steps of length equal to *w* meters, and Bolt can perform only steps of length equal to *b* meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).
Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance *L*.
Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to *t* (both are included). What is the probability that Willman and Bolt tie again today? | The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively. | Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*. | [
"10 3 2\n",
"7 1 2\n"
] | [
"3/10\n",
"3/7\n"
] | In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack. | 1,500 | [
{
"input": "10 3 2",
"output": "3/10"
},
{
"input": "7 1 2",
"output": "3/7"
},
{
"input": "1 1 1",
"output": "1/1"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 813 766",
"output": "765/94268"
},
{
"input": "262610 5583 4717",
"output": "2358/131305"
},
{
"input": "3898439 96326 71937",
"output": "71936/3898439"
},
{
"input": "257593781689876390 32561717 4411677",
"output": "7914548537/257593781689876390"
},
{
"input": "111319886766128339 7862842484895022 3003994959686829",
"output": "3003994959686828/111319886766128339"
},
{
"input": "413850294331656955 570110918058849723 409853735661743839",
"output": "409853735661743838/413850294331656955"
},
{
"input": "3000000000000000000 2999999999999999873 2999999999999999977",
"output": "23437499999999999/23437500000000000"
},
{
"input": "9 6 1",
"output": "1/9"
},
{
"input": "32 9 2",
"output": "3/32"
},
{
"input": "976 5 6",
"output": "41/244"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 714 345",
"output": "689/94268"
},
{
"input": "262610 5583 4717",
"output": "2358/131305"
},
{
"input": "3898439 96326 71937",
"output": "71936/3898439"
},
{
"input": "54682301 778668 253103",
"output": "253102/54682301"
},
{
"input": "329245015 1173508 8918834",
"output": "1173507/329245015"
},
{
"input": "321076647734423976 7 7",
"output": "1/1"
},
{
"input": "455227494055672047 92 28",
"output": "19792499741550983/455227494055672047"
},
{
"input": "595779167455745259 6954 8697",
"output": "205511958419723/595779167455745259"
},
{
"input": "1000000000000000000 1000000000 2000000000",
"output": "1/2"
},
{
"input": "462643382718281828 462643382718281507 462643382718281701",
"output": "33045955908448679/33045955908448702"
},
{
"input": "4000000000000000000 9999999999999997 99999999999999999",
"output": "2499999999999999/1000000000000000000"
},
{
"input": "4003000100004000000 9999999099999999 99999999999999999",
"output": "4999999549999999/2001500050002000000"
},
{
"input": "4903000100004000000 58997960959949999 99933992929999999",
"output": "29498980479974999/2451500050002000000"
},
{
"input": "257593781689876390 32561717 4411677",
"output": "7914548537/257593781689876390"
},
{
"input": "111319886766128339 7862842484895022 3003994959686829",
"output": "3003994959686828/111319886766128339"
},
{
"input": "413850294331656955 570110918058849723 409853735661743839",
"output": "409853735661743838/413850294331656955"
},
{
"input": "232 17 83",
"output": "2/29"
},
{
"input": "5496272 63 200",
"output": "13765/2748136"
},
{
"input": "180 174 53",
"output": "13/45"
},
{
"input": "1954 190 537",
"output": "189/1954"
},
{
"input": "146752429 510 514",
"output": "571199/146752429"
},
{
"input": "579312860 55 70",
"output": "10344881/144828215"
},
{
"input": "1 9 9",
"output": "1/1"
},
{
"input": "95 19 19",
"output": "1/1"
},
{
"input": "404 63 441",
"output": "31/202"
},
{
"input": "5566 4798 4798",
"output": "1/1"
},
{
"input": "118289676 570846883 570846883",
"output": "1/1"
},
{
"input": "763 358 358",
"output": "1/1"
},
{
"input": "85356138 7223 482120804",
"output": "3611/42678069"
},
{
"input": "674664088 435395270 5",
"output": "9/674664088"
},
{
"input": "762200126044291557 370330636048898430 6",
"output": "17/762200126044291557"
},
{
"input": "917148533938841535 47 344459175789842163",
"output": "28/183429706787768307"
},
{
"input": "360212127113008697 877228952036215545 5259",
"output": "5258/360212127113008697"
},
{
"input": "683705963104411677 89876390 116741460012229240",
"output": "539258339/683705963104411677"
},
{
"input": "573003994959686829 275856334120822851 1319886766128339",
"output": "3959660298385016/573003994959686829"
},
{
"input": "409853735661743839 413850294331656955 413850294331656955",
"output": "1/1"
},
{
"input": "19 1 19",
"output": "1/19"
},
{
"input": "576 18 32",
"output": "1/16"
},
{
"input": "9540 10 954",
"output": "1/477"
},
{
"input": "101997840 6 16999640",
"output": "1/8499820"
},
{
"input": "955944 1278 748",
"output": "1/639"
},
{
"input": "482120804 66748 7223",
"output": "1/66748"
},
{
"input": "370330636048898430 61721772674816405 6",
"output": "1/61721772674816405"
},
{
"input": "344459175789842163 7328918633826429 47",
"output": "1/7328918633826429"
},
{
"input": "877228952036215545 166805277055755 5259",
"output": "1/55601759018585"
},
{
"input": "116741460012229240 1298911316 89876390",
"output": "1/649455658"
},
{
"input": "275856334120822851 209 1319886766128339",
"output": "1/1319886766128339"
},
{
"input": "413850294331656955 1 413850294331656955",
"output": "1/413850294331656955"
},
{
"input": "54682301 778668 253103",
"output": "253102/54682301"
},
{
"input": "329245015 3931027 6443236",
"output": "357366/29931365"
},
{
"input": "321076647734423976 7 8",
"output": "1672274206950125/13378193655600999"
},
{
"input": "455227494055672047 71 60",
"output": "6411654845854559/455227494055672047"
},
{
"input": "595779167455745259 9741 9331",
"output": "61162012885196/595779167455745259"
},
{
"input": "6470 80 160",
"output": "327/647"
},
{
"input": "686325 828 1656",
"output": "114511/228775"
},
{
"input": "4535304 2129 4258",
"output": "755973/1511768"
},
{
"input": "40525189 6365 12730",
"output": "20265394/40525189"
},
{
"input": "675297075 25986 51972",
"output": "112553659/225099025"
},
{
"input": "5681598412 75376 226128",
"output": "1893897375/5681598412"
},
{
"input": "384118571739435733 619773000 1859319000",
"output": "128039524053435733/384118571739435733"
},
{
"input": "391554751752251913 625743359 1877230077",
"output": "130518250652782079/391554751752251913"
},
{
"input": "390728504279201198 625082797 1250165594",
"output": "195364252413988195/390728504279201198"
},
{
"input": "389902265396085075 624421544 1248843088",
"output": "64983710976697837/129967421798695025"
},
{
"input": "734812071040507372 857211800 2571635400",
"output": "61234339274051543/183703017760126843"
},
{
"input": "1 1 2",
"output": "0/1"
},
{
"input": "3 1 4",
"output": "0/1"
},
{
"input": "8 2 3",
"output": "3/8"
},
{
"input": "64 32 16",
"output": "1/2"
},
{
"input": "1 1 1000000000",
"output": "0/1"
},
{
"input": "1000000000 1 1",
"output": "1/1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1/1"
},
{
"input": "1000000000 2 4",
"output": "1/2"
},
{
"input": "1000000000 123 456",
"output": "6579023/1000000000"
},
{
"input": "1000000000 123123 654",
"output": "24851/1000000000"
},
{
"input": "123456 123 456",
"output": "215/30864"
},
{
"input": "123456 1234567 123",
"output": "61/61728"
},
{
"input": "314159265 271 8281",
"output": "37939/314159265"
},
{
"input": "11071994 4231 1324",
"output": "2647/11071994"
},
{
"input": "961748927 961748941 982451653",
"output": "1/1"
},
{
"input": "15485221 1259 90863",
"output": "1258/15485221"
},
{
"input": "5000000000000000000 4999999999999999837 4999999999999999963",
"output": "1249999999999999959/1250000000000000000"
},
{
"input": "4000000000000000000 3999999999999999691 3999999999999999887",
"output": "399999999999999969/400000000000000000"
},
{
"input": "999999999999999999 999999999999999709 999999999999999737",
"output": "333333333333333236/333333333333333333"
},
{
"input": "799999999999999999 799999999999999969 799999999999999991",
"output": "799999999999999968/799999999999999999"
},
{
"input": "812312312312312222 812312312312311897 812312312312312029",
"output": "406156156156155948/406156156156156111"
},
{
"input": "500000000000000000 499999999999999927 499999999999999931",
"output": "249999999999999963/250000000000000000"
},
{
"input": "555555555555555555 555555555555555083 555555555555555229",
"output": "50505050505050462/50505050505050505"
},
{
"input": "199419941994199419 199419941994199369 199419941994199391",
"output": "66473313998066456/66473313998066473"
},
{
"input": "145685485411238588 145685485411238483 145685485411238573",
"output": "72842742705619241/72842742705619294"
},
{
"input": "314159265358979323 314159265358979167 314159265358979213",
"output": "314159265358979166/314159265358979323"
},
{
"input": "10 1000000000000000000 1000000000000000001",
"output": "1/1"
},
{
"input": "5 100000000000000000 99999999999999999",
"output": "1/1"
},
{
"input": "5 1000000000000 1000000000001",
"output": "1/1"
},
{
"input": "5 1000000000000000000 1000000000000000001",
"output": "1/1"
},
{
"input": "2 1000000000000000000 1000000000000000001",
"output": "1/1"
},
{
"input": "2 10 11",
"output": "1/1"
},
{
"input": "10 123456789123456789 723456789123456781",
"output": "1/1"
},
{
"input": "12345678910 123456789101112131 123456789101112132",
"output": "1/1"
},
{
"input": "5 499999999999999999 499999999999999998",
"output": "1/1"
}
] | 1,446,314,315 | 5,315 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 7 | 1,000 | 98,304,000 | t, w, b = map(int, input().split())
x = min(w, b)-1
possibles = [ i for i in range(1, x+1) ]
from fractions import gcd, Fraction
g = gcd(w,b)
y = w*b/g
if y <= t:
possibles.append(int(y))
(a, b) = divmod(t, y)
count = int(len(possibles)*a)
if b != 0:
for possible in possibles:
if possible > b:
break
count += 1
if count == t:
print("1/1")
else:
x = Fraction(count, t)
print(x) | Title: The Big Race
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While watching previous races the organizers have noticed that Willman can perform only steps of length equal to *w* meters, and Bolt can perform only steps of length equal to *b* meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).
Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance *L*.
Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to *t* (both are included). What is the probability that Willman and Bolt tie again today?
Input Specification:
The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.
Output Specification:
Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*.
Demo Input:
['10 3 2\n', '7 1 2\n']
Demo Output:
['3/10\n', '3/7\n']
Note:
In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack. | ```python
t, w, b = map(int, input().split())
x = min(w, b)-1
possibles = [ i for i in range(1, x+1) ]
from fractions import gcd, Fraction
g = gcd(w,b)
y = w*b/g
if y <= t:
possibles.append(int(y))
(a, b) = divmod(t, y)
count = int(len(possibles)*a)
if b != 0:
for possible in possibles:
if possible > b:
break
count += 1
if count == t:
print("1/1")
else:
x = Fraction(count, t)
print(x)
``` | 0 |
|
448 | D | Multiplication Table | PROGRAMMING | 1,800 | [
"binary search",
"brute force"
] | null | null | Bizon the Champion isn't just charming, he also is very smart.
While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an *n*<=×<=*m* multiplication table, where the element on the intersection of the *i*-th row and *j*-th column equals *i*·*j* (the rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table is the *k*-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success?
Consider the given multiplication table. If you write out all *n*·*m* numbers from the table in the non-decreasing order, then the *k*-th number you write out is called the *k*-th largest number. | The single line contains integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=5·105; 1<=≤<=*k*<=≤<=*n*·*m*). | Print the *k*-th largest number in a *n*<=×<=*m* multiplication table. | [
"2 2 2\n",
"2 3 4\n",
"1 10 5\n"
] | [
"2\n",
"3\n",
"5\n"
] | A 2 × 3 multiplication table looks like this: | 2,000 | [
{
"input": "2 2 2",
"output": "2"
},
{
"input": "2 3 4",
"output": "3"
},
{
"input": "1 10 5",
"output": "5"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "10 1 7",
"output": "7"
},
{
"input": "10 10 33",
"output": "14"
},
{
"input": "500000 500000 1",
"output": "1"
},
{
"input": "500000 500000 250000000000",
"output": "250000000000"
},
{
"input": "3 3 1",
"output": "1"
},
{
"input": "3 3 2",
"output": "2"
},
{
"input": "3 3 3",
"output": "2"
},
{
"input": "3 3 5",
"output": "3"
},
{
"input": "3 3 8",
"output": "6"
},
{
"input": "3 3 9",
"output": "9"
},
{
"input": "1 500000 74747",
"output": "74747"
},
{
"input": "500000 1 47474",
"output": "47474"
},
{
"input": "499975 499981 12345",
"output": "1634"
},
{
"input": "499997 499989 248758432143",
"output": "225563648440"
},
{
"input": "5 1 2",
"output": "2"
},
{
"input": "2 2 4",
"output": "4"
},
{
"input": "1 2 1",
"output": "1"
},
{
"input": "2 44 36",
"output": "24"
},
{
"input": "2 28 49",
"output": "42"
},
{
"input": "3 48 30",
"output": "17"
},
{
"input": "5 385 1296",
"output": "711"
},
{
"input": "1 454 340",
"output": "340"
},
{
"input": "1 450 399",
"output": "399"
},
{
"input": "1 3304 218",
"output": "218"
},
{
"input": "3 4175 661",
"output": "361"
},
{
"input": "4 1796 2564",
"output": "1232"
},
{
"input": "2 33975 17369",
"output": "11580"
},
{
"input": "4 25555 45556",
"output": "21868"
},
{
"input": "5 17136 9220",
"output": "4039"
},
{
"input": "3 355632 94220",
"output": "51393"
},
{
"input": "5 353491 107977",
"output": "47290"
},
{
"input": "4 194790 114613",
"output": "55015"
},
{
"input": "47 5 157",
"output": "87"
},
{
"input": "26 5 79",
"output": "42"
},
{
"input": "40 2 3",
"output": "2"
},
{
"input": "12 28 127",
"output": "49"
},
{
"input": "32 12 132",
"output": "50"
},
{
"input": "48 40 937",
"output": "364"
},
{
"input": "45 317 6079",
"output": "2160"
},
{
"input": "18 459 7733",
"output": "5684"
},
{
"input": "38 127 1330",
"output": "404"
},
{
"input": "25 1155 9981",
"output": "3318"
},
{
"input": "41 4600 39636",
"output": "10865"
},
{
"input": "20 2222 11312",
"output": "3502"
},
{
"input": "32 11568 36460",
"output": "8988"
},
{
"input": "48 33111 5809",
"output": "1308"
},
{
"input": "27 24692 71714",
"output": "18432"
},
{
"input": "46 356143 2399416",
"output": "598032"
},
{
"input": "25 127045 1458997",
"output": "548779"
},
{
"input": "41 246624 2596292",
"output": "751716"
},
{
"input": "264 3 775",
"output": "741"
},
{
"input": "495 3 17",
"output": "10"
},
{
"input": "252 5 672",
"output": "328"
},
{
"input": "314 32 3903",
"output": "1345"
},
{
"input": "472 15 932",
"output": "283"
},
{
"input": "302 39 4623",
"output": "1589"
},
{
"input": "318 440 57023",
"output": "19203"
},
{
"input": "403 363 932",
"output": "175"
},
{
"input": "306 433 25754",
"output": "6500"
},
{
"input": "143 1735 246128",
"output": "218316"
},
{
"input": "447 4446 802918",
"output": "268036"
},
{
"input": "132 3890 439379",
"output": "265096"
},
{
"input": "366 45769 5885721",
"output": "1841004"
},
{
"input": "123 37349 4224986",
"output": "2895390"
},
{
"input": "427 46704 7152399",
"output": "2256408"
},
{
"input": "357 184324 28748161",
"output": "9992350"
},
{
"input": "187 425625 25103321",
"output": "7534560"
},
{
"input": "345 423483 40390152",
"output": "11441760"
},
{
"input": "4775 3 7798",
"output": "4254"
},
{
"input": "1035 2 2055",
"output": "2040"
},
{
"input": "3119 3 7305",
"output": "5024"
},
{
"input": "1140 18 11371",
"output": "4830"
},
{
"input": "4313 40 86640",
"output": "33496"
},
{
"input": "2396 24 55229",
"output": "43102"
},
{
"input": "2115 384 385536",
"output": "140250"
},
{
"input": "2376 308 665957",
"output": "445248"
},
{
"input": "4460 377 1197310",
"output": "581462"
},
{
"input": "2315 1673 225263",
"output": "40950"
},
{
"input": "1487 3295 736705",
"output": "169290"
},
{
"input": "3571 3828 7070865",
"output": "2696688"
},
{
"input": "3082 23173 68350097",
"output": "51543000"
},
{
"input": "1165 34678 7211566",
"output": "1745254"
},
{
"input": "1426 26259 37212278",
"output": "33359110"
},
{
"input": "2930 491026 923941798",
"output": "409544625"
},
{
"input": "3191 454046 718852491",
"output": "267275676"
},
{
"input": "1274 295345 301511265",
"output": "165699050"
},
{
"input": "10657 3 9816",
"output": "5355"
},
{
"input": "38939 3 6757",
"output": "3686"
},
{
"input": "37107 4 28350",
"output": "13608"
},
{
"input": "19618 16 313726",
"output": "311296"
},
{
"input": "27824 40 906786",
"output": "518185"
},
{
"input": "46068 31 424079",
"output": "131352"
},
{
"input": "40716 482 14569037",
"output": "7363656"
},
{
"input": "48922 150 653002",
"output": "135716"
},
{
"input": "37203 219 2355222",
"output": "681502"
},
{
"input": "23808 3322 48603931",
"output": "20824476"
},
{
"input": "12090 2766 12261436",
"output": "3894264"
},
{
"input": "20296 4388 29300901",
"output": "8862304"
},
{
"input": "29699 38801 37684232",
"output": "6032628"
},
{
"input": "17980 28231 221639883",
"output": "76707084"
},
{
"input": "16148 39736 239320912",
"output": "76569666"
},
{
"input": "35531 340928 9207622511",
"output": "4761654318"
},
{
"input": "43737 111829 865416726",
"output": "208223208"
},
{
"input": "21980 353130 2233068545",
"output": "638445948"
},
{
"input": "339697 4 1259155",
"output": "993876"
},
{
"input": "404625 2 132619",
"output": "88413"
},
{
"input": "226111 2 359116",
"output": "266010"
},
{
"input": "318377 38 7214261",
"output": "3108710"
},
{
"input": "139863 21 1834174",
"output": "833220"
},
{
"input": "204791 41 8382971",
"output": "8020256"
},
{
"input": "149281 382 51428462",
"output": "33762615"
},
{
"input": "370768 123 15161219",
"output": "4677246"
},
{
"input": "313975 448 85041752",
"output": "36070940"
},
{
"input": "136614 3211 364472869",
"output": "209750632"
},
{
"input": "201542 4833 512478332",
"output": "197440230"
},
{
"input": "423029 1365 126620483",
"output": "32780826"
},
{
"input": "110941 47433 2098952903",
"output": "693548595"
},
{
"input": "175869 39014 3201917805",
"output": "1148848775"
},
{
"input": "397356 10518 874806404",
"output": "222468766"
},
{
"input": "118728 168631 16269281609",
"output": "9092195490"
},
{
"input": "183656 409931 42943608085",
"output": "17438143800"
},
{
"input": "283422 407789 73398688052",
"output": "32237937640"
},
{
"input": "500000 500000 888888",
"output": "77856"
}
] | 1,632,343,027 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 6,963,200 | n, m, k = [int(i) for i in input().split()]
idx = 0
col = 1
i = 1
j = 1
curr = 0
while idx < k:
curr = i * j
i += 1
j -= 1
if j == 0 or i == n + 1:
col += 1
i = 1
j = col
idx += 1
print(curr) | Title: Multiplication Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion isn't just charming, he also is very smart.
While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an *n*<=×<=*m* multiplication table, where the element on the intersection of the *i*-th row and *j*-th column equals *i*·*j* (the rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table is the *k*-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success?
Consider the given multiplication table. If you write out all *n*·*m* numbers from the table in the non-decreasing order, then the *k*-th number you write out is called the *k*-th largest number.
Input Specification:
The single line contains integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=5·105; 1<=≤<=*k*<=≤<=*n*·*m*).
Output Specification:
Print the *k*-th largest number in a *n*<=×<=*m* multiplication table.
Demo Input:
['2 2 2\n', '2 3 4\n', '1 10 5\n']
Demo Output:
['2\n', '3\n', '5\n']
Note:
A 2 × 3 multiplication table looks like this: | ```python
n, m, k = [int(i) for i in input().split()]
idx = 0
col = 1
i = 1
j = 1
curr = 0
while idx < k:
curr = i * j
i += 1
j -= 1
if j == 0 or i == n + 1:
col += 1
i = 1
j = col
idx += 1
print(curr)
``` | 0 |
|
220 | A | Little Elephant and Problem | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array *a*, only if array *a* can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements.
Help the Little Elephant, determine if he could have accidentally changed the array *a*, sorted by non-decreasing, himself. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*.
Note that the elements of the array are not necessarily distinct numbers. | In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise. | [
"2\n1 2\n",
"3\n3 2 1\n",
"4\n4 3 2 1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES".
In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES".
In the third sample we can't sort the array in more than one swap operation, so the answer is "NO". | 500 | [
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n3 2 1",
"output": "YES"
},
{
"input": "4\n4 3 2 1",
"output": "NO"
},
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "2\n2 1",
"output": "YES"
},
{
"input": "9\n7 7 8 8 10 10 10 10 1000000000",
"output": "YES"
},
{
"input": "10\n1 2 9 4 5 6 7 8 3 10",
"output": "YES"
},
{
"input": "4\n2 2 2 1",
"output": "YES"
},
{
"input": "10\n1 2 4 4 4 5 5 7 7 10",
"output": "YES"
},
{
"input": "10\n4 5 11 12 13 14 16 16 16 18",
"output": "YES"
},
{
"input": "20\n38205814 119727790 127848638 189351562 742927936 284688399 318826601 326499046 387938139 395996609 494453625 551393005 561264192 573569187 600766727 606718722 730549586 261502770 751513115 943272321",
"output": "YES"
},
{
"input": "47\n6 277 329 393 410 432 434 505 529 545 650 896 949 1053 1543 1554 1599 1648 1927 1976 1998 2141 2248 2384 2542 2638 2995 3155 3216 3355 3409 3597 3851 3940 4169 4176 4378 4378 4425 4490 4627 4986 5025 5033 5374 5453 5644",
"output": "YES"
},
{
"input": "50\n6 7 8 4 10 3 2 7 1 3 10 3 4 7 2 3 7 4 10 6 8 10 9 6 5 10 9 6 1 8 9 4 3 7 3 10 5 3 10 1 6 10 6 7 10 7 1 5 9 5",
"output": "NO"
},
{
"input": "100\n3 7 7 8 15 25 26 31 37 41 43 43 46 64 65 82 94 102 102 103 107 124 125 131 140 145 146 150 151 160 160 161 162 165 169 175 182 191 201 211 214 216 218 304 224 229 236 241 244 249 252 269 270 271 273 289 285 295 222 307 312 317 319 319 320 321 325 330 340 341 345 347 354 356 366 366 375 376 380 383 386 398 401 407 414 417 423 426 431 438 440 444 446 454 457 458 458 466 466 472",
"output": "NO"
},
{
"input": "128\n1 2 4 6 8 17 20 20 23 33 43 49 49 49 52 73 74 75 82 84 85 87 90 91 102 103 104 105 111 111 401 142 142 152 155 160 175 176 178 181 183 184 187 188 191 193 326 202 202 214 224 225 236 239 240 243 246 247 249 249 257 257 261 264 265 271 277 281 284 284 286 289 290 296 297 303 305 307 307 317 318 320 322 200 332 342 393 349 350 350 369 375 381 381 385 385 387 393 347 397 398 115 402 407 407 408 410 411 411 416 423 426 429 429 430 440 447 449 463 464 466 471 473 480 480 483 497 503",
"output": "NO"
},
{
"input": "4\n5 12 12 6",
"output": "YES"
},
{
"input": "5\n1 3 3 3 2",
"output": "YES"
},
{
"input": "4\n2 1 1 1",
"output": "YES"
},
{
"input": "2\n1 1",
"output": "YES"
},
{
"input": "4\n1000000000 1 1000000000 1",
"output": "YES"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 1",
"output": "YES"
},
{
"input": "6\n1 2 3 4 5 3",
"output": "NO"
},
{
"input": "9\n3 3 3 2 2 2 1 1 1",
"output": "NO"
},
{
"input": "4\n4 1 2 3",
"output": "NO"
},
{
"input": "6\n3 4 5 6 7 2",
"output": "NO"
},
{
"input": "4\n4 2 1 3",
"output": "NO"
},
{
"input": "4\n3 3 2 2",
"output": "NO"
},
{
"input": "4\n3 2 1 1",
"output": "NO"
},
{
"input": "4\n4 5 1 1",
"output": "NO"
},
{
"input": "6\n1 6 2 4 3 5",
"output": "NO"
},
{
"input": "5\n1 4 5 2 3",
"output": "NO"
},
{
"input": "4\n2 2 1 1",
"output": "NO"
},
{
"input": "5\n1 4 3 2 1",
"output": "NO"
},
{
"input": "5\n1 4 2 2 3",
"output": "NO"
},
{
"input": "6\n1 2 3 1 2 3",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "NO"
},
{
"input": "5\n5 1 2 3 4",
"output": "NO"
},
{
"input": "5\n3 3 3 2 2",
"output": "NO"
},
{
"input": "5\n100 5 6 10 7",
"output": "NO"
},
{
"input": "3\n2 3 1",
"output": "NO"
},
{
"input": "5\n4 4 1 1 1",
"output": "NO"
},
{
"input": "5\n1 2 5 3 4",
"output": "NO"
},
{
"input": "4\n3 4 1 2",
"output": "NO"
},
{
"input": "4\n2 4 1 5",
"output": "NO"
},
{
"input": "5\n1 3 3 2 2",
"output": "NO"
},
{
"input": "5\n1 5 4 4 4",
"output": "YES"
},
{
"input": "7\n3 2 1 2 3 5 4",
"output": "NO"
},
{
"input": "5\n1 1 3 2 2",
"output": "YES"
},
{
"input": "9\n1 8 7 7 7 7 7 8 3",
"output": "YES"
},
{
"input": "5\n1 3 2 3 3",
"output": "YES"
},
{
"input": "10\n4 4 4 4 10 4 4 4 4 4",
"output": "YES"
},
{
"input": "8\n3 6 6 6 6 6 4 9",
"output": "YES"
},
{
"input": "4\n4 4 3 3",
"output": "NO"
},
{
"input": "4\n3 2 2 4",
"output": "YES"
},
{
"input": "5\n2 2 1 3 3",
"output": "YES"
},
{
"input": "5\n1 2 7 3 5",
"output": "NO"
},
{
"input": "5\n2 3 4 5 1",
"output": "NO"
},
{
"input": "6\n1 4 3 6 2 5",
"output": "NO"
},
{
"input": "5\n3 3 1 5 4",
"output": "NO"
},
{
"input": "4\n1 2 1 2",
"output": "YES"
},
{
"input": "6\n4 5 3 4 2 6",
"output": "NO"
},
{
"input": "11\n1 2 3 4 5 1 2 3 4 5 1",
"output": "NO"
},
{
"input": "6\n6 1 2 3 4 5",
"output": "NO"
},
{
"input": "5\n4 1 1 1 1",
"output": "YES"
},
{
"input": "9\n1 2 3 5 4 6 7 8 9",
"output": "YES"
},
{
"input": "6\n6 1 2 3 4 2",
"output": "NO"
},
{
"input": "6\n2 2 2 2 3 2",
"output": "YES"
},
{
"input": "3\n2 1 1",
"output": "YES"
},
{
"input": "5\n1 2 1 1 2",
"output": "YES"
},
{
"input": "5\n1 2 2 1 2",
"output": "YES"
},
{
"input": "8\n5 5 5 5 5 5 1 1",
"output": "NO"
}
] | 1,668,168,033 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 32 | 108 | 8,089,600 | n = int(input())
l = list(map(int, input().split()))
c = 0
for i in range(n-1):
if(l[i] > l[i+1]):
c += 1
if(c <= 2):
print("YES")
else:
print("NO") | Title: Little Elephant and Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array *a*, only if array *a* can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements.
Help the Little Elephant, determine if he could have accidentally changed the array *a*, sorted by non-decreasing, himself.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*.
Note that the elements of the array are not necessarily distinct numbers.
Output Specification:
In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise.
Demo Input:
['2\n1 2\n', '3\n3 2 1\n', '4\n4 3 2 1\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES".
In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES".
In the third sample we can't sort the array in more than one swap operation, so the answer is "NO". | ```python
n = int(input())
l = list(map(int, input().split()))
c = 0
for i in range(n-1):
if(l[i] > l[i+1]):
c += 1
if(c <= 2):
print("YES")
else:
print("NO")
``` | 0 |
|
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,641,260,684 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | def Main():
n, k = map(int, input().split())
sm = 0
arr = list(map(int, input().split()))
sm = sum(arr)
N = n
cnt = 0
while (sm + N // 2) // N < k:
sm += k
N += 1
cnt += 1
print(cnt) | 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
def Main():
n, k = map(int, input().split())
sm = 0
arr = list(map(int, input().split()))
sm = sum(arr)
N = n
cnt = 0
while (sm + N // 2) // N < k:
sm += k
N += 1
cnt += 1
print(cnt)
``` | 0 |
|
225 | C | Barcode | PROGRAMMING | 1,700 | [
"dp",
"matrices"
] | null | null | You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulfilled:
- All pixels in each column are of the same color. - The width of each monochrome vertical line is at least *x* and at most *y* pixels. In other words, if we group all neighbouring columns of the pixels with equal color, the size of each group can not be less than *x* or greater than *y*. | The first line contains four space-separated integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*,<=*x*,<=*y*<=≤<=1000; *x*<=≤<=*y*).
Then follow *n* lines, describing the original image. Each of these lines contains exactly *m* characters. Character "." represents a white pixel and "#" represents a black pixel. The picture description doesn't have any other characters besides "." and "#". | In the first line print the minimum number of pixels to repaint. It is guaranteed that the answer exists. | [
"6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..\n",
"2 5 1 1\n#####\n.....\n"
] | [
"11\n",
"5\n"
] | In the first test sample the picture after changing some colors can looks as follows:
In the second test sample the picture after changing some colors can looks as follows: | 1,500 | [
{
"input": "6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..",
"output": "11"
},
{
"input": "10 5 3 7\n.####\n###..\n##.##\n#..#.\n.#...\n#.##.\n.##..\n.#.##\n#.#..\n.#..#",
"output": "24"
},
{
"input": "6 3 1 4\n##.\n#..\n#..\n..#\n.#.\n#.#",
"output": "6"
},
{
"input": "5 10 4 16\n.#####....\n##..#..##.\n.#..##.#..\n##..#####.\n...#.##..#",
"output": "21"
},
{
"input": "5 4 1 4\n####\n..##\n##..\n..#.\n#..#",
"output": "8"
},
{
"input": "1 1 1 2\n.",
"output": "0"
},
{
"input": "3 44 2 18\n####..###.#.##........##...###.####.#.....##\n...#....##.###.###.##.#####.#######.#..#..#.\n#...#.####.#.##.#.#.#.....##.##..###.#....##",
"output": "39"
},
{
"input": "69 1 1 2\n#\n.\n#\n#\n.\n#\n#\n.\n.\n#\n.\n.\n#\n.\n#\n#\n.\n#\n#\n#\n#\n#\n.\n#\n.\n.\n#\n#\n#\n.\n.\n.\n.\n#\n#\n.\n#\n#\n.\n#\n.\n.\n#\n.\n.\n.\n#\n.\n.\n#\n#\n.\n.\n#\n.\n.\n.\n#\n#\n#\n#\n#\n.\n#\n.\n#\n#\n#\n#",
"output": "31"
},
{
"input": "56 2 2 2\n##\n##\n##\n..\n..\n##\n.#\n#.\n..\n##\n##\n..\n..\n#.\n#.\n#.\n#.\n##\n..\n.#\n..\n##\n##\n.#\n#.\n.#\n..\n..\n#.\n..\n##\n..\n#.\n.#\n#.\n#.\n#.\n##\n#.\n##\n##\n.#\n#.\n##\n..\n.#\n#.\n#.\n##\n..\n..\n#.\n##\n..\n..\n##",
"output": "55"
}
] | 1,635,163,279 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 4,608,000 | import sys
import os.path
if(os.path.exists('input.txt')) :
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
sys.stderr = open("error.txt", "w")
depth = 1000000
mod = 1000000007
lim = mod * mod
sys.setrecursionlimit(depth)
linp = lambda: list(minp())
minp = lambda: map(int, input().split())
from math import inf, ceil, sqrt, log2, gcd
from collections import defaultdict, deque
dxy = [(1, 0),(-1, 0),(0, 1),(0, -1)]
def solve(idx, curr, color) :
if idx == m : return 0
if dp[(idx, curr, color)] != -1 : return dp[(idx, curr, color)]
if curr < x :
ans = solve(idx+1, curr+1, color) + cost[idx][1-color]
elif curr < y :
v1 = solve(idx+1, curr+1, color) + cost[idx][1-color]
v2 = solve(idx+1, 1, 1-color) + cost[idx][color]
ans = min(v1, v2)
else :
ans = solve(idx+1, 1, 1-color) + cost[idx][color]
dp[(idx, curr, color)] = ans
return ans
n, m, x, y = minp()
mat, cost = list(), list()
for _ in range(n) :
mat.append(input())
for j in range(m) :
c = 0
for i in range(n) :
if mat[i][j] == "#" :
c += 1
cost.append((c, n-c))
dp = defaultdict(lambda: -1)
v1 = solve(0, 0, 0)
v2 = solve(0, 0, 1)
print(min(v1, v2)) | Title: Barcode
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulfilled:
- All pixels in each column are of the same color. - The width of each monochrome vertical line is at least *x* and at most *y* pixels. In other words, if we group all neighbouring columns of the pixels with equal color, the size of each group can not be less than *x* or greater than *y*.
Input Specification:
The first line contains four space-separated integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*,<=*x*,<=*y*<=≤<=1000; *x*<=≤<=*y*).
Then follow *n* lines, describing the original image. Each of these lines contains exactly *m* characters. Character "." represents a white pixel and "#" represents a black pixel. The picture description doesn't have any other characters besides "." and "#".
Output Specification:
In the first line print the minimum number of pixels to repaint. It is guaranteed that the answer exists.
Demo Input:
['6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..\n', '2 5 1 1\n#####\n.....\n']
Demo Output:
['11\n', '5\n']
Note:
In the first test sample the picture after changing some colors can looks as follows:
In the second test sample the picture after changing some colors can looks as follows: | ```python
import sys
import os.path
if(os.path.exists('input.txt')) :
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
sys.stderr = open("error.txt", "w")
depth = 1000000
mod = 1000000007
lim = mod * mod
sys.setrecursionlimit(depth)
linp = lambda: list(minp())
minp = lambda: map(int, input().split())
from math import inf, ceil, sqrt, log2, gcd
from collections import defaultdict, deque
dxy = [(1, 0),(-1, 0),(0, 1),(0, -1)]
def solve(idx, curr, color) :
if idx == m : return 0
if dp[(idx, curr, color)] != -1 : return dp[(idx, curr, color)]
if curr < x :
ans = solve(idx+1, curr+1, color) + cost[idx][1-color]
elif curr < y :
v1 = solve(idx+1, curr+1, color) + cost[idx][1-color]
v2 = solve(idx+1, 1, 1-color) + cost[idx][color]
ans = min(v1, v2)
else :
ans = solve(idx+1, 1, 1-color) + cost[idx][color]
dp[(idx, curr, color)] = ans
return ans
n, m, x, y = minp()
mat, cost = list(), list()
for _ in range(n) :
mat.append(input())
for j in range(m) :
c = 0
for i in range(n) :
if mat[i][j] == "#" :
c += 1
cost.append((c, n-c))
dp = defaultdict(lambda: -1)
v1 = solve(0, 0, 0)
v2 = solve(0, 0, 1)
print(min(v1, v2))
``` | 0 |
|
975 | C | Valhalla Siege | PROGRAMMING | 1,400 | [
"binary search"
] | null | null | Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. The first warrior leads the attack.
Each attacker can take up to $a_i$ arrows before he falls to the ground, where $a_i$ is the $i$-th warrior's strength.
Lagertha orders her warriors to shoot $k_i$ arrows during the $i$-th minute, the arrows one by one hit the first still standing warrior. After all Ivar's warriors fall and all the currently flying arrows fly by, Thor smashes his hammer and all Ivar's warriors get their previous strengths back and stand up to fight again. In other words, if all warriors die in minute $t$, they will all be standing to fight at the end of minute $t$.
The battle will last for $q$ minutes, after each minute you should tell Ivar what is the number of his standing warriors. | The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2, \ldots, k_q$ ($1 \leq k_i \leq 10^{14}$), the $i$-th of them represents Lagertha's order at the $i$-th minute: $k_i$ arrows will attack the warriors. | Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute. | [
"5 5\n1 2 1 2 1\n3 10 1 1 1\n",
"4 4\n1 2 3 4\n9 1 10 6\n"
] | [
"3\n5\n4\n4\n3\n",
"1\n4\n4\n1\n"
] | In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warrior takes a hit and his strength decreases by 1. - after the 5-th minute, the 2-nd warrior dies. | 1,500 | [
{
"input": "5 5\n1 2 1 2 1\n3 10 1 1 1",
"output": "3\n5\n4\n4\n3"
},
{
"input": "4 4\n1 2 3 4\n9 1 10 6",
"output": "1\n4\n4\n1"
},
{
"input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5",
"output": "10\n10\n5"
},
{
"input": "1 1\n56563128\n897699770",
"output": "1"
},
{
"input": "100 55\n1 2 4 4 3 5 5 2 3 4 2 1 1 2 3 5 1 5 4 2 5 4 4 3 3 5 3 4 4 5 5 2 3 3 4 4 3 4 5 5 5 5 3 5 1 2 4 3 4 5 3 3 2 1 4 5 3 4 4 1 5 1 5 2 2 1 4 5 3 3 1 4 2 5 4 5 3 2 5 5 2 3 2 3 2 2 3 4 4 4 1 4 2 4 5 3 1 3 3 1\n5 2 1 4 3 4 3 1 4 4 1 2 3 2 1 5 5 4 5 4 2 5 2 1 5 1 4 4 3 5 4 5 1 4 4 1 5 3 1 5 2 4 1 3 2 5 4 5 4 3 4 2 2 4 3",
"output": "98\n97\n97\n96\n95\n94\n94\n94\n92\n91\n91\n90\n87\n86\n86\n85\n83\n82\n80\n80\n79\n78\n77\n77\n75\n75\n74\n73\n72\n71\n70\n69\n69\n67\n66\n66\n65\n64\n63\n62\n62\n61\n61\n60\n60\n59\n58\n57\n54\n54\n52\n52\n51\n51\n50"
}
] | 1,534,186,168 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 1,653 | 21,504,000 | import math
from bisect import bisect_right
numWarriors,numMinutes = map(int,input().split(" "))
warriorsStrength = list(map(int,input().split(" ")))
arrowCount = list(map(int,input().split(" ")))
warriorsSumStrength = [0]*(numWarriors)
warriorsSumStrength[0] = warriorsStrength[0]
def find_gt(a,x,lo,hi):
#Find leftmost value grater than x
i = bisect_right(a,x,lo,hi)
if i != len(a):
return i
raise ValueError
for i in range(1,numWarriors):
warriorsSumStrength[i] = warriorsSumStrength[i-1] + warriorsStrength[i]
currWarrior = 0
currWarriorStrength = warriorsStrength[currWarrior]
for numArrows in arrowCount:
#print("currWarrior: ",currWarrior)
#print("currWarriorStrength: ",currWarriorStrength)
if currWarriorStrength >= numArrows:
currWarriorStrength -= numArrows
if currWarriorStrength == 0:
currWarrior += 1
if currWarrior == numWarriors:
currWarrior = 0
currWarriorStrength = warriorsStrength[currWarrior]
print(numWarriors-currWarrior)
continue
numArrows -= currWarriorStrength
if warriorsSumStrength[numWarriors-1] - warriorsSumStrength[currWarrior] <= numArrows:
currWarrior = 0
currWarriorStrength = warriorsStrength[currWarrior]
print(numWarriors-currWarrior)
continue
#print("numArrows: ",numArrows)
newWarrior = find_gt(warriorsSumStrength,numArrows+warriorsSumStrength[currWarrior],currWarrior+1,numWarriors)
#print("newWarrior: ",newWarrior)
#print("currWarrior: ",currWarrior)
currWarriorStrength = warriorsSumStrength[newWarrior]-warriorsSumStrength[currWarrior]-numArrows
#print("newWarriorStrength: ",currWarriorStrength)
currWarrior = newWarrior
print(numWarriors-currWarrior)
| Title: Valhalla Siege
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. The first warrior leads the attack.
Each attacker can take up to $a_i$ arrows before he falls to the ground, where $a_i$ is the $i$-th warrior's strength.
Lagertha orders her warriors to shoot $k_i$ arrows during the $i$-th minute, the arrows one by one hit the first still standing warrior. After all Ivar's warriors fall and all the currently flying arrows fly by, Thor smashes his hammer and all Ivar's warriors get their previous strengths back and stand up to fight again. In other words, if all warriors die in minute $t$, they will all be standing to fight at the end of minute $t$.
The battle will last for $q$ minutes, after each minute you should tell Ivar what is the number of his standing warriors.
Input Specification:
The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2, \ldots, k_q$ ($1 \leq k_i \leq 10^{14}$), the $i$-th of them represents Lagertha's order at the $i$-th minute: $k_i$ arrows will attack the warriors.
Output Specification:
Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute.
Demo Input:
['5 5\n1 2 1 2 1\n3 10 1 1 1\n', '4 4\n1 2 3 4\n9 1 10 6\n']
Demo Output:
['3\n5\n4\n4\n3\n', '1\n4\n4\n1\n']
Note:
In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warrior takes a hit and his strength decreases by 1. - after the 5-th minute, the 2-nd warrior dies. | ```python
import math
from bisect import bisect_right
numWarriors,numMinutes = map(int,input().split(" "))
warriorsStrength = list(map(int,input().split(" ")))
arrowCount = list(map(int,input().split(" ")))
warriorsSumStrength = [0]*(numWarriors)
warriorsSumStrength[0] = warriorsStrength[0]
def find_gt(a,x,lo,hi):
#Find leftmost value grater than x
i = bisect_right(a,x,lo,hi)
if i != len(a):
return i
raise ValueError
for i in range(1,numWarriors):
warriorsSumStrength[i] = warriorsSumStrength[i-1] + warriorsStrength[i]
currWarrior = 0
currWarriorStrength = warriorsStrength[currWarrior]
for numArrows in arrowCount:
#print("currWarrior: ",currWarrior)
#print("currWarriorStrength: ",currWarriorStrength)
if currWarriorStrength >= numArrows:
currWarriorStrength -= numArrows
if currWarriorStrength == 0:
currWarrior += 1
if currWarrior == numWarriors:
currWarrior = 0
currWarriorStrength = warriorsStrength[currWarrior]
print(numWarriors-currWarrior)
continue
numArrows -= currWarriorStrength
if warriorsSumStrength[numWarriors-1] - warriorsSumStrength[currWarrior] <= numArrows:
currWarrior = 0
currWarriorStrength = warriorsStrength[currWarrior]
print(numWarriors-currWarrior)
continue
#print("numArrows: ",numArrows)
newWarrior = find_gt(warriorsSumStrength,numArrows+warriorsSumStrength[currWarrior],currWarrior+1,numWarriors)
#print("newWarrior: ",newWarrior)
#print("currWarrior: ",currWarrior)
currWarriorStrength = warriorsSumStrength[newWarrior]-warriorsSumStrength[currWarrior]-numArrows
#print("newWarriorStrength: ",currWarriorStrength)
currWarrior = newWarrior
print(numWarriors-currWarrior)
``` | 3 |
|
366 | B | Dima and To-do List | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.
Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in circles muttering about how useless her sweetheart is. During that time Dima has time to peacefully complete *k*<=-<=1 tasks. Then Inna returns and tells Dima off for the next task he does in her presence and goes to another room again. It continues until Dima is through with his tasks.
Overall, Dima has *n* tasks to do, each task has a unique number from 1 to *n*. Dima loves order, so he does tasks consecutively, starting from some task. For example, if Dima has 6 tasks to do in total, then, if he starts from the 5-th task, the order is like that: first Dima does the 5-th task, then the 6-th one, then the 1-st one, then the 2-nd one, then the 3-rd one, then the 4-th one.
Inna tells Dima off (only lovingly and appropriately!) so often and systematically that he's very well learned the power with which she tells him off for each task. Help Dima choose the first task so that in total he gets told off with as little power as possible. | The first line of the input contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103), where *a**i* is the power Inna tells Dima off with if she is present in the room while he is doing the *i*-th task.
It is guaranteed that *n* is divisible by *k*. | In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do. | [
"6 2\n3 2 1 6 5 4\n",
"10 5\n1 3 5 7 9 9 4 1 8 5\n"
] | [
"1\n",
"3\n"
] | Explanation of the first example.
If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as *k* = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If Dima started from the second task, for example, then Inna would tell him off for tasks 2, 4 and 6 with power 2 + 6 + 4 = 12.
Explanation of the second example.
In the second example *k* = 5, thus, Dima manages to complete 4 tasks in-between the telling off sessions. Thus, Inna tells Dima off for tasks number 1 and 6 (if he starts from 1 or 6), 2 and 7 (if he starts from 2 or 7) and so on. The optimal answer is to start from task 3 or 8, 3 has a smaller number, so the answer is 3. | 1,000 | [
{
"input": "6 2\n3 2 1 6 5 4",
"output": "1"
},
{
"input": "10 5\n1 3 5 7 9 9 4 1 8 5",
"output": "3"
},
{
"input": "20 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "10 10\n8 4 5 7 6 9 2 2 3 5",
"output": "7"
},
{
"input": "50 10\n1 2 3 4 5 6 7 8 9 10 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "4 2\n2 1 1 3",
"output": "1"
},
{
"input": "15 5\n5 5 5 5 5 1 2 3 4 5 1 2 3 4 5",
"output": "1"
},
{
"input": "20 10\n3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 6 4",
"output": "1"
}
] | 1,655,834,651 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 124 | 8,396,800 | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
w = list(map(int, input().split()))
if k > n/2:
print(w.index(min(w))+1)
else:
d = [1e9, -1]
for i in range(k):
c = 0
for j in range(i, n, k):
c += w[j]
if c < d[0]:
d = [c, i+1]
print(d[1]) | Title: Dima and To-do List
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.
Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in circles muttering about how useless her sweetheart is. During that time Dima has time to peacefully complete *k*<=-<=1 tasks. Then Inna returns and tells Dima off for the next task he does in her presence and goes to another room again. It continues until Dima is through with his tasks.
Overall, Dima has *n* tasks to do, each task has a unique number from 1 to *n*. Dima loves order, so he does tasks consecutively, starting from some task. For example, if Dima has 6 tasks to do in total, then, if he starts from the 5-th task, the order is like that: first Dima does the 5-th task, then the 6-th one, then the 1-st one, then the 2-nd one, then the 3-rd one, then the 4-th one.
Inna tells Dima off (only lovingly and appropriately!) so often and systematically that he's very well learned the power with which she tells him off for each task. Help Dima choose the first task so that in total he gets told off with as little power as possible.
Input Specification:
The first line of the input contains two integers *n*,<=*k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103), where *a**i* is the power Inna tells Dima off with if she is present in the room while he is doing the *i*-th task.
It is guaranteed that *n* is divisible by *k*.
Output Specification:
In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do.
Demo Input:
['6 2\n3 2 1 6 5 4\n', '10 5\n1 3 5 7 9 9 4 1 8 5\n']
Demo Output:
['1\n', '3\n']
Note:
Explanation of the first example.
If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as *k* = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If Dima started from the second task, for example, then Inna would tell him off for tasks 2, 4 and 6 with power 2 + 6 + 4 = 12.
Explanation of the second example.
In the second example *k* = 5, thus, Dima manages to complete 4 tasks in-between the telling off sessions. Thus, Inna tells Dima off for tasks number 1 and 6 (if he starts from 1 or 6), 2 and 7 (if he starts from 2 or 7) and so on. The optimal answer is to start from task 3 or 8, 3 has a smaller number, so the answer is 3. | ```python
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
w = list(map(int, input().split()))
if k > n/2:
print(w.index(min(w))+1)
else:
d = [1e9, -1]
for i in range(k):
c = 0
for j in range(i, n, k):
c += w[j]
if c < d[0]:
d = [c, i+1]
print(d[1])
``` | 3 |
|
447 | B | DZY Loves Strings | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get? | The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. | Print a single integer — the largest possible value of the resulting string DZY could get. | [
"abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"
] | [
"41\n"
] | In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41. | 1,000 | [
{
"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "41"
},
{
"input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453",
"output": "29978"
},
{
"input": "ajeeseerqnpaujubmajpibxrccazaawetywxmifzehojf\n23\n359 813 772 413 733 654 33 87 890 433 395 311 801 852 376 148 914 420 636 695 583 733 664 394 407 314",
"output": "1762894"
},
{
"input": "uahngxejpomhbsebcxvelfsojbaouynnlsogjyvktpwwtcyddkcdqcqs\n34\n530 709 150 660 947 830 487 142 208 276 885 542 138 214 76 184 273 753 30 195 722 236 82 691 572 585",
"output": "2960349"
},
{
"input": "xnzeqmouqyzvblcidmhbkqmtusszuczadpooslqxegldanwopilmdwzbczvrwgnwaireykwpugvpnpafbxlyggkgawghysufuegvmzvpgcqyjkoadcreaguzepbendwnowsuekxxivkziibxvxfoilofxcgnxvfefyezfhevfvtetsuhwtyxdlkccdkvqjl\n282\n170 117 627 886 751 147 414 187 150 960 410 70 576 681 641 729 798 877 611 108 772 643 683 166 305 933",
"output": "99140444"
},
{
"input": "pplkqmluhfympkjfjnfdkwrkpumgdmbkfbbldpepicbbmdgafttpopzdxsevlqbtywzkoxyviglbbxsohycbdqksrhlumsldiwzjmednbkcjishkiekfrchzuztkcxnvuykhuenqojrmzaxlaoxnljnvqgnabtmcftisaazzgbmubmpsorygyusmeonrhrgphnfhlaxrvyhuxsnnezjxmdoklpquzpvjbxgbywppmegzxknhfzyygrmejleesoqfwheulmqhonqaukyuejtwxskjldplripyihbfpookxkuehiwqthbfafyrgmykuxglpplozycgydyecqkgfjljfqvigqhuxssqqtfanwszduwbsoytnrtgc\n464\n838 95 473 955 690 84 436 19 179 437 674 626 377 365 781 4 733 776 462 203 119 256 381 668 855 686",
"output": "301124161"
},
{
"input": "qkautnuilwlhjsldfcuwhiqtgtoihifszlyvfaygrnivzgvwthkrzzdtfjcirrjjlrmjtbjlzmjeqmuffsjorjyggzefwgvmblvotvzffnwjhqxorpowzdcnfksdibezdtfjjxfozaghieksbmowrbeehuxlesmvqjsphlvauxiijm\n98\n121 622 0 691 616 959 838 161 581 862 876 830 267 812 598 106 337 73 588 323 999 17 522 399 657 495",
"output": "30125295"
},
{
"input": "tghyxqfmhz\n8\n191 893 426 203 780 326 148 259 182 140 847 636 778 97 167 773 219 891 758 993 695 603 223 779 368 165",
"output": "136422"
},
{
"input": "nyawbfjxnxjiyhwkydaruozobpphgjqdpfdqzezcsoyvurnapu\n30\n65 682 543 533 990 148 815 821 315 916 632 771 332 513 472 864 12 73 548 687 660 572 507 192 226 348",
"output": "2578628"
},
{
"input": "pylrnkrbcjgoytvdnhmlvnkknijkdgdhworlvtwuonrkhrilkewcnofodaumgvnsisxooswgrgtvdeauyxhkipfoxrrtysuepjcf\n60\n894 206 704 179 272 337 413 828 119 182 330 46 440 102 250 191 242 539 678 783 843 431 612 567 33 338",
"output": "9168707"
},
{
"input": "vhjnkrxbyhjhnjrxvwxmhxwoxttbtqosfxtcuvhfjlkyfspeypthsdkkwnqdpxdlnxsgtzvkrgqosgfjrwetqbxgoarkjhrjbspzgblsapifltkfxbfdbxqwoohlgyzijmiwnpmveybyzvasoctxsmgjehpyysmqblwnmkappbecklqjfmxhlyceordroflnposohfplrvijxbwvqdtvzhobtrumiujnyrfbwthvciinuveoizkccelxtaveiiagryqnyvsgfnipnavrtmdqlcnldepocbpzmqnarkdvykds\n276\n364 244 798 82 582 9 309 950 286 547 892 371 569 159 705 975 740 845 655 179 130 993 255 552 882 657",
"output": "144901921"
},
{
"input": "gsaddmezrnttfalbwlqbnedumvikplfosw\n12\n290 850 872 361 483 895 152 118 974 619 701 154 899 285 328 712 669 984 407 340 851 775 324 892 554 860",
"output": "809931"
},
{
"input": "a\n0\n5 1 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": "5"
},
{
"input": "lol\n3\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",
"output": "21"
}
] | 1,548,200,530 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 155 | 819,200 | import string
lower=string.ascii_lowercase
x=input()
k=int(input())
l=list(map(int,input().split()))
op=k
d={}
ans=[]
for i in range(26):
d[lower[i]]=l[i]
l=sorted(l,reverse=True)
while k!=0:
ans.append(l.pop(0))
k-=1
#print(ans)
hlf=0
for i in range(len(x)):
hlf+=d[x[i]]*(i+1)
vlf=0
f=len(x)
for i in range(f+1,f+op+1,1):
vlf+=i*ans[0]
print(hlf+vlf)
| Title: DZY Loves Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input Specification:
The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000.
Output Specification:
Print a single integer — the largest possible value of the resulting string DZY could get.
Demo Input:
['abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n']
Demo Output:
['41\n']
Note:
In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41. | ```python
import string
lower=string.ascii_lowercase
x=input()
k=int(input())
l=list(map(int,input().split()))
op=k
d={}
ans=[]
for i in range(26):
d[lower[i]]=l[i]
l=sorted(l,reverse=True)
while k!=0:
ans.append(l.pop(0))
k-=1
#print(ans)
hlf=0
for i in range(len(x)):
hlf+=d[x[i]]*(i+1)
vlf=0
f=len(x)
for i in range(f+1,f+op+1,1):
vlf+=i*ans[0]
print(hlf+vlf)
``` | -1 |
|
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "414",
"output": "NO"
},
{
"input": "1000000000",
"output": "NO"
},
{
"input": "144144144",
"output": "YES"
},
{
"input": "1444",
"output": "NO"
},
{
"input": "11",
"output": "YES"
},
{
"input": "141414141",
"output": "YES"
},
{
"input": "11110111",
"output": "NO"
},
{
"input": "114114144",
"output": "YES"
},
{
"input": "444",
"output": "NO"
},
{
"input": "9999",
"output": "NO"
},
{
"input": "111444",
"output": "NO"
},
{
"input": "11114",
"output": "YES"
},
{
"input": "41111",
"output": "NO"
},
{
"input": "114414441",
"output": "NO"
},
{
"input": "144414441",
"output": "NO"
},
{
"input": "144244144",
"output": "NO"
},
{
"input": "111111111",
"output": "YES"
},
{
"input": "144444444",
"output": "NO"
},
{
"input": "444444444",
"output": "NO"
},
{
"input": "141441441",
"output": "YES"
},
{
"input": "441",
"output": "NO"
},
{
"input": "15",
"output": "NO"
},
{
"input": "14444",
"output": "NO"
},
{
"input": "11444",
"output": "NO"
},
{
"input": "144",
"output": "YES"
},
{
"input": "1414414",
"output": "YES"
},
{
"input": "141444",
"output": "NO"
},
{
"input": "14144",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "1144",
"output": "YES"
},
{
"input": "141111444",
"output": "NO"
},
{
"input": "14414414",
"output": "YES"
},
{
"input": "141414144",
"output": "YES"
},
{
"input": "1414",
"output": "YES"
},
{
"input": "1441",
"output": "YES"
},
{
"input": "12",
"output": "NO"
},
{
"input": "144144141",
"output": "YES"
},
{
"input": "144144",
"output": "YES"
},
{
"input": "14414411",
"output": "YES"
},
{
"input": "14414",
"output": "YES"
}
] | 1,679,615,619 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 186 | 0 | n = input()
s = "YES"
x = 0
for i in range(len(n)):
if i == 0 and n[i] != '1':
s = "NO"
break
if n[i] != '1' and n[i] != '4':
s = "NO"
break
if n[i] == '4':
x += 1
if n[i] == '1':
x = 0
if x > 2:
s = "NO"
break
print(s) | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input Specification:
The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros.
Output Specification:
Print "YES" if *n* is a magic number or print "NO" if it's not.
Demo Input:
['114114\n', '1111\n', '441231\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none | ```python
n = input()
s = "YES"
x = 0
for i in range(len(n)):
if i == 0 and n[i] != '1':
s = "NO"
break
if n[i] != '1' and n[i] != '4':
s = "NO"
break
if n[i] == '4':
x += 1
if n[i] == '1':
x = 0
if x > 2:
s = "NO"
break
print(s)
``` | 3 |
|
982 | A | Row | PROGRAMMING | 1,200 | [
"brute force",
"constructive algorithms"
] | null | null | You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means that the corresponding seat is empty, $1$ — occupied). The goal is to determine whether this seating is "maximal".
Note that the first and last seats are not adjacent (if $n \ne 2$). | The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs.
The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating. | Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase). | [
"3\n101\n",
"4\n1011\n",
"5\n10001\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | 500 | [
{
"input": "3\n101",
"output": "Yes"
},
{
"input": "4\n1011",
"output": "No"
},
{
"input": "5\n10001",
"output": "No"
},
{
"input": "1\n0",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "100\n0101001010101001010010010101001010100101001001001010010101010010101001001010101001001001010100101010",
"output": "Yes"
},
{
"input": "4\n0100",
"output": "No"
},
{
"input": "42\n011000100101001001101011011010100010011010",
"output": "No"
},
{
"input": "3\n001",
"output": "No"
},
{
"input": "64\n1001001010010010100101010010010100100101001001001001010100101001",
"output": "Yes"
},
{
"input": "3\n111",
"output": "No"
},
{
"input": "4\n0000",
"output": "No"
},
{
"input": "4\n0001",
"output": "No"
},
{
"input": "4\n0010",
"output": "No"
},
{
"input": "4\n0011",
"output": "No"
},
{
"input": "4\n0101",
"output": "Yes"
},
{
"input": "4\n0110",
"output": "No"
},
{
"input": "4\n0111",
"output": "No"
},
{
"input": "4\n1000",
"output": "No"
},
{
"input": "4\n1001",
"output": "Yes"
},
{
"input": "4\n1010",
"output": "Yes"
},
{
"input": "4\n1100",
"output": "No"
},
{
"input": "4\n1101",
"output": "No"
},
{
"input": "4\n1110",
"output": "No"
},
{
"input": "4\n1111",
"output": "No"
},
{
"input": "2\n00",
"output": "No"
},
{
"input": "2\n01",
"output": "Yes"
},
{
"input": "2\n10",
"output": "Yes"
},
{
"input": "2\n11",
"output": "No"
},
{
"input": "3\n000",
"output": "No"
},
{
"input": "3\n010",
"output": "Yes"
},
{
"input": "3\n011",
"output": "No"
},
{
"input": "3\n100",
"output": "No"
},
{
"input": "3\n110",
"output": "No"
},
{
"input": "100\n0111001010101110001100000010011000100101110010001100111110101110001110101010111000010010011000000110",
"output": "No"
},
{
"input": "357\n100101010010010010010100101001001010101010100100100100101001010101001010010100101001010100101001010010100100101001010101010101001001010100101010010100101001010100100100101010010010010100101010010010101001010010010101001001010010010101010100100101010010100100101001010100101001010100101001010010010010100101001010100100100100100100100101010101010010010100101",
"output": "Yes"
},
{
"input": "459\n000111000101010000100001001010111110011011010001100101111010111011101110111101111101100101100011011001100110001001111001101000111001011100110100011111011111000010000110010011100110011011111110011100001101001111000100111011001000001011111100110100001001001100101011100001110110100101011011110100100111101011000101110000100110100100010000000100001001111111000011101010010011001111010111001100000100111001010111011010000011000011100101101011101000011011000110011",
"output": "No"
},
{
"input": "3\n001",
"output": "No"
},
{
"input": "4\n0010",
"output": "No"
},
{
"input": "3\n111",
"output": "No"
},
{
"input": "4\n0110",
"output": "No"
},
{
"input": "2\n11",
"output": "No"
},
{
"input": "2\n10",
"output": "Yes"
},
{
"input": "2\n01",
"output": "Yes"
},
{
"input": "4\n1101",
"output": "No"
},
{
"input": "2\n00",
"output": "No"
},
{
"input": "4\n1111",
"output": "No"
},
{
"input": "15\n000010101010000",
"output": "No"
},
{
"input": "8\n10010100",
"output": "No"
},
{
"input": "5\n00100",
"output": "No"
},
{
"input": "6\n100100",
"output": "No"
},
{
"input": "7\n1000001",
"output": "No"
},
{
"input": "98\n10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "Yes"
}
] | 1,640,881,805 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input())
ainput = input()
if n == 1:
if ainput == '1':
print("Yes")
else:
print("No")
if n == 2:
if ainput == '01' or ainput == '10':
print("Yes")
else:
print("No")
if n == 3:
if ainput == '010' or ainput == '101':
print("Yes")
else:
print("No")
if n == 4:
if ainput == '1001' or ainput == '0101' or ainput == '1010':
print("Yes")
else:
print("No")
else:
if '11' or '000' in ainput:
print("No")
else:
print("Yes") | Title: Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means that the corresponding seat is empty, $1$ — occupied). The goal is to determine whether this seating is "maximal".
Note that the first and last seats are not adjacent (if $n \ne 2$).
Input Specification:
The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs.
The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating.
Output Specification:
Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase).
Demo Input:
['3\n101\n', '4\n1011\n', '5\n10001\n']
Demo Output:
['Yes\n', 'No\n', 'No\n']
Note:
In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | ```python
n = int(input())
ainput = input()
if n == 1:
if ainput == '1':
print("Yes")
else:
print("No")
if n == 2:
if ainput == '01' or ainput == '10':
print("Yes")
else:
print("No")
if n == 3:
if ainput == '010' or ainput == '101':
print("Yes")
else:
print("No")
if n == 4:
if ainput == '1001' or ainput == '0101' or ainput == '1010':
print("Yes")
else:
print("No")
else:
if '11' or '000' in ainput:
print("No")
else:
print("Yes")
``` | 0 |
|
803 | A | Maximal Binary Matrix | PROGRAMMING | 1,400 | [
"constructive algorithms"
] | null | null | You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.
If there exists no such matrix then output -1. | The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106). | If the answer exists then output resulting matrix. Otherwise output -1. | [
"2 1\n",
"3 2\n",
"2 5\n"
] | [
"1 0 \n0 0 \n",
"1 0 0 \n0 1 0 \n0 0 0 \n",
"-1\n"
] | none | 0 | [
{
"input": "2 1",
"output": "1 0 \n0 0 "
},
{
"input": "3 2",
"output": "1 0 0 \n0 1 0 \n0 0 0 "
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "1 0",
"output": "0 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "20 398",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1..."
},
{
"input": "20 401",
"output": "-1"
},
{
"input": "100 3574",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "100 10000",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "100 10001",
"output": "-1"
},
{
"input": "2 3",
"output": "1 1 \n1 0 "
},
{
"input": "4 5",
"output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 "
},
{
"input": "5 6",
"output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 24",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 "
},
{
"input": "2 0",
"output": "0 0 \n0 0 "
},
{
"input": "3 5",
"output": "1 1 1 \n1 0 0 \n1 0 0 "
},
{
"input": "3 3",
"output": "1 1 0 \n1 0 0 \n0 0 0 "
},
{
"input": "5 10",
"output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "3 4",
"output": "1 1 0 \n1 1 0 \n0 0 0 "
},
{
"input": "4 3",
"output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "1 1000000",
"output": "-1"
},
{
"input": "3 6",
"output": "1 1 1 \n1 1 0 \n1 0 0 "
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "1 0",
"output": "0 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "1 3",
"output": "-1"
},
{
"input": "1 4",
"output": "-1"
},
{
"input": "1 5",
"output": "-1"
},
{
"input": "1 6",
"output": "-1"
},
{
"input": "1 7",
"output": "-1"
},
{
"input": "1 8",
"output": "-1"
},
{
"input": "1 9",
"output": "-1"
},
{
"input": "1 10",
"output": "-1"
},
{
"input": "1 11",
"output": "-1"
},
{
"input": "1 12",
"output": "-1"
},
{
"input": "1 13",
"output": "-1"
},
{
"input": "1 14",
"output": "-1"
},
{
"input": "1 15",
"output": "-1"
},
{
"input": "1 16",
"output": "-1"
},
{
"input": "1 17",
"output": "-1"
},
{
"input": "1 18",
"output": "-1"
},
{
"input": "1 19",
"output": "-1"
},
{
"input": "1 20",
"output": "-1"
},
{
"input": "1 21",
"output": "-1"
},
{
"input": "1 22",
"output": "-1"
},
{
"input": "1 23",
"output": "-1"
},
{
"input": "1 24",
"output": "-1"
},
{
"input": "1 25",
"output": "-1"
},
{
"input": "1 26",
"output": "-1"
},
{
"input": "2 0",
"output": "0 0 \n0 0 "
},
{
"input": "2 1",
"output": "1 0 \n0 0 "
},
{
"input": "2 2",
"output": "1 0 \n0 1 "
},
{
"input": "2 3",
"output": "1 1 \n1 0 "
},
{
"input": "2 4",
"output": "1 1 \n1 1 "
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "2 6",
"output": "-1"
},
{
"input": "2 7",
"output": "-1"
},
{
"input": "2 8",
"output": "-1"
},
{
"input": "2 9",
"output": "-1"
},
{
"input": "2 10",
"output": "-1"
},
{
"input": "2 11",
"output": "-1"
},
{
"input": "2 12",
"output": "-1"
},
{
"input": "2 13",
"output": "-1"
},
{
"input": "2 14",
"output": "-1"
},
{
"input": "2 15",
"output": "-1"
},
{
"input": "2 16",
"output": "-1"
},
{
"input": "2 17",
"output": "-1"
},
{
"input": "2 18",
"output": "-1"
},
{
"input": "2 19",
"output": "-1"
},
{
"input": "2 20",
"output": "-1"
},
{
"input": "2 21",
"output": "-1"
},
{
"input": "2 22",
"output": "-1"
},
{
"input": "2 23",
"output": "-1"
},
{
"input": "2 24",
"output": "-1"
},
{
"input": "2 25",
"output": "-1"
},
{
"input": "2 26",
"output": "-1"
},
{
"input": "3 0",
"output": "0 0 0 \n0 0 0 \n0 0 0 "
},
{
"input": "3 1",
"output": "1 0 0 \n0 0 0 \n0 0 0 "
},
{
"input": "3 2",
"output": "1 0 0 \n0 1 0 \n0 0 0 "
},
{
"input": "3 3",
"output": "1 1 0 \n1 0 0 \n0 0 0 "
},
{
"input": "3 4",
"output": "1 1 0 \n1 1 0 \n0 0 0 "
},
{
"input": "3 5",
"output": "1 1 1 \n1 0 0 \n1 0 0 "
},
{
"input": "3 6",
"output": "1 1 1 \n1 1 0 \n1 0 0 "
},
{
"input": "3 7",
"output": "1 1 1 \n1 1 0 \n1 0 1 "
},
{
"input": "3 8",
"output": "1 1 1 \n1 1 1 \n1 1 0 "
},
{
"input": "3 9",
"output": "1 1 1 \n1 1 1 \n1 1 1 "
},
{
"input": "3 10",
"output": "-1"
},
{
"input": "3 11",
"output": "-1"
},
{
"input": "3 12",
"output": "-1"
},
{
"input": "3 13",
"output": "-1"
},
{
"input": "3 14",
"output": "-1"
},
{
"input": "3 15",
"output": "-1"
},
{
"input": "3 16",
"output": "-1"
},
{
"input": "3 17",
"output": "-1"
},
{
"input": "3 18",
"output": "-1"
},
{
"input": "3 19",
"output": "-1"
},
{
"input": "3 20",
"output": "-1"
},
{
"input": "3 21",
"output": "-1"
},
{
"input": "3 22",
"output": "-1"
},
{
"input": "3 23",
"output": "-1"
},
{
"input": "3 24",
"output": "-1"
},
{
"input": "3 25",
"output": "-1"
},
{
"input": "3 26",
"output": "-1"
},
{
"input": "4 0",
"output": "0 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 1",
"output": "1 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 2",
"output": "1 0 0 0 \n0 1 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 3",
"output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 4",
"output": "1 1 0 0 \n1 1 0 0 \n0 0 0 0 \n0 0 0 0 "
},
{
"input": "4 5",
"output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 "
},
{
"input": "4 6",
"output": "1 1 1 0 \n1 1 0 0 \n1 0 0 0 \n0 0 0 0 "
},
{
"input": "4 7",
"output": "1 1 1 1 \n1 0 0 0 \n1 0 0 0 \n1 0 0 0 "
},
{
"input": "4 8",
"output": "1 1 1 1 \n1 1 0 0 \n1 0 0 0 \n1 0 0 0 "
},
{
"input": "4 9",
"output": "1 1 1 1 \n1 1 0 0 \n1 0 1 0 \n1 0 0 0 "
},
{
"input": "4 10",
"output": "1 1 1 1 \n1 1 1 0 \n1 1 0 0 \n1 0 0 0 "
},
{
"input": "4 11",
"output": "1 1 1 1 \n1 1 1 0 \n1 1 1 0 \n1 0 0 0 "
},
{
"input": "4 12",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 0 0 \n1 1 0 0 "
},
{
"input": "4 13",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 0 "
},
{
"input": "4 14",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 1 "
},
{
"input": "4 15",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 0 "
},
{
"input": "4 16",
"output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 1 "
},
{
"input": "4 17",
"output": "-1"
},
{
"input": "4 18",
"output": "-1"
},
{
"input": "4 19",
"output": "-1"
},
{
"input": "4 20",
"output": "-1"
},
{
"input": "4 21",
"output": "-1"
},
{
"input": "4 22",
"output": "-1"
},
{
"input": "4 23",
"output": "-1"
},
{
"input": "4 24",
"output": "-1"
},
{
"input": "4 25",
"output": "-1"
},
{
"input": "4 26",
"output": "-1"
},
{
"input": "5 0",
"output": "0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 1",
"output": "1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 2",
"output": "1 0 0 0 0 \n0 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 3",
"output": "1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 4",
"output": "1 1 0 0 0 \n1 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 5",
"output": "1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 6",
"output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 7",
"output": "1 1 1 1 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 8",
"output": "1 1 1 1 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 "
},
{
"input": "5 9",
"output": "1 1 1 1 1 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 10",
"output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 11",
"output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 12",
"output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 13",
"output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 14",
"output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 0 0 0 \n1 1 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 15",
"output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 "
},
{
"input": "5 16",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 0 0 0 \n1 1 0 0 0 \n1 1 0 0 0 "
},
{
"input": "5 17",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 1 0 0 0 "
},
{
"input": "5 18",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 1 0 \n1 1 0 0 0 "
},
{
"input": "5 19",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 "
},
{
"input": "5 20",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 1 0 \n1 1 0 0 0 "
},
{
"input": "5 21",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 "
},
{
"input": "5 22",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 "
},
{
"input": "5 23",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 1 "
},
{
"input": "5 24",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 "
},
{
"input": "5 25",
"output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 "
},
{
"input": "5 26",
"output": "-1"
},
{
"input": "100 0",
"output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 1",
"output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 2",
"output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 3",
"output": "1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 99",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 100",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 101",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 9999",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "100 10000",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "100 10001",
"output": "-1"
}
] | 1,698,319,726 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | n,k=map(int,input().split())
if n<k:
print(-1)
else:
for i in range(k):
lst=['0' for _ in range(n)]
lst[i]='1'
print(' '.join(lst))
for j in range(n-k):
print('0 '*(n-1)+'0') | Title: Maximal Binary Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.
If there exists no such matrix then output -1.
Input Specification:
The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106).
Output Specification:
If the answer exists then output resulting matrix. Otherwise output -1.
Demo Input:
['2 1\n', '3 2\n', '2 5\n']
Demo Output:
['1 0 \n0 0 \n', '1 0 0 \n0 1 0 \n0 0 0 \n', '-1\n']
Note:
none | ```python
n,k=map(int,input().split())
if n<k:
print(-1)
else:
for i in range(k):
lst=['0' for _ in range(n)]
lst[i]='1'
print(' '.join(lst))
for j in range(n-k):
print('0 '*(n-1)+'0')
``` | 0 |
|
805 | B | 3-palindrome | PROGRAMMING | 1,000 | [
"constructive algorithms"
] | null | null | In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. | Print the string that satisfies all the constraints.
If there are multiple answers, print any of them. | [
"2\n",
"3\n"
] | [
"aa\n",
"bba\n"
] | A palindrome is a sequence of characters which reads the same backward and forward. | 1,000 | [
{
"input": "2",
"output": "aa"
},
{
"input": "3",
"output": "aab"
},
{
"input": "38",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "47",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "59",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "67",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "77",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "89",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "98",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "109",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "117",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
},
{
"input": "1",
"output": "a"
},
{
"input": "200000",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "100000",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "143670",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "104217",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "17879",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "131809",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "140873",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "77859",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "153022",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "179227",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "182801",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "5188",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "86539",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "12802",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "120289",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "132866",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "133377",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "31775",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "160397",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "161415",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "163623",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "22942",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "134767",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "52257",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "64905",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "183758",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "60131",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "146883",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab..."
},
{
"input": "6",
"output": "aabbaa"
},
{
"input": "4",
"output": "aabb"
}
] | 1,557,696,469 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | print((lambda t:('aabc'*t)[:t])(int(input()))) | Title: 3-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string.
Output Specification:
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Demo Input:
['2\n', '3\n']
Demo Output:
['aa\n', 'bba\n']
Note:
A palindrome is a sequence of characters which reads the same backward and forward. | ```python
print((lambda t:('aabc'*t)[:t])(int(input())))
``` | 0 |
|
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,677,437,187 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 15 | 0 | import math
numbers = input('')
result = 0
height = 0
width = 0
n = int(numbers[0])
m = int(numbers[2])
a = int(numbers[4])
if n*m == a*a:
result = 1
else:
if a > n and a > m:
height = 1
elif n == a:
height = 0
width = math.ceil(m/a)
elif m == a:
width = 0
height = math.ceil(n/a)
else:
height = math.ceil(n/a)
width = math.ceil(m/a)
result = height + width
print(result) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
import math
numbers = input('')
result = 0
height = 0
width = 0
n = int(numbers[0])
m = int(numbers[2])
a = int(numbers[4])
if n*m == a*a:
result = 1
else:
if a > n and a > m:
height = 1
elif n == a:
height = 0
width = math.ceil(m/a)
elif m == a:
width = 0
height = math.ceil(n/a)
else:
height = math.ceil(n/a)
width = math.ceil(m/a)
result = height + width
print(result)
``` | 0 |
106 | A | Card Game | PROGRAMMING | 1,000 | [
"implementation"
] | A. Card Game | 2 | 256 | There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want.
To play durak you need a pack of 36 cards. Each card has a suit ("S", "H", "D" and "C") and a rank (in the increasing order "6", "7", "8", "9", "T", "J", "Q", "K" and "A"). At the beginning of the game one suit is arbitrarily chosen as trump.
The players move like that: one player puts one or several of his cards on the table and the other one should beat each of them with his cards.
A card beats another one if both cards have similar suits and the first card has a higher rank then the second one. Besides, a trump card can beat any non-trump card whatever the cards’ ranks are. In all other cases you can not beat the second card with the first one.
You are given the trump suit and two different cards. Determine whether the first one beats the second one or not. | The first line contains the tramp suit. It is "S", "H", "D" or "C".
The second line contains the description of the two different cards. Each card is described by one word consisting of two symbols. The first symbol stands for the rank ("6", "7", "8", "9", "T", "J", "Q", "K" and "A"), and the second one stands for the suit ("S", "H", "D" and "C"). | Print "YES" (without the quotes) if the first cards beats the second one. Otherwise, print "NO" (also without the quotes). | [
"H\nQH 9S\n",
"S\n8D 6D\n",
"C\n7H AS\n"
] | [
"YES\n",
"YES",
"NO"
] | none | 500 | [
{
"input": "H\nQH 9S",
"output": "YES"
},
{
"input": "S\n8D 6D",
"output": "YES"
},
{
"input": "C\n7H AS",
"output": "NO"
},
{
"input": "C\nKC 9C",
"output": "YES"
},
{
"input": "D\n7D KD",
"output": "NO"
},
{
"input": "H\n7H KD",
"output": "YES"
},
{
"input": "D\nAS AH",
"output": "NO"
},
{
"input": "H\nKH KS",
"output": "YES"
},
{
"input": "C\n9H 6C",
"output": "NO"
},
{
"input": "C\n9H JC",
"output": "NO"
},
{
"input": "D\nTD JD",
"output": "NO"
},
{
"input": "H\n6S 7S",
"output": "NO"
},
{
"input": "D\n7S 8S",
"output": "NO"
},
{
"input": "S\n8H 9H",
"output": "NO"
},
{
"input": "C\n9D TD",
"output": "NO"
},
{
"input": "H\nTC JC",
"output": "NO"
},
{
"input": "C\nJH QH",
"output": "NO"
},
{
"input": "H\nQD KD",
"output": "NO"
},
{
"input": "D\nKS AS",
"output": "NO"
},
{
"input": "S\nAH 6H",
"output": "YES"
},
{
"input": "H\n7D 6D",
"output": "YES"
},
{
"input": "S\n8H 7H",
"output": "YES"
},
{
"input": "D\n9S 8S",
"output": "YES"
},
{
"input": "S\nTC 9C",
"output": "YES"
},
{
"input": "H\nJS TS",
"output": "YES"
},
{
"input": "S\nQD JD",
"output": "YES"
},
{
"input": "D\nKH QH",
"output": "YES"
},
{
"input": "H\nAD KD",
"output": "YES"
},
{
"input": "H\nQS QD",
"output": "NO"
},
{
"input": "C\nTS TH",
"output": "NO"
},
{
"input": "C\n6C 6D",
"output": "YES"
},
{
"input": "H\n8H 8D",
"output": "YES"
},
{
"input": "S\n7D 7S",
"output": "NO"
},
{
"input": "H\nJC JH",
"output": "NO"
},
{
"input": "H\n8H 9C",
"output": "YES"
},
{
"input": "D\n9D 6S",
"output": "YES"
},
{
"input": "C\nJC AH",
"output": "YES"
},
{
"input": "S\nAS KD",
"output": "YES"
},
{
"input": "S\n7S JS",
"output": "NO"
},
{
"input": "H\nTH 8H",
"output": "YES"
},
{
"input": "S\n7S QS",
"output": "NO"
},
{
"input": "C\nKC QC",
"output": "YES"
},
{
"input": "S\nAD 9S",
"output": "NO"
},
{
"input": "D\n7H 8D",
"output": "NO"
},
{
"input": "H\nJC 9H",
"output": "NO"
},
{
"input": "C\n7S AC",
"output": "NO"
},
{
"input": "C\n8C 7C",
"output": "YES"
},
{
"input": "H\n9D 8S",
"output": "NO"
},
{
"input": "D\nAC KS",
"output": "NO"
},
{
"input": "H\n8C QH",
"output": "NO"
},
{
"input": "S\n7S TS",
"output": "NO"
},
{
"input": "C\nAH 6S",
"output": "NO"
},
{
"input": "S\nKS QS",
"output": "YES"
},
{
"input": "H\nAC QC",
"output": "YES"
},
{
"input": "S\n9H 8D",
"output": "NO"
},
{
"input": "S\nTS JS",
"output": "NO"
},
{
"input": "S\n8H 7C",
"output": "NO"
},
{
"input": "C\nAH 6S",
"output": "NO"
},
{
"input": "S\n7S QS",
"output": "NO"
},
{
"input": "C\nAH 6S",
"output": "NO"
},
{
"input": "S\nTS KS",
"output": "NO"
},
{
"input": "C\nTH KH",
"output": "NO"
},
{
"input": "H\n9C 6D",
"output": "NO"
},
{
"input": "H\n9C 8D",
"output": "NO"
},
{
"input": "H\nTH AH",
"output": "NO"
},
{
"input": "H\nTH JH",
"output": "NO"
},
{
"input": "H\nQS 9C",
"output": "NO"
},
{
"input": "H\nKC AC",
"output": "NO"
},
{
"input": "H\nAH KH",
"output": "YES"
},
{
"input": "H\nKS QS",
"output": "YES"
},
{
"input": "C\nAD KS",
"output": "NO"
},
{
"input": "H\nQS 9C",
"output": "NO"
},
{
"input": "H\n9D 7S",
"output": "NO"
},
{
"input": "D\n6D 9S",
"output": "YES"
},
{
"input": "H\nAH KH",
"output": "YES"
},
{
"input": "H\nKC AC",
"output": "NO"
},
{
"input": "D\n8S 6C",
"output": "NO"
},
{
"input": "S\nAC KC",
"output": "YES"
}
] | 1,651,847,585 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 124 | 512,000 | T=10;J=11;Q=12;K=13;A=14
trm=input()
c1,c2=map(str,input().split())
c1=[c1[0],c1[1]]
c2=[c2[0],c2[1]]
if c1[0]=='T':c1[0]=T
elif c1[0]=='J':c1[0]=J
elif c1[0]=='Q':c1[0]=Q
elif c1[0]=='K':c1[0]=K
elif c1[0]=='A':c1[0]=A
else: c1[0]=int(c1[0])
if c2[0]=='T':c2[0]=T
elif c2[0]=='J':c2[0]=J
elif c2[0]=='Q':c2[0]=Q
elif c2[0]=='K':c2[0]=K
elif c2[0]=='A':c2[0]=A
else: c2[0]=int(c2[0])
if c1[1]=='trm':
if c2[1]=='trm':
if c1[0]>c2[0]:
print('YES')
else:
print('NO')
else:
print('YES')
else:
if c1[0]>c2[0]:
print('YES')
else:
print('NO') | Title: Card Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want.
To play durak you need a pack of 36 cards. Each card has a suit ("S", "H", "D" and "C") and a rank (in the increasing order "6", "7", "8", "9", "T", "J", "Q", "K" and "A"). At the beginning of the game one suit is arbitrarily chosen as trump.
The players move like that: one player puts one or several of his cards on the table and the other one should beat each of them with his cards.
A card beats another one if both cards have similar suits and the first card has a higher rank then the second one. Besides, a trump card can beat any non-trump card whatever the cards’ ranks are. In all other cases you can not beat the second card with the first one.
You are given the trump suit and two different cards. Determine whether the first one beats the second one or not.
Input Specification:
The first line contains the tramp suit. It is "S", "H", "D" or "C".
The second line contains the description of the two different cards. Each card is described by one word consisting of two symbols. The first symbol stands for the rank ("6", "7", "8", "9", "T", "J", "Q", "K" and "A"), and the second one stands for the suit ("S", "H", "D" and "C").
Output Specification:
Print "YES" (without the quotes) if the first cards beats the second one. Otherwise, print "NO" (also without the quotes).
Demo Input:
['H\nQH 9S\n', 'S\n8D 6D\n', 'C\n7H AS\n']
Demo Output:
['YES\n', 'YES', 'NO']
Note:
none | ```python
T=10;J=11;Q=12;K=13;A=14
trm=input()
c1,c2=map(str,input().split())
c1=[c1[0],c1[1]]
c2=[c2[0],c2[1]]
if c1[0]=='T':c1[0]=T
elif c1[0]=='J':c1[0]=J
elif c1[0]=='Q':c1[0]=Q
elif c1[0]=='K':c1[0]=K
elif c1[0]=='A':c1[0]=A
else: c1[0]=int(c1[0])
if c2[0]=='T':c2[0]=T
elif c2[0]=='J':c2[0]=J
elif c2[0]=='Q':c2[0]=Q
elif c2[0]=='K':c2[0]=K
elif c2[0]=='A':c2[0]=A
else: c2[0]=int(c2[0])
if c1[1]=='trm':
if c2[1]=='trm':
if c1[0]>c2[0]:
print('YES')
else:
print('NO')
else:
print('YES')
else:
if c1[0]>c2[0]:
print('YES')
else:
print('NO')
``` | 0 |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*.
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.
What is the minimum number of groups that must be formed? | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles. | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": "2"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n2\n-1",
"output": "2"
},
{
"input": "2\n-1\n-1",
"output": "1"
},
{
"input": "3\n2\n-1\n1",
"output": "3"
},
{
"input": "3\n-1\n-1\n-1",
"output": "1"
},
{
"input": "5\n4\n5\n1\n-1\n4",
"output": "3"
},
{
"input": "12\n-1\n1\n1\n1\n1\n1\n3\n4\n3\n3\n4\n7",
"output": "4"
},
{
"input": "12\n-1\n-1\n1\n-1\n1\n1\n5\n11\n8\n6\n6\n4",
"output": "5"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n2\n-1\n-1\n-1",
"output": "2"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1",
"output": "1"
},
{
"input": "12\n3\n4\n2\n8\n7\n1\n10\n12\n5\n-1\n9\n11",
"output": "12"
},
{
"input": "12\n5\n6\n7\n1\n-1\n9\n12\n4\n8\n-1\n3\n2",
"output": "11"
},
{
"input": "12\n-1\n9\n11\n6\n6\n-1\n6\n3\n8\n6\n1\n6",
"output": "6"
},
{
"input": "12\n7\n8\n4\n12\n7\n9\n-1\n-1\n-1\n8\n6\n-1",
"output": "3"
},
{
"input": "12\n-1\n10\n-1\n1\n-1\n5\n9\n12\n-1\n-1\n3\n-1",
"output": "2"
},
{
"input": "12\n-1\n7\n9\n12\n1\n7\n-1\n-1\n8\n5\n4\n-1",
"output": "3"
},
{
"input": "12\n11\n11\n8\n9\n1\n1\n2\n-1\n10\n3\n-1\n8",
"output": "5"
},
{
"input": "12\n-1\n8\n9\n-1\n4\n2\n11\n1\n-1\n6\n-1\n10",
"output": "6"
},
{
"input": "12\n7\n4\n4\n-1\n6\n7\n9\n7\n-1\n7\n4\n1",
"output": "4"
},
{
"input": "12\n-1\n6\n10\n6\n1\n11\n5\n9\n11\n5\n1\n9",
"output": "4"
},
{
"input": "12\n8\n6\n6\n8\n6\n-1\n6\n6\n8\n6\n8\n8",
"output": "3"
},
{
"input": "12\n3\n8\n9\n12\n2\n8\n11\n12\n2\n9\n-1\n11",
"output": "7"
},
{
"input": "7\n7\n6\n-1\n-1\n4\n4\n-1",
"output": "3"
},
{
"input": "77\n53\n-1\n48\n-1\n51\n-1\n54\n43\n70\n19\n64\n31\n45\n58\n6\n61\n41\n56\n34\n-1\n54\n-1\n66\n65\n74\n16\n38\n1\n2\n61\n-1\n34\n-1\n-1\n7\n19\n57\n13\n61\n42\n-1\n34\n65\n16\n31\n61\n6\n5\n34\n15\n-1\n13\n4\n22\n74\n7\n-1\n70\n38\n61\n45\n53\n46\n22\n-1\n65\n34\n19\n43\n48\n33\n58\n36\n-1\n47\n24\n34",
"output": "6"
},
{
"input": "5\n2\n3\n4\n5\n-1",
"output": "5"
}
] | 1,698,385,290 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 2,120 | 1,740,800 | def find_depth(employee, adj):
if employee not in adj: # If the employee is a leaf (has no subordinates)
return 1
return 1 + max(find_depth(subordinate, adj) for subordinate in adj[employee])
def main():
n = int(input())
adj = {} # Adjacency list
for i in range(n):
manager = int(input())
if manager != -1:
if manager in adj:
adj[manager].append(i+1)
else:
adj[manager] = [i+1]
# Find the depth for each root (an employee with no manager)
depths = [find_depth(employee, adj) for employee in adj if employee not in sum(adj.values(), [])]
print(max(depths))
if __name__ == "__main__":
main()
| Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*.
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.
What is the minimum number of groups that must be formed?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles.
Output Specification:
Print a single integer denoting the minimum number of groups that will be formed in the party.
Demo Input:
['5\n-1\n1\n2\n1\n-1\n']
Demo Output:
['3\n']
Note:
For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | ```python
def find_depth(employee, adj):
if employee not in adj: # If the employee is a leaf (has no subordinates)
return 1
return 1 + max(find_depth(subordinate, adj) for subordinate in adj[employee])
def main():
n = int(input())
adj = {} # Adjacency list
for i in range(n):
manager = int(input())
if manager != -1:
if manager in adj:
adj[manager].append(i+1)
else:
adj[manager] = [i+1]
# Find the depth for each root (an employee with no manager)
depths = [find_depth(employee, adj) for employee in adj if employee not in sum(adj.values(), [])]
print(max(depths))
if __name__ == "__main__":
main()
``` | -1 |
|
659 | A | Round House | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in the direction of increasing numbers (in this order entrance *n* should be followed by entrance 1). The negative value of *b* corresponds to moving |*b*| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance *n*). If *b*<==<=0, then Vasya prefers to walk beside his entrance.
Help Vasya to determine the number of the entrance, near which he will be at the end of his walk. | The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. | Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk. | [
"6 2 -5\n",
"5 1 3\n",
"3 2 7\n"
] | [
"3\n",
"4\n",
"3\n"
] | The first example is illustrated by the picture in the statements. | 500 | [
{
"input": "6 2 -5",
"output": "3"
},
{
"input": "5 1 3",
"output": "4"
},
{
"input": "3 2 7",
"output": "3"
},
{
"input": "1 1 0",
"output": "1"
},
{
"input": "1 1 -1",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "100 1 -1",
"output": "100"
},
{
"input": "100 54 100",
"output": "54"
},
{
"input": "100 37 -100",
"output": "37"
},
{
"input": "99 41 0",
"output": "41"
},
{
"input": "97 37 -92",
"output": "42"
},
{
"input": "99 38 59",
"output": "97"
},
{
"input": "35 34 1",
"output": "35"
},
{
"input": "48 1 -1",
"output": "48"
},
{
"input": "87 65 -76",
"output": "76"
},
{
"input": "76 26 29",
"output": "55"
},
{
"input": "100 65 0",
"output": "65"
},
{
"input": "2 1 100",
"output": "1"
},
{
"input": "3 2 -100",
"output": "1"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "1 1 -100",
"output": "1"
},
{
"input": "3 1 -100",
"output": "3"
},
{
"input": "4 3 -100",
"output": "3"
},
{
"input": "3 2 -12",
"output": "2"
},
{
"input": "2 2 -100",
"output": "2"
},
{
"input": "3 2 -90",
"output": "2"
},
{
"input": "6 2 -10",
"output": "4"
},
{
"input": "3 3 -100",
"output": "2"
},
{
"input": "5 2 4",
"output": "1"
},
{
"input": "6 4 5",
"output": "3"
},
{
"input": "3 2 -6",
"output": "2"
},
{
"input": "5 1 -99",
"output": "2"
},
{
"input": "6 2 5",
"output": "1"
},
{
"input": "10 1 -100",
"output": "1"
},
{
"input": "2 2 1",
"output": "1"
},
{
"input": "3 3 1",
"output": "1"
},
{
"input": "6 4 4",
"output": "2"
},
{
"input": "17 17 2",
"output": "2"
},
{
"input": "6 6 1",
"output": "1"
},
{
"input": "5 3 -2",
"output": "1"
},
{
"input": "6 2 -100",
"output": "4"
},
{
"input": "5 3 -100",
"output": "3"
},
{
"input": "5 4 3",
"output": "2"
},
{
"input": "3 2 2",
"output": "1"
},
{
"input": "5 5 2",
"output": "2"
},
{
"input": "3 2 5",
"output": "1"
},
{
"input": "5 5 -1",
"output": "4"
},
{
"input": "5 3 3",
"output": "1"
},
{
"input": "4 2 3",
"output": "1"
},
{
"input": "88 76 74",
"output": "62"
}
] | 1,615,194,498 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 62 | 307,200 | n, a, b = map(int, input().split())
mas =[f for f in range(1, n+1)]
if n == 1:
print(1)
elif b >= 0 and len(mas) >= a + b:
print(a + b)
elif b < 0:
if abs(a+b) <= len(mas):
print(mas[a+b-1])
else:
remains = b % len(mas)
print(mas[remains])
else:
remains = b % len(mas)
print(mas[remains + 1]) | Title: Round House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in the direction of increasing numbers (in this order entrance *n* should be followed by entrance 1). The negative value of *b* corresponds to moving |*b*| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance *n*). If *b*<==<=0, then Vasya prefers to walk beside his entrance.
Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.
Input Specification:
The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.
Output Specification:
Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk.
Demo Input:
['6 2 -5\n', '5 1 3\n', '3 2 7\n']
Demo Output:
['3\n', '4\n', '3\n']
Note:
The first example is illustrated by the picture in the statements. | ```python
n, a, b = map(int, input().split())
mas =[f for f in range(1, n+1)]
if n == 1:
print(1)
elif b >= 0 and len(mas) >= a + b:
print(a + b)
elif b < 0:
if abs(a+b) <= len(mas):
print(mas[a+b-1])
else:
remains = b % len(mas)
print(mas[remains])
else:
remains = b % len(mas)
print(mas[remains + 1])
``` | 0 |
|
557 | B | Pasha and Tea | PROGRAMMING | 1,500 | [
"constructive algorithms",
"implementation",
"math",
"sortings"
] | null | null | Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water.
It turned out that among Pasha's friends there are exactly *n* boys and exactly *n* girls and all of them are going to come to the tea party. To please everyone, Pasha decided to pour the water for the tea as follows:
- Pasha can boil the teapot exactly once by pouring there at most *w* milliliters of water; - Pasha pours the same amount of water to each girl; - Pasha pours the same amount of water to each boy; - if each girl gets *x* milliliters of water, then each boy gets 2*x* milliliters of water.
In the other words, each boy should get two times more water than each girl does.
Pasha is very kind and polite, so he wants to maximize the total amount of the water that he pours to his friends. Your task is to help him and determine the optimum distribution of cups between Pasha's friends. | The first line of the input contains two integers, *n* and *w* (1<=≤<=*n*<=≤<=105, 1<=≤<=*w*<=≤<=109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters.
The second line of the input contains the sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=109, 1<=≤<=*i*<=≤<=2*n*) — the capacities of Pasha's tea cups in milliliters. | Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6. | [
"2 4\n1 1 1 1\n",
"3 18\n4 4 4 2 2 2\n",
"1 5\n2 3\n"
] | [
"3",
"18",
"4.5"
] | Pasha also has candies that he is going to give to girls but that is another task... | 1,000 | [
{
"input": "2 4\n1 1 1 1",
"output": "3.0000000000"
},
{
"input": "3 18\n4 4 4 2 2 2",
"output": "18.0000000000"
},
{
"input": "1 5\n2 3",
"output": "4.5000000000"
},
{
"input": "1 1\n1000000000 1000000000",
"output": "1.0000000000"
},
{
"input": "4 1000000000\n1 1 1 1 1 1 1 1",
"output": "6.0000000000"
},
{
"input": "4 1000000000\n1 1 1 1 2 2 2 2",
"output": "12.0000000000"
},
{
"input": "4 1\n3 3 3 3 4 4 4 4",
"output": "1.0000000000"
},
{
"input": "2 19\n3 3 5 5",
"output": "15.0000000000"
},
{
"input": "3 31\n3 3 3 5 5 5",
"output": "22.5000000000"
},
{
"input": "5 15\n2 3 4 1 2 4 5 3 5 10",
"output": "15.0000000000"
},
{
"input": "5 14\n2 3 4 1 2 4 5 3 5 10",
"output": "14.0000000000"
},
{
"input": "5 16\n2 3 4 1 2 4 5 3 5 10",
"output": "15.0000000000"
},
{
"input": "1 100\n1 200",
"output": "3.0000000000"
},
{
"input": "1 1\n1 1",
"output": "1.0000000000"
},
{
"input": "2 1000000000\n1 1 1 100",
"output": "3.0000000000"
},
{
"input": "4 30\n3 3 3 3 4 5 6 7",
"output": "24.0000000000"
},
{
"input": "2 100\n1 1 1 10",
"output": "3.0000000000"
},
{
"input": "3 18\n1 1 1 1 1 5",
"output": "4.5000000000"
}
] | 1,435,688,566 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 217 | 17,408,000 | n, w = [int(i) for i in input().split()]
a = sorted([int(i) for i in input().split()])
if a[0] > (w/3)/n and a[n] > 2*(w/3)/n:
print(w)
else:
print(min(a[n]/2, a[0])*3*n)
| Title: Pasha and Tea
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water.
It turned out that among Pasha's friends there are exactly *n* boys and exactly *n* girls and all of them are going to come to the tea party. To please everyone, Pasha decided to pour the water for the tea as follows:
- Pasha can boil the teapot exactly once by pouring there at most *w* milliliters of water; - Pasha pours the same amount of water to each girl; - Pasha pours the same amount of water to each boy; - if each girl gets *x* milliliters of water, then each boy gets 2*x* milliliters of water.
In the other words, each boy should get two times more water than each girl does.
Pasha is very kind and polite, so he wants to maximize the total amount of the water that he pours to his friends. Your task is to help him and determine the optimum distribution of cups between Pasha's friends.
Input Specification:
The first line of the input contains two integers, *n* and *w* (1<=≤<=*n*<=≤<=105, 1<=≤<=*w*<=≤<=109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters.
The second line of the input contains the sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=109, 1<=≤<=*i*<=≤<=2*n*) — the capacities of Pasha's tea cups in milliliters.
Output Specification:
Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6.
Demo Input:
['2 4\n1 1 1 1\n', '3 18\n4 4 4 2 2 2\n', '1 5\n2 3\n']
Demo Output:
['3', '18', '4.5']
Note:
Pasha also has candies that he is going to give to girls but that is another task... | ```python
n, w = [int(i) for i in input().split()]
a = sorted([int(i) for i in input().split()])
if a[0] > (w/3)/n and a[n] > 2*(w/3)/n:
print(w)
else:
print(min(a[n]/2, a[0])*3*n)
``` | 3 |
|
548 | A | Mike and Fax | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages in his own bag, each was a palindrome string and all those strings had the same length.
He asked you to help him and tell him if he has worn his own back-bag. Check if the given string *s* is a concatenation of *k* palindromes of the same length. | The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000).
The second line contains integer *k* (1<=≤<=*k*<=≤<=1000). | Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. | [
"saba\n2\n",
"saddastavvat\n2\n"
] | [
"NO\n",
"YES\n"
] | Palindrome is a string reading the same forward and backward.
In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | 500 | [
{
"input": "saba\n2",
"output": "NO"
},
{
"input": "saddastavvat\n2",
"output": "YES"
},
{
"input": "aaaaaaaaaa\n3",
"output": "NO"
},
{
"input": "aaaaaa\n3",
"output": "YES"
},
{
"input": "abaacca\n2",
"output": "NO"
},
{
"input": "a\n1",
"output": "YES"
},
{
"input": "princeofpersia\n1",
"output": "NO"
},
{
"input": "xhwbdoryfiaxglripavycmxmcejbcpzidrqsqvikfzjyfnmedxrvlnusavyhillaxrblkynwdrlhthtqzjktzkullgrqsolqssocpfwcaizhovajlhmeibhiuwtxpljkyyiwykzpmazkkzampzkywiyykjlpxtwuihbiemhljavohziacwfpcossqlosqrgllukztkjzqththlrdwnyklbrxallihyvasunlvrxdemnfyjzfkivqsqrdizpcbjecmxmcyvapirlgxaifyrodbwhx\n1",
"output": "YES"
},
{
"input": "yfhqnbzaqeqmcvtsbcdn\n456",
"output": "NO"
},
{
"input": "lgsdfiforlqrohhjyzrigewkigiiffvbyrapzmjvtkklndeyuqpuukajgtguhlarjdqlxksyekbjgrmhuyiqdlzjqqzlxufffpelyptodwhvkfbalxbufrlcsjgxmfxeqsszqghcustqrqjljattgvzynyvfbjgbuynbcguqtyfowgtcbbaywvcrgzrulqpghwoflutswu\n584",
"output": "NO"
},
{
"input": "awlrhmxxivqbntvtapwkdkunamcqoerfncfmookhdnuxtttlxmejojpwbdyxirdsjippzjhdrpjepremruczbedxrjpodlyyldopjrxdebzcurmerpejprdhjzppijsdrixydbwpjojemxltttxundhkoomfcnfreoqcmanukdkwpatvtnbqvixxmhrlwa\n1",
"output": "YES"
},
{
"input": "kafzpsglcpzludxojtdhzynpbekzssvhzizfrboxbhqvojiqtjitrackqccxgenwwnegxccqkcartijtqijovqhbxobrfzizhvsszkebpnyzhdtjoxdulzpclgspzfakvcbbjejeubvrrzlvjjgrcprntbyuakoxowoybbxgdugjffgbtfwrfiobifrshyaqqayhsrfiboifrwftbgffjgudgxbbyowoxokauybtnrpcrgjjvlzrrvbuejejbbcv\n2",
"output": "YES"
},
{
"input": "zieqwmmbrtoxysvavwdemmdeatfrolsqvvlgphhhmojjfxfurtuiqdiilhlcwwqedlhblrzmvuoaczcwrqzyymiggpvbpkycibsvkhytrzhguksxyykkkvfljbbnjblylftmqxkojithwsegzsaexlpuicexbdzpwesrkzbqltxhifwqcehzsjgsqbwkujvjbjpqxdpmlimsusumizizpyigmkxwuberthdghnepyrxzvvidxeafwylegschhtywvqsxuqmsddhkzgkdiekodqpnftdyhnpicsnbhfxemxllvaurkmjvtrmqkulerxtaolmokiqqvqgechkqxmendpmgxwiaffcajmqjmvrwryzxujmiasuqtosuisiclnv\n8",
"output": "NO"
},
{
"input": "syghzncbi\n829",
"output": "NO"
},
{
"input": "ljpdpstntznciejqqtpysskztdfawuncqzwwfefrfsihyrdopwawowshquqnjhesxszuywezpebpzhtopgngrnqgwnoqhyrykojguybvdbjpfpmvkxscocywzsxcivysfrrzsonayztzzuybrkiombhqcfkszyscykzistiobrpavezedgobowjszfadcccmxyqehmkgywiwxffibzetb\n137",
"output": "NO"
},
{
"input": "eytuqriplfczwsqlsnjetfpzehzvzayickkbnfqddaisfpasvigwtnvbybwultsgrtjbaebktvubwofysgidpufzteuhuaaqkhmhguockoczlrmlrrzouvqtwbcchxxiydbohnvrmtqjzhkfmvdulojhdvgwudvidpausvfujkjprxsobliuauxleqvsmz\n253",
"output": "NO"
},
{
"input": "xkaqgwabuilhuqwhnrdtyattmqcjfbiqodjlwzgcyvghqncklbhnlmagvjvwysrfryrlmclninogumjfmyenkmydlmifxpkvlaapgnfarejaowftxxztshsesjtsgommaeslrhronruqdurvjesydrzmxirmxumrcqezznqltngsgdcthivdnjnshjfujtiqsltpttgbljfcbqsfwbzokciqlavrthgaqbzikpwwsebzwddlvdwrmztwmhcxdinwlbklwmteeybbdbzevfbsrtldapulwgusuvnreiflkytonzmervyrlbqhzapgxepwauaiwygpxarfeyqhimzlxntjuaaigeisgrvwgbhqemqetzyallzaoqprhzpjibkutgwrodruqu\n857",
"output": "NO"
},
{
"input": "rbehjxpblnzfgeebpkvzznwtzszghjuuxovreapmwehqyjymrkmksffbdpbdyegulabsmjiykeeqtuvqqyxlitpxjdpwmqtlmudqsksgwqekvwfjdsggzajcpsyserkctpbajgzdbiqaekfaepnecezdzamqszpwfvhlannszgaiewvcdnnvzhblmuzjtqeyjcqjqoxatavavokyxokuxwuqueskktxnxraihnqovrfykpzsyjmrhqsvbobzsnfqwvdwatvjxaubtiwhgvrqwjhgfnauqegqmcwnaruinplmtmxhvohhqgvcatsdqiwkvslhqzqevdgdhpijjevuyuitnixdjhwlmjsstmugownjdhvxueg\n677",
"output": "NO"
},
{
"input": "a\n3",
"output": "NO"
},
{
"input": "aa\n2",
"output": "YES"
},
{
"input": "abcaabca\n2",
"output": "NO"
},
{
"input": "aaaaaaaaab\n5",
"output": "NO"
},
{
"input": "aabbb\n3",
"output": "NO"
},
{
"input": "abcde\n5",
"output": "YES"
},
{
"input": "aabc\n2",
"output": "NO"
},
{
"input": "aabcaa\n3",
"output": "NO"
}
] | 1,432,668,244 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | s = input()
k = int(input())
if len(s) % k != 0:
print('NO')
lenS = len(s)
for i in range(0, len(s), lenS//k):
if s[i:i+lenS//k] != s[i:i+lenS//k][::-1]:
print('NO')
break
else:
print('YES')
| Title: Mike and Fax
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*.
He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages in his own bag, each was a palindrome string and all those strings had the same length.
He asked you to help him and tell him if he has worn his own back-bag. Check if the given string *s* is a concatenation of *k* palindromes of the same length.
Input Specification:
The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000).
The second line contains integer *k* (1<=≤<=*k*<=≤<=1000).
Output Specification:
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
Demo Input:
['saba\n2\n', 'saddastavvat\n2\n']
Demo Output:
['NO\n', 'YES\n']
Note:
Palindrome is a string reading the same forward and backward.
In the second sample, the faxes in his back-bag can be "saddas" and "tavvat". | ```python
s = input()
k = int(input())
if len(s) % k != 0:
print('NO')
lenS = len(s)
for i in range(0, len(s), lenS//k):
if s[i:i+lenS//k] != s[i:i+lenS//k][::-1]:
print('NO')
break
else:
print('YES')
``` | 0 |
|
644 | B | Processing Queries | PROGRAMMING | 1,700 | [
"*special",
"constructive algorithms",
"data structures",
"two pointers"
] | null | null | In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* are guaranteed to be distinct.
When a query appears server may react in three possible ways:
1. If server is free and query queue is empty, then server immediately starts to process this query. 1. If server is busy and there are less than *b* queries in the queue, then new query is added to the end of the queue. 1. If server is busy and there are already *b* queries pending in the queue, then new query is just rejected and will never be processed.
As soon as server finished to process some query, it picks new one from the queue (if it's not empty, of course). If a new query comes at some moment *x*, and the server finishes to process another query at exactly the same moment, we consider that first query is picked from the queue and only then new query appears.
For each query find the moment when the server will finish to process it or print -1 if this query will be rejected. | The first line of the input contains two integers *n* and *b* (1<=≤<=*n*,<=*b*<=≤<=200<=000) — the number of queries and the maximum possible size of the query queue.
Then follow *n* lines with queries descriptions (in chronological order). Each description consists of two integers *t**i* and *d**i* (1<=≤<=*t**i*,<=*d**i*<=≤<=109), where *t**i* is the moment of time when the *i*-th query appears and *d**i* is the time server needs to process it. It is guaranteed that *t**i*<=-<=1<=<<=*t**i* for all *i*<=><=1. | Print the sequence of *n* integers *e*1,<=*e*2,<=...,<=*e**n*, where *e**i* is the moment the server will finish to process the *i*-th query (queries are numbered in the order they appear in the input) or <=-<=1 if the corresponding query will be rejected. | [
"5 1\n2 9\n4 8\n10 9\n15 2\n19 1\n",
"4 1\n2 8\n4 8\n10 9\n15 2\n"
] | [
"11 19 -1 21 22 \n",
"10 18 27 -1 \n"
] | Consider the first sample.
1. The server will start to process first query at the moment 2 and will finish to process it at the moment 11. 1. At the moment 4 second query appears and proceeds to the queue. 1. At the moment 10 third query appears. However, the server is still busy with query 1, *b* = 1 and there is already query 2 pending in the queue, so third query is just rejected. 1. At the moment 11 server will finish to process first query and will take the second query from the queue. 1. At the moment 15 fourth query appears. As the server is currently busy it proceeds to the queue. 1. At the moment 19 two events occur simultaneously: server finishes to proceed the second query and the fifth query appears. As was said in the statement above, first server will finish to process the second query, then it will pick the fourth query from the queue and only then will the fifth query appear. As the queue is empty fifth query is proceed there. 1. Server finishes to process query number 4 at the moment 21. Query number 5 is picked from the queue. 1. Server finishes to process query number 5 at the moment 22. | 1,000 | [
{
"input": "5 1\n2 9\n4 8\n10 9\n15 2\n19 1",
"output": "11 19 -1 21 22 "
},
{
"input": "4 1\n2 8\n4 8\n10 9\n15 2",
"output": "10 18 27 -1 "
},
{
"input": "1 1\n1000000000 1000000000",
"output": "2000000000 "
},
{
"input": "4 3\n999999996 1000000000\n999999997 1000000000\n999999998 1000000000\n999999999 1000000000",
"output": "1999999996 2999999996 3999999996 4999999996 "
},
{
"input": "5 1\n2 1\n3 6\n4 5\n6 4\n7 2",
"output": "3 9 14 -1 -1 "
},
{
"input": "10 2\n4 14\n5 2\n6 6\n7 11\n8 6\n9 5\n10 13\n11 8\n13 2\n20 2",
"output": "18 20 26 -1 -1 -1 -1 -1 -1 28 "
},
{
"input": "6 4\n2 4\n4 2\n5 2\n6 2\n7 2\n9 2",
"output": "6 8 10 12 14 16 "
},
{
"input": "8 3\n1 2\n3 1\n4 3\n5 3\n6 1\n7 2\n8 8\n9 7",
"output": "3 4 7 10 11 13 21 -1 "
},
{
"input": "10 3\n1 14\n3 2\n5 4\n6 9\n9 1\n12 22\n15 11\n18 8\n28 2\n29 4",
"output": "15 17 21 30 -1 -1 41 49 51 -1 "
},
{
"input": "5 2\n2 7\n3 3\n7 4\n9 1\n10 2",
"output": "9 12 16 17 -1 "
},
{
"input": "4 1\n2 1\n6 5\n9 2\n10 3",
"output": "3 11 13 -1 "
},
{
"input": "4 1\n1 2\n2 1\n3 1\n4 3",
"output": "3 4 5 8 "
},
{
"input": "6 3\n1 2\n2 3\n100 200\n200 300\n10000 20000\n20000 30000",
"output": "3 6 300 600 30000 60000 "
}
] | 1,458,123,632 | 4,832 | PyPy 3 | OK | TESTS | 71 | 4,180 | 19,968,000 | from collections import deque
n, b = map(int, input().split())
q = deque()
for _ in range(n):
t, d = map(int, input().split())
while q and q[0] <= t:
q.popleft()
if len(q) == b + 1:
print(-1, end = ' ')
else:
if q:
t = q[-1]
print(t + d, end = ' ')
q.append(t + d)
| Title: Processing Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* are guaranteed to be distinct.
When a query appears server may react in three possible ways:
1. If server is free and query queue is empty, then server immediately starts to process this query. 1. If server is busy and there are less than *b* queries in the queue, then new query is added to the end of the queue. 1. If server is busy and there are already *b* queries pending in the queue, then new query is just rejected and will never be processed.
As soon as server finished to process some query, it picks new one from the queue (if it's not empty, of course). If a new query comes at some moment *x*, and the server finishes to process another query at exactly the same moment, we consider that first query is picked from the queue and only then new query appears.
For each query find the moment when the server will finish to process it or print -1 if this query will be rejected.
Input Specification:
The first line of the input contains two integers *n* and *b* (1<=≤<=*n*,<=*b*<=≤<=200<=000) — the number of queries and the maximum possible size of the query queue.
Then follow *n* lines with queries descriptions (in chronological order). Each description consists of two integers *t**i* and *d**i* (1<=≤<=*t**i*,<=*d**i*<=≤<=109), where *t**i* is the moment of time when the *i*-th query appears and *d**i* is the time server needs to process it. It is guaranteed that *t**i*<=-<=1<=<<=*t**i* for all *i*<=><=1.
Output Specification:
Print the sequence of *n* integers *e*1,<=*e*2,<=...,<=*e**n*, where *e**i* is the moment the server will finish to process the *i*-th query (queries are numbered in the order they appear in the input) or <=-<=1 if the corresponding query will be rejected.
Demo Input:
['5 1\n2 9\n4 8\n10 9\n15 2\n19 1\n', '4 1\n2 8\n4 8\n10 9\n15 2\n']
Demo Output:
['11 19 -1 21 22 \n', '10 18 27 -1 \n']
Note:
Consider the first sample.
1. The server will start to process first query at the moment 2 and will finish to process it at the moment 11. 1. At the moment 4 second query appears and proceeds to the queue. 1. At the moment 10 third query appears. However, the server is still busy with query 1, *b* = 1 and there is already query 2 pending in the queue, so third query is just rejected. 1. At the moment 11 server will finish to process first query and will take the second query from the queue. 1. At the moment 15 fourth query appears. As the server is currently busy it proceeds to the queue. 1. At the moment 19 two events occur simultaneously: server finishes to proceed the second query and the fifth query appears. As was said in the statement above, first server will finish to process the second query, then it will pick the fourth query from the queue and only then will the fifth query appear. As the queue is empty fifth query is proceed there. 1. Server finishes to process query number 4 at the moment 21. Query number 5 is picked from the queue. 1. Server finishes to process query number 5 at the moment 22. | ```python
from collections import deque
n, b = map(int, input().split())
q = deque()
for _ in range(n):
t, d = map(int, input().split())
while q and q[0] <= t:
q.popleft()
if len(q) == b + 1:
print(-1, end = ' ')
else:
if q:
t = q[-1]
print(t + d, end = ' ')
q.append(t + d)
``` | 3 |
|
316 | D2 | PE Lesson | PROGRAMMING | 2,300 | [
"dp"
] | null | null | Smart Beaver decided to be not only smart, but also a healthy beaver! And so he began to attend physical education classes at school X. In this school, physical education has a very creative teacher. One of his favorite warm-up exercises is throwing balls. Students line up. Each one gets a single ball in the beginning. The balls are numbered from 1 to *n* (by the demand of the inventory commission).
After receiving the balls the students perform the warm-up exercise. The exercise takes place in a few throws. For each throw the teacher chooses any two arbitrary different students who will participate in it. The selected students throw their balls to each other. Thus, after each throw the students remain in their positions, and the two balls are swapped.
In this case there was a throw between the students, who were holding the 2-nd and the 4-th balls. Since the warm-up has many exercises, each of them can only continue for little time. Therefore, for each student we know the maximum number of throws he can participate in. For this lessons maximum number of throws will be 1 or 2.
Note that after all phases of the considered exercise any ball can end up with any student. Smart Beaver decided to formalize it and introduced the concept of the "ball order". The ball order is a sequence of *n* numbers that correspond to the order of balls in the line. The first number will match the number of the ball of the first from the left student in the line, the second number will match the ball of the second student, and so on. For example, in figure 2 the order of the balls was (1, 2, 3, 4, 5), and after the throw it was (1, 4, 3, 2, 5). Smart beaver knows the number of students and for each student he knows the maximum number of throws in which he can participate. And now he is wondering: what is the number of distinct ways of ball orders by the end of the exercise. | The first line contains a single number *n* — the number of students in the line and the number of balls. The next line contains exactly *n* space-separated integers. Each number corresponds to a student in the line (the *i*-th number corresponds to the *i*-th from the left student in the line) and shows the number of throws he can participate in.
The input limits for scoring 30 points are (subproblem D1):
- 1<=≤<=*n*<=≤<=10.
The input limits for scoring 70 points are (subproblems D1+D2):
- 1<=≤<=*n*<=≤<=500.
The input limits for scoring 100 points are (subproblems D1+D2+D3):
- 1<=≤<=*n*<=≤<=1000000. | The output should contain a single integer — the number of variants of ball orders after the warm up exercise is complete. As the number can be rather large, print it modulo 1000000007 (109<=+<=7). | [
"5\n1 2 2 1 2\n",
"8\n1 2 2 1 2 1 1 2\n"
] | [
"120\n",
"16800\n"
] | none | 40 | [] | 1,391,171,925 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS2 | 0 | 3,000 | 4,710,400 | def sp(a,b):
if (b==0):
return 1
t=sp(a,b//2)
t=t*t
if (b%2==1):
t=t*a
return t
print(sp(7,20000000))
| Title: PE Lesson
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Smart Beaver decided to be not only smart, but also a healthy beaver! And so he began to attend physical education classes at school X. In this school, physical education has a very creative teacher. One of his favorite warm-up exercises is throwing balls. Students line up. Each one gets a single ball in the beginning. The balls are numbered from 1 to *n* (by the demand of the inventory commission).
After receiving the balls the students perform the warm-up exercise. The exercise takes place in a few throws. For each throw the teacher chooses any two arbitrary different students who will participate in it. The selected students throw their balls to each other. Thus, after each throw the students remain in their positions, and the two balls are swapped.
In this case there was a throw between the students, who were holding the 2-nd and the 4-th balls. Since the warm-up has many exercises, each of them can only continue for little time. Therefore, for each student we know the maximum number of throws he can participate in. For this lessons maximum number of throws will be 1 or 2.
Note that after all phases of the considered exercise any ball can end up with any student. Smart Beaver decided to formalize it and introduced the concept of the "ball order". The ball order is a sequence of *n* numbers that correspond to the order of balls in the line. The first number will match the number of the ball of the first from the left student in the line, the second number will match the ball of the second student, and so on. For example, in figure 2 the order of the balls was (1, 2, 3, 4, 5), and after the throw it was (1, 4, 3, 2, 5). Smart beaver knows the number of students and for each student he knows the maximum number of throws in which he can participate. And now he is wondering: what is the number of distinct ways of ball orders by the end of the exercise.
Input Specification:
The first line contains a single number *n* — the number of students in the line and the number of balls. The next line contains exactly *n* space-separated integers. Each number corresponds to a student in the line (the *i*-th number corresponds to the *i*-th from the left student in the line) and shows the number of throws he can participate in.
The input limits for scoring 30 points are (subproblem D1):
- 1<=≤<=*n*<=≤<=10.
The input limits for scoring 70 points are (subproblems D1+D2):
- 1<=≤<=*n*<=≤<=500.
The input limits for scoring 100 points are (subproblems D1+D2+D3):
- 1<=≤<=*n*<=≤<=1000000.
Output Specification:
The output should contain a single integer — the number of variants of ball orders after the warm up exercise is complete. As the number can be rather large, print it modulo 1000000007 (109<=+<=7).
Demo Input:
['5\n1 2 2 1 2\n', '8\n1 2 2 1 2 1 1 2\n']
Demo Output:
['120\n', '16800\n']
Note:
none | ```python
def sp(a,b):
if (b==0):
return 1
t=sp(a,b//2)
t=t*t
if (b%2==1):
t=t*a
return t
print(sp(7,20000000))
``` | 0 |
|
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.
Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party. | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 586975278",
"output": "1"
},
{
"input": "259504825 377489979 588153796 377489979",
"output": "1"
},
{
"input": "652588203 931100304 931100304 652588203",
"output": "2"
},
{
"input": "391958720 651507265 391958720 651507265",
"output": "2"
},
{
"input": "90793237 90793237 90793237 90793237",
"output": "3"
},
{
"input": "551651653 551651653 551651653 551651653",
"output": "3"
},
{
"input": "156630260 609654355 668943582 973622757",
"output": "0"
},
{
"input": "17061017 110313588 434481173 796661222",
"output": "0"
},
{
"input": "24975422 256716298 337790533 690960249",
"output": "0"
},
{
"input": "255635360 732742923 798648949 883146723",
"output": "0"
},
{
"input": "133315691 265159773 734556507 265159773",
"output": "1"
},
{
"input": "28442865 741657755 978106882 978106882",
"output": "1"
},
{
"input": "131245479 174845575 497483467 131245479",
"output": "1"
},
{
"input": "139159884 616215581 958341883 616215581",
"output": "1"
},
{
"input": "147784432 947653080 947653080 947653080",
"output": "2"
},
{
"input": "94055790 756126496 756126496 94055790",
"output": "2"
},
{
"input": "240458500 511952208 240458500 511952208",
"output": "2"
},
{
"input": "681828506 972810624 972810624 681828506",
"output": "2"
},
{
"input": "454961014 454961014 454961014 454961014",
"output": "3"
},
{
"input": "915819430 915819430 915819430 915819430",
"output": "3"
},
{
"input": "671645142 671645142 671645142 671645142",
"output": "3"
},
{
"input": "132503558 132503558 132503558 132503558",
"output": "3"
},
{
"input": "5 5 999999 6",
"output": "1"
},
{
"input": "1 1 2 5",
"output": "1"
},
{
"input": "2 1 2 3",
"output": "1"
},
{
"input": "1 1 3 5",
"output": "1"
},
{
"input": "1 1 3 3",
"output": "2"
},
{
"input": "2 2 2 1",
"output": "2"
},
{
"input": "3 1 1 1",
"output": "2"
},
{
"input": "1 2 2 2",
"output": "2"
}
] | 1,691,292,942 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 124 | 0 | s = [int(e) for e in input().split(' ')]
seen, c = [], 0
for e in s:
if e in seen:
c += 1
continue
seen += [e]
print(c) | Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.
Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
Input Specification:
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers.
Output Specification:
Print a single integer — the minimum number of horseshoes Valera needs to buy.
Demo Input:
['1 7 3 3\n', '7 7 7 7\n']
Demo Output:
['1\n', '3\n']
Note:
none | ```python
s = [int(e) for e in input().split(' ')]
seen, c = [], 0
for e in s:
if e in seen:
c += 1
continue
seen += [e]
print(c)
``` | 3 |
|
633 | A | Ebony and Ivory | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of damage. In order to break the shield Dante has to deal exactly *c* units of damage. Find out if this is possible. | The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. | Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. | [
"4 6 15\n",
"3 2 7\n",
"6 11 6\n"
] | [
"No\n",
"Yes\n",
"Yes\n"
] | In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage. | 250 | [
{
"input": "4 6 15",
"output": "No"
},
{
"input": "3 2 7",
"output": "Yes"
},
{
"input": "6 11 6",
"output": "Yes"
},
{
"input": "3 12 15",
"output": "Yes"
},
{
"input": "5 5 10",
"output": "Yes"
},
{
"input": "6 6 7",
"output": "No"
},
{
"input": "1 1 20",
"output": "Yes"
},
{
"input": "12 14 19",
"output": "No"
},
{
"input": "15 12 26",
"output": "No"
},
{
"input": "2 4 8",
"output": "Yes"
},
{
"input": "4 5 30",
"output": "Yes"
},
{
"input": "4 5 48",
"output": "Yes"
},
{
"input": "2 17 105",
"output": "Yes"
},
{
"input": "10 25 282",
"output": "No"
},
{
"input": "6 34 323",
"output": "No"
},
{
"input": "2 47 464",
"output": "Yes"
},
{
"input": "4 53 113",
"output": "Yes"
},
{
"input": "6 64 546",
"output": "Yes"
},
{
"input": "1 78 725",
"output": "Yes"
},
{
"input": "1 84 811",
"output": "Yes"
},
{
"input": "3 100 441",
"output": "Yes"
},
{
"input": "20 5 57",
"output": "No"
},
{
"input": "14 19 143",
"output": "No"
},
{
"input": "17 23 248",
"output": "No"
},
{
"input": "11 34 383",
"output": "Yes"
},
{
"input": "20 47 568",
"output": "Yes"
},
{
"input": "16 58 410",
"output": "Yes"
},
{
"input": "11 70 1199",
"output": "Yes"
},
{
"input": "16 78 712",
"output": "Yes"
},
{
"input": "20 84 562",
"output": "No"
},
{
"input": "19 100 836",
"output": "Yes"
},
{
"input": "23 10 58",
"output": "No"
},
{
"input": "25 17 448",
"output": "Yes"
},
{
"input": "22 24 866",
"output": "Yes"
},
{
"input": "24 35 67",
"output": "No"
},
{
"input": "29 47 264",
"output": "Yes"
},
{
"input": "23 56 45",
"output": "No"
},
{
"input": "25 66 1183",
"output": "Yes"
},
{
"input": "21 71 657",
"output": "Yes"
},
{
"input": "29 81 629",
"output": "No"
},
{
"input": "23 95 2226",
"output": "Yes"
},
{
"input": "32 4 62",
"output": "No"
},
{
"input": "37 15 789",
"output": "Yes"
},
{
"input": "39 24 999",
"output": "Yes"
},
{
"input": "38 32 865",
"output": "No"
},
{
"input": "32 50 205",
"output": "No"
},
{
"input": "31 57 1362",
"output": "Yes"
},
{
"input": "38 68 1870",
"output": "Yes"
},
{
"input": "36 76 549",
"output": "No"
},
{
"input": "35 84 1257",
"output": "No"
},
{
"input": "39 92 2753",
"output": "Yes"
},
{
"input": "44 1 287",
"output": "Yes"
},
{
"input": "42 12 830",
"output": "No"
},
{
"input": "42 27 9",
"output": "No"
},
{
"input": "49 40 1422",
"output": "No"
},
{
"input": "44 42 2005",
"output": "No"
},
{
"input": "50 55 2479",
"output": "No"
},
{
"input": "48 65 917",
"output": "No"
},
{
"input": "45 78 152",
"output": "No"
},
{
"input": "43 90 4096",
"output": "Yes"
},
{
"input": "43 94 4316",
"output": "Yes"
},
{
"input": "60 7 526",
"output": "Yes"
},
{
"input": "53 11 735",
"output": "Yes"
},
{
"input": "52 27 609",
"output": "Yes"
},
{
"input": "57 32 992",
"output": "Yes"
},
{
"input": "52 49 421",
"output": "No"
},
{
"input": "57 52 2634",
"output": "Yes"
},
{
"input": "54 67 3181",
"output": "Yes"
},
{
"input": "52 73 638",
"output": "No"
},
{
"input": "57 84 3470",
"output": "No"
},
{
"input": "52 100 5582",
"output": "No"
},
{
"input": "62 1 501",
"output": "Yes"
},
{
"input": "63 17 858",
"output": "Yes"
},
{
"input": "70 24 1784",
"output": "Yes"
},
{
"input": "65 32 1391",
"output": "Yes"
},
{
"input": "62 50 2775",
"output": "No"
},
{
"input": "62 58 88",
"output": "No"
},
{
"input": "66 68 3112",
"output": "Yes"
},
{
"input": "61 71 1643",
"output": "No"
},
{
"input": "69 81 3880",
"output": "No"
},
{
"input": "63 100 1960",
"output": "Yes"
},
{
"input": "73 6 431",
"output": "Yes"
},
{
"input": "75 19 736",
"output": "Yes"
},
{
"input": "78 25 247",
"output": "No"
},
{
"input": "79 36 2854",
"output": "Yes"
},
{
"input": "80 43 1864",
"output": "Yes"
},
{
"input": "76 55 2196",
"output": "Yes"
},
{
"input": "76 69 4122",
"output": "Yes"
},
{
"input": "76 76 4905",
"output": "No"
},
{
"input": "75 89 3056",
"output": "Yes"
},
{
"input": "73 100 3111",
"output": "Yes"
},
{
"input": "84 9 530",
"output": "No"
},
{
"input": "82 18 633",
"output": "No"
},
{
"input": "85 29 2533",
"output": "Yes"
},
{
"input": "89 38 2879",
"output": "Yes"
},
{
"input": "89 49 2200",
"output": "Yes"
},
{
"input": "88 60 4140",
"output": "Yes"
},
{
"input": "82 68 1299",
"output": "No"
},
{
"input": "90 76 2207",
"output": "No"
},
{
"input": "83 84 4923",
"output": "Yes"
},
{
"input": "89 99 7969",
"output": "Yes"
},
{
"input": "94 9 168",
"output": "No"
},
{
"input": "91 20 1009",
"output": "No"
},
{
"input": "93 23 2872",
"output": "Yes"
},
{
"input": "97 31 3761",
"output": "Yes"
},
{
"input": "99 46 1341",
"output": "Yes"
},
{
"input": "98 51 2845",
"output": "No"
},
{
"input": "93 66 3412",
"output": "No"
},
{
"input": "95 76 3724",
"output": "Yes"
},
{
"input": "91 87 6237",
"output": "Yes"
},
{
"input": "98 97 7886",
"output": "Yes"
},
{
"input": "12 17 15",
"output": "No"
},
{
"input": "93 94 95",
"output": "No"
},
{
"input": "27 43 27",
"output": "Yes"
},
{
"input": "17 43 68",
"output": "Yes"
},
{
"input": "44 12 12",
"output": "Yes"
},
{
"input": "44 50 150",
"output": "Yes"
},
{
"input": "1 1 10000",
"output": "Yes"
},
{
"input": "2 3 10000",
"output": "Yes"
},
{
"input": "100 1 10",
"output": "Yes"
},
{
"input": "3 2 1",
"output": "No"
},
{
"input": "1 1 1",
"output": "Yes"
},
{
"input": "9 9 10000",
"output": "No"
},
{
"input": "2 3 9995",
"output": "Yes"
},
{
"input": "3 5 4",
"output": "No"
},
{
"input": "99 98 100",
"output": "No"
},
{
"input": "6 10 2",
"output": "No"
},
{
"input": "1 6 5",
"output": "Yes"
},
{
"input": "1 4 3",
"output": "Yes"
},
{
"input": "3 2 3",
"output": "Yes"
},
{
"input": "1 7 6",
"output": "Yes"
},
{
"input": "2 3 9871",
"output": "Yes"
},
{
"input": "10 5 5",
"output": "Yes"
},
{
"input": "10 8 2",
"output": "No"
}
] | 1,497,971,516 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 117 | 62 | 5,529,600 | from sys import exit
a, b, c = [int(i) for i in input().split()]
for i in range(101):
for j in range(101):
if a * i + b * j == c:
print("Yes")
exit(0)
print("No")
| Title: Ebony and Ivory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of damage. In order to break the shield Dante has to deal exactly *c* units of damage. Find out if this is possible.
Input Specification:
The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively.
Output Specification:
Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise.
Demo Input:
['4 6 15\n', '3 2 7\n', '6 11 6\n']
Demo Output:
['No\n', 'Yes\n', 'Yes\n']
Note:
In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage. | ```python
from sys import exit
a, b, c = [int(i) for i in input().split()]
for i in range(101):
for j in range(101):
if a * i + b * j == c:
print("Yes")
exit(0)
print("No")
``` | 0 |
|
745 | B | Hongcow Solves A Puzzle | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an *n* by *m* grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.
The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.
You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position. | The first line of input will contain two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=500), the dimensions of the puzzle piece.
The next *n* lines will describe the jigsaw piece. Each line will have length *m* and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space.
It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region. | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | [
"2 3\nXXX\nXXX\n",
"2 2\n.X\nXX\n",
"5 5\n.....\n..X..\n.....\n.....\n.....\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | For the first sample, one example of a rectangle we can form is as follows
For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.
In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: | 1,000 | [
{
"input": "2 3\nXXX\nXXX",
"output": "YES"
},
{
"input": "2 2\n.X\nXX",
"output": "NO"
},
{
"input": "1 500\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.",
"output": "YES"
},
{
"input": "10 1\n.\n.\n.\n.\nX\n.\n.\n.\n.\n.",
"output": "YES"
},
{
"input": "8 5\nXX.XX\nX.XXX\nX.XXX\nXXX.X\nXX.XX\nXX..X\nXXX.X\nXXXX.",
"output": "NO"
},
{
"input": "6 8\nXXXXXX..\nXXXXXXXX\n.X.X..X.\n.XXXX..X\nXX.XXXXX\nX...X..X",
"output": "NO"
},
{
"input": "10 2\n.X\n.X\nXX\nXX\nX.\nXX\nX.\nX.\n..\n..",
"output": "NO"
},
{
"input": "1 1\nX",
"output": "YES"
},
{
"input": "3 3\nXXX\nX.X\nX..",
"output": "NO"
},
{
"input": "3 3\nXX.\nXXX\n.XX",
"output": "NO"
},
{
"input": "4 4\nXXXX\nXXXX\nXX..\nXX..",
"output": "NO"
},
{
"input": "3 3\nX.X\nX.X\nXXX",
"output": "NO"
},
{
"input": "3 2\nX.\nXX\n.X",
"output": "NO"
},
{
"input": "2 1\nX\nX",
"output": "YES"
},
{
"input": "1 2\nXX",
"output": "YES"
},
{
"input": "2 3\n.XX\nXX.",
"output": "NO"
},
{
"input": "5 5\nXXX..\n.XXX.\n..XXX\nXXX..\n.XXX.",
"output": "NO"
},
{
"input": "2 4\nXX..\n.XX.",
"output": "NO"
},
{
"input": "4 4\nXXX.\nXXX.\nX.X.\n..X.",
"output": "NO"
},
{
"input": "2 3\nXX.\n.XX",
"output": "NO"
},
{
"input": "3 5\nXXXX.\n.XXXX\nXXXX.",
"output": "NO"
},
{
"input": "2 4\nXXX.\n.XXX",
"output": "NO"
},
{
"input": "3 3\n...\n.X.\nXXX",
"output": "NO"
},
{
"input": "3 3\n.X.\nXX.\nX..",
"output": "NO"
},
{
"input": "3 4\nXXX.\nX.X.\nXXX.",
"output": "NO"
},
{
"input": "4 4\n....\n....\n.XX.\n..X.",
"output": "NO"
},
{
"input": "4 4\n....\n....\n.XXX\n..X.",
"output": "NO"
},
{
"input": "2 6\nXXXXX.\nXXXXXX",
"output": "NO"
},
{
"input": "3 3\nX.X\nXXX\n.X.",
"output": "NO"
},
{
"input": "3 3\nXXX\nX.X\n..X",
"output": "NO"
},
{
"input": "3 3\n.XX\nXX.\n.XX",
"output": "NO"
},
{
"input": "3 8\n.XXXXXX.\nXXX..XXX\n.XXXXXX.",
"output": "NO"
},
{
"input": "3 3\nXX.\n.XX\nXX.",
"output": "NO"
},
{
"input": "3 3\n.XX\nXX.\nXX.",
"output": "NO"
},
{
"input": "4 4\n....\nXXX.\nX.XX\nXXX.",
"output": "NO"
},
{
"input": "2 2\nX.\nX.",
"output": "YES"
},
{
"input": "2 5\n...XX\n..XX.",
"output": "NO"
},
{
"input": "3 5\nXXX..\n.XXX.\n..XXX",
"output": "NO"
},
{
"input": "2 6\n...XXX\n.XXX..",
"output": "NO"
},
{
"input": "5 5\n.X.XX\n.XXX.\n.XXX.\n.XXX.\n.XXX.",
"output": "NO"
},
{
"input": "4 4\n....\n.XXX\n..X.\n.XX.",
"output": "NO"
},
{
"input": "2 4\n..XX\n.XX.",
"output": "NO"
},
{
"input": "3 6\nXXX...\n.XXX..\n..XXX.",
"output": "NO"
},
{
"input": "3 4\n.XXX\nXXX.\n.XXX",
"output": "NO"
}
] | 1,482,053,837 | 2,147,483,647 | Python 3 | OK | TESTS | 77 | 420 | 614,400 | n,m = map(int, input().split())
piece = [input().rstrip() for i in range(n)]
maxx, minx, maxy, miny = -1, n, -1, m
count = 0
for i in range(n):
for j in range(m):
if piece[i][j] == 'X':
maxx = max(maxx, i)
minx = min(minx, i)
maxy = max(maxy, j)
miny = min(miny, j)
count += 1
if (maxx - minx + 1) * (maxy - miny + 1) == count:
print("YES")
else:
print("NO")
| Title: Hongcow Solves A Puzzle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an *n* by *m* grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.
The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.
You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position.
Input Specification:
The first line of input will contain two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=500), the dimensions of the puzzle piece.
The next *n* lines will describe the jigsaw piece. Each line will have length *m* and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space.
It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region.
Output Specification:
Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise.
Demo Input:
['2 3\nXXX\nXXX\n', '2 2\n.X\nXX\n', '5 5\n.....\n..X..\n.....\n.....\n.....\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
For the first sample, one example of a rectangle we can form is as follows
For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.
In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: | ```python
n,m = map(int, input().split())
piece = [input().rstrip() for i in range(n)]
maxx, minx, maxy, miny = -1, n, -1, m
count = 0
for i in range(n):
for j in range(m):
if piece[i][j] == 'X':
maxx = max(maxx, i)
minx = min(minx, i)
maxy = max(maxy, j)
miny = min(miny, j)
count += 1
if (maxx - minx + 1) * (maxy - miny + 1) == count:
print("YES")
else:
print("NO")
``` | 3 |
|
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "10",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "53",
"output": "NO"
},
{
"input": "77",
"output": "NO"
},
{
"input": "32",
"output": "YES"
},
{
"input": "44",
"output": "YES"
},
{
"input": "98",
"output": "YES"
},
{
"input": "99",
"output": "NO"
},
{
"input": "90",
"output": "YES"
},
{
"input": "67",
"output": "NO"
},
{
"input": "100",
"output": "YES"
},
{
"input": "88",
"output": "YES"
}
] | 1,695,311,184 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | x = float(input("Enter a number"))
x = x %2
if x == 0 :
print("Yes")
else:
print("No") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
Input Specification:
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Output Specification:
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
Demo Input:
['8\n']
Demo Output:
['YES\n']
Note:
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | ```python
x = float(input("Enter a number"))
x = x %2
if x == 0 :
print("Yes")
else:
print("No")
``` | 0 |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
},
{
"input": "859 453892 543",
"output": "126416972"
},
{
"input": "1000 1000000000 1000",
"output": "0"
},
{
"input": "1000 500500000 1000",
"output": "0"
},
{
"input": "1000 500500001 1000",
"output": "0"
},
{
"input": "1000 500499999 1000",
"output": "1"
},
{
"input": "634 87973 214",
"output": "14497197"
},
{
"input": "432 10000 241",
"output": "12587552"
},
{
"input": "111 111111111 111",
"output": "0"
},
{
"input": "20 43 3",
"output": "77"
}
] | 1,694,986,876 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | p=0
a=list(map(int,input().split()))
k=a[0]
n=a[1]
w=a[2]
for i in range(1,w+1):
p+=i*k
print(p-n) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
Input Specification:
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output Specification:
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Demo Input:
['3 17 4\n']
Demo Output:
['13']
Note:
none | ```python
p=0
a=list(map(int,input().split()))
k=a[0]
n=a[1]
w=a[2]
for i in range(1,w+1):
p+=i*k
print(p-n)
``` | 0 |
|
809 | C | Find a car | PROGRAMMING | 2,600 | [
"combinatorics",
"divide and conquer",
"dp"
] | null | null | After a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Leha cannot find his car on a huge parking near the restaurant. So he decided to turn to the watchman for help.
Formally the parking can be represented as a matrix 109<=×<=109. There is exactly one car in every cell of the matrix. All cars have their own machine numbers represented as a positive integer. Let's index the columns of the matrix by integers from 1 to 109 from left to right and the rows by integers from 1 to 109 from top to bottom. By coincidence it turned out, that for every cell (*x*,<=*y*) the number of the car, which stands in this cell, is equal to the minimum positive integer, which can't be found in the cells (*i*,<=*y*) and (*x*,<=*j*), 1<=≤<=*i*<=<<=*x*,<=1<=≤<=*j*<=<<=*y*.
Leha wants to ask the watchman *q* requests, which can help him to find his car. Every request is represented as five integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=*k*. The watchman have to consider all cells (*x*,<=*y*) of the matrix, such that *x*1<=≤<=*x*<=≤<=*x*2 and *y*1<=≤<=*y*<=≤<=*y*2, and if the number of the car in cell (*x*,<=*y*) does not exceed *k*, increase the answer to the request by the number of the car in cell (*x*,<=*y*). For each request Leha asks the watchman to tell him the resulting sum. Due to the fact that the sum can turn out to be quite large, hacker asks to calculate it modulo 109<=+<=7.
However the requests seem to be impracticable for the watchman. Help the watchman to answer all Leha's requests. | The first line contains one integer *q* (1<=≤<=*q*<=≤<=104) — the number of Leha's requests.
The next *q* lines contain five integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=*k* (1<=≤<=*x*1<=≤<=*x*2<=≤<=109,<=1<=≤<=*y*1<=≤<=*y*2<=≤<=109,<=1<=≤<=*k*<=≤<=2·109) — parameters of Leha's requests. | Print exactly *q* lines — in the first line print the answer to the first request, in the second — the answer to the second request and so on. | [
"4\n1 1 1 1 1\n3 2 5 4 5\n1 1 5 5 10000\n1 4 2 5 2\n"
] | [
"1\n13\n93\n0\n"
] | Let's analyze all the requests. In each case the requested submatrix is highlighted in blue.
In the first request (*k* = 1) Leha asks only about the upper left parking cell. In this cell the car's number is 1. Consequentally the answer is 1.
<img class="tex-graphics" src="https://espresso.codeforces.com/76839e22308c8bf65bf6a862f4c9bc49b50ec2f4.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In the second request (*k* = 5) suitable numbers are 4, 1, 2, 3, 2, 1. Consequentally the answer is 4 + 1 + 2 + 3 + 2 + 1 = 13.
<img class="tex-graphics" src="https://espresso.codeforces.com/f86466a8ccbb4825331662353153b686b40ab62f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In the third request (*k* = 10000) Leha asks about the upper left frament 5 × 5 of the parking. Since *k* is big enough, the answer is equal to 93.
<img class="tex-graphics" src="https://espresso.codeforces.com/f3fae55460e5237c800c229f19113cd1f4181f3c.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In the last request (*k* = 2) none of the cur's numbers are suitable, so the answer is 0.
<img class="tex-graphics" src="https://espresso.codeforces.com/59bf21e74f30e2f3cdbdd55d300500e3e3f9b632.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,500 | [
{
"input": "4\n1 1 1 1 1\n3 2 5 4 5\n1 1 5 5 10000\n1 4 2 5 2",
"output": "1\n13\n93\n0"
},
{
"input": "10\n3 7 4 10 7\n6 1 7 10 18\n9 6 10 8 3\n1 8 3 10 3\n10 4 10 5 19\n8 9 9 10 10\n10 1 10 5 4\n8 1 9 4 18\n6 3 9 5 1\n6 6 9 6 16",
"output": "22\n130\n0\n0\n25\n3\n0\n68\n0\n22"
},
{
"input": "10\n1 1 2 2 8\n3 4 5 9 4\n2 10 5 10 6\n8 5 10 8 8\n1 2 8 2 20\n8 6 10 8 20\n6 7 6 7 9\n8 5 10 10 13\n1 8 10 9 13\n9 8 10 9 3",
"output": "6\n13\n0\n10\n36\n95\n4\n42\n94\n3"
},
{
"input": "10\n4 4 9 8 14\n5 5 10 10 7\n1 1 10 5 14\n3 5 8 9 15\n3 2 8 7 17\n5 1 10 6 7\n6 6 10 10 1\n3 3 7 10 15\n6 6 10 10 17\n6 5 10 9 5",
"output": "132\n46\n291\n157\n162\n92\n5\n244\n205\n33"
},
{
"input": "10\n6 2 10 9 7\n4 3 8 7 9\n2 1 7 9 5\n2 6 10 10 3\n1 4 7 8 18\n1 2 7 6 14\n2 6 6 10 14\n3 1 10 9 10\n4 6 10 10 14\n1 6 9 10 20",
"output": "74\n106\n90\n24\n165\n155\n193\n257\n158\n356"
},
{
"input": "10\n35670 87689 78020 97199 170735\n49603 42971 77473 79458 124936\n94018 22571 99563 79717 79594\n65172 72864 69350 77801 174349\n45117 31256 60374 67497 156317\n36047 95407 60232 98208 139099\n32487 46904 57699 99668 80778\n21651 59154 75570 62785 115538\n29698 87365 74417 93703 117692\n14164 51564 33862 97087 68406",
"output": "454444876\n271069018\n549471212\n320529941\n94517473\n311684494\n819172459\n675269446\n7036993\n762542106"
},
{
"input": "10\n51798 36533 70866 80025 119989\n28380 14954 62643 52624 29118\n54458 49611 75784 95421 49917\n69985 20586 84374 81162 14398\n65761 87545 72679 89308 70174\n22064 89628 77685 93857 38969\n75905 57174 86394 88214 107079\n48955 26587 98075 76935 72945\n69991 81288 96051 90174 75880\n66736 31080 84603 89293 196873",
"output": "12182239\n653954597\n844386299\n206168423\n437228219\n154397952\n317840300\n905267860\n968243748\n750471863"
},
{
"input": "10\n45965 63556 68448 95894 98898\n50414 55822 93611 81912 81281\n51874 82624 99557 93570 17105\n83870 83481 98209 86976 37205\n34423 98865 81812 99559 52923\n59982 80565 63020 90493 156405\n73425 8598 94843 23120 95359\n75710 49176 96524 75354 10095\n11342 31715 50626 83343 14952\n50673 61478 61380 81973 35755",
"output": "199194379\n133563355\n535853348\n105738618\n790969580\n176118196\n203632117\n366899916\n146517938\n749331834"
},
{
"input": "10\n39453 1588 68666 44518 80856\n65967 37333 79860 79474 185463\n72918 67988 88918 85752 178916\n4960 53963 30061 77750 101446\n68699 86791 98399 87875 166780\n42051 5526 86018 54457 56275\n35111 22360 46210 77033 154364\n79350 54886 79640 66722 206\n57162 67626 99566 96156 173141\n42028 40518 52695 94347 188413",
"output": "974201015\n675658286\n140222566\n668884231\n613269116\n620825458\n239625852\n0\n193348271\n860068784"
},
{
"input": "10\n60149 83439 91672 93997 29005\n2170 81207 33662 85253 169296\n84242 35792 96226 46307 32764\n48745 41099 63904 50301 99488\n20797 58596 98423 69870 151507\n79648 84250 95429 93302 160725\n29270 74595 41752 87094 46279\n97721 20075 99994 24743 121486\n44598 9233 59399 56549 114860\n81435 24939 83492 87248 55048",
"output": "922941587\n694484017\n0\n117048300\n483223856\n262420342\n0\n449352476\n757860438\n37418807"
},
{
"input": "10\n17273 60120 44211 66117 121362\n38045 49581 43392 60379 106182\n29993 28891 49459 68331 170383\n13745 94716 99131 96384 163728\n35994 29973 69541 91771 65364\n93514 84168 95810 91743 60595\n57881 7334 95096 48342 39876\n41495 70230 56091 84188 78893\n12540 23228 26212 81656 105752\n83061 65904 87563 68222 150811",
"output": "908485580\n424476218\n6537747\n993909605\n825278510\n232753578\n980640613\n0\n732434354\n794713552"
},
{
"input": "10\n89912 38588 100000 61519 131263\n63723 14623 74226 61508 104495\n80783 19628 93957 60942 72631\n49607 2064 60475 32125 43001\n397 31798 60225 47064 161900\n87074 8737 99607 47892 162291\n10290 73252 84596 86607 106118\n38621 44306 76871 87471 44012\n26666 84711 53248 98378 27672\n22685 36055 57791 80992 140124",
"output": "191639278\n266398397\n387687950\n268970017\n733430769\n239026110\n569640661\n502549869\n0\n901026605"
},
{
"input": "10\n25583 8810 71473 84303 56325\n52527 14549 67038 87309 41381\n85964 55620 99929 76963 34442\n28280 87558 56450 98865 107242\n61281 44852 99966 67445 108461\n58298 39201 70236 74834 62161\n54864 73811 68399 96057 132419\n11978 85542 35272 97885 1419\n89151 60500 99966 89149 185860\n48390 40961 87183 97309 35887",
"output": "605688865\n873699306\n156635112\n698424830\n86490140\n906905842\n454122876\n0\n347292150\n987085065"
},
{
"input": "10\n1 1 100000 100000 124458\n1 1 100000 100000 89626\n1 1 100000 100000 42210\n1 1 100000 100000 65721\n1 1 100000 100000 148198\n1 1 100000 100000 122029\n1 1 100000 100000 50224\n1 1 100000 100000 16314\n1 1 100000 100000 158599\n1 1 100000 100000 142792",
"output": "986777122\n640050028\n864029027\n339397763\n973589169\n723174232\n902088077\n287074869\n973589169\n973589169"
},
{
"input": "10\n1 1 100000 100000 73712\n1 1 100000 100000 193808\n1 1 100000 100000 69429\n1 1 100000 100000 162666\n1 1 100000 100000 94759\n1 1 100000 100000 21899\n1 1 100000 100000 76524\n1 1 100000 100000 182233\n1 1 100000 100000 125300\n1 1 100000 100000 71258",
"output": "717056579\n973589169\n625066178\n973589169\n207662527\n561940319\n600480675\n973589169\n665222578\n844687430"
},
{
"input": "10\n63468235 40219768 326916221 835104676 1952530008\n297013188 212688608 432392437 887776079 1462376999\n153855395 41506149 261808021 778766232 291194343\n238640217 22153210 642972954 719331789 371665652\n528859722 494055455 831993741 924681396 251221747\n19429387 475067059 567446881 908192965 1886584907\n472431037 68414189 620339945 605371645 1906964799\n741781008 683180935 932571485 883233060 987079989\n557448838 174849798 875225676 549316493 360200169\n61358988 97847347 487462496 955727516 1024792731",
"output": "383784865\n892686589\n440520525\n909297528\n857306896\n138121854\n327512104\n256512043\n89816936\n158271270"
},
{
"input": "10\n1 1 1000000000 1000000000 497721466\n1 1 1000000000 1000000000 1096400602\n1 1 1000000000 1000000000 1120358961\n1 1 1000000000 1000000000 232914786\n1 1 1000000000 1000000000 601018859\n1 1 1000000000 1000000000 310363393\n1 1 1000000000 1000000000 636663039\n1 1 1000000000 1000000000 1548359129\n1 1 1000000000 1000000000 1183677871\n1 1 1000000000 1000000000 792703683",
"output": "11780124\n248752269\n248752269\n883198940\n218155629\n747605194\n352461300\n248752269\n248752269\n562283839"
},
{
"input": "10\n1 1 1000000000 1000000000 1477070720\n1 1 1000000000 1000000000 1378704784\n1 1 1000000000 1000000000 782520772\n1 1 1000000000 1000000000 1377211731\n1 1 1000000000 1000000000 623332716\n1 1 1000000000 1000000000 497630560\n1 1 1000000000 1000000000 47465148\n1 1 1000000000 1000000000 790892344\n1 1 1000000000 1000000000 1071836060\n1 1 1000000000 1000000000 1949232149",
"output": "248752269\n248752269\n949069688\n248752269\n840885502\n42891263\n23378226\n985784682\n561979540\n248752269"
}
] | 1,497,606,973 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = input()
for i in range(int(n)-1):
a = input()
s = list(map(int, a.split(' '))
t = 0
for i in range(s[0],s[2]+1):
for j in range(s[1],s[3]+1):
if (i-1^j-1) +1 <= s[4]:
t += (i-1^j-1) +1
if t > 10**9 +7:
print(t % 10**9 +7)
else: print(t)
| Title: Find a car
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Leha cannot find his car on a huge parking near the restaurant. So he decided to turn to the watchman for help.
Formally the parking can be represented as a matrix 109<=×<=109. There is exactly one car in every cell of the matrix. All cars have their own machine numbers represented as a positive integer. Let's index the columns of the matrix by integers from 1 to 109 from left to right and the rows by integers from 1 to 109 from top to bottom. By coincidence it turned out, that for every cell (*x*,<=*y*) the number of the car, which stands in this cell, is equal to the minimum positive integer, which can't be found in the cells (*i*,<=*y*) and (*x*,<=*j*), 1<=≤<=*i*<=<<=*x*,<=1<=≤<=*j*<=<<=*y*.
Leha wants to ask the watchman *q* requests, which can help him to find his car. Every request is represented as five integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=*k*. The watchman have to consider all cells (*x*,<=*y*) of the matrix, such that *x*1<=≤<=*x*<=≤<=*x*2 and *y*1<=≤<=*y*<=≤<=*y*2, and if the number of the car in cell (*x*,<=*y*) does not exceed *k*, increase the answer to the request by the number of the car in cell (*x*,<=*y*). For each request Leha asks the watchman to tell him the resulting sum. Due to the fact that the sum can turn out to be quite large, hacker asks to calculate it modulo 109<=+<=7.
However the requests seem to be impracticable for the watchman. Help the watchman to answer all Leha's requests.
Input Specification:
The first line contains one integer *q* (1<=≤<=*q*<=≤<=104) — the number of Leha's requests.
The next *q* lines contain five integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=*k* (1<=≤<=*x*1<=≤<=*x*2<=≤<=109,<=1<=≤<=*y*1<=≤<=*y*2<=≤<=109,<=1<=≤<=*k*<=≤<=2·109) — parameters of Leha's requests.
Output Specification:
Print exactly *q* lines — in the first line print the answer to the first request, in the second — the answer to the second request and so on.
Demo Input:
['4\n1 1 1 1 1\n3 2 5 4 5\n1 1 5 5 10000\n1 4 2 5 2\n']
Demo Output:
['1\n13\n93\n0\n']
Note:
Let's analyze all the requests. In each case the requested submatrix is highlighted in blue.
In the first request (*k* = 1) Leha asks only about the upper left parking cell. In this cell the car's number is 1. Consequentally the answer is 1.
<img class="tex-graphics" src="https://espresso.codeforces.com/76839e22308c8bf65bf6a862f4c9bc49b50ec2f4.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In the second request (*k* = 5) suitable numbers are 4, 1, 2, 3, 2, 1. Consequentally the answer is 4 + 1 + 2 + 3 + 2 + 1 = 13.
<img class="tex-graphics" src="https://espresso.codeforces.com/f86466a8ccbb4825331662353153b686b40ab62f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In the third request (*k* = 10000) Leha asks about the upper left frament 5 × 5 of the parking. Since *k* is big enough, the answer is equal to 93.
<img class="tex-graphics" src="https://espresso.codeforces.com/f3fae55460e5237c800c229f19113cd1f4181f3c.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In the last request (*k* = 2) none of the cur's numbers are suitable, so the answer is 0.
<img class="tex-graphics" src="https://espresso.codeforces.com/59bf21e74f30e2f3cdbdd55d300500e3e3f9b632.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
n = input()
for i in range(int(n)-1):
a = input()
s = list(map(int, a.split(' '))
t = 0
for i in range(s[0],s[2]+1):
for j in range(s[1],s[3]+1):
if (i-1^j-1) +1 <= s[4]:
t += (i-1^j-1) +1
if t > 10**9 +7:
print(t % 10**9 +7)
else: print(t)
``` | -1 |
|
735 | A | Ostap and Grasshopper | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly *k* cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if *k*<==<=1 the grasshopper can jump to a neighboring cell only, and if *k*<==<=2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect. | The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once. | If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes). | [
"5 2\n#G#T#\n",
"6 1\nT....G\n",
"7 3\nT..#..G\n",
"6 2\n..GT..\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect. | 500 | [
{
"input": "5 2\n#G#T#",
"output": "YES"
},
{
"input": "6 1\nT....G",
"output": "YES"
},
{
"input": "7 3\nT..#..G",
"output": "NO"
},
{
"input": "6 2\n..GT..",
"output": "NO"
},
{
"input": "2 1\nGT",
"output": "YES"
},
{
"input": "100 5\nG####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####T####",
"output": "YES"
},
{
"input": "100 5\nG####.####.####.####.####.####.####.####.####.####.####.####.####.#########.####.####.####.####T####",
"output": "NO"
},
{
"input": "2 1\nTG",
"output": "YES"
},
{
"input": "99 1\n...T.............................................................................................G.",
"output": "YES"
},
{
"input": "100 2\nG............#.....#...........#....#...........##............#............#......................T.",
"output": "NO"
},
{
"input": "100 1\n#.#.#.##..#..##.#....##.##.##.#....####..##.#.##..GT..##...###.#.##.#..#..##.###..#.####..#.#.##..##",
"output": "YES"
},
{
"input": "100 2\n..#####.#.#.......#.#.#...##..####..###..#.#######GT####.#.#...##...##.#..###....##.#.#..#.###....#.",
"output": "NO"
},
{
"input": "100 3\nG..................................................................................................T",
"output": "YES"
},
{
"input": "100 3\nG..................................................................................................T",
"output": "YES"
},
{
"input": "100 3\nG..................................#......#......#.......#.#..........#........#......#..........#.T",
"output": "NO"
},
{
"input": "100 3\nG..............#..........#...#..............#.#.....................#......#........#.........#...T",
"output": "NO"
},
{
"input": "100 3\nG##################################################################################################T",
"output": "NO"
},
{
"input": "100 33\nG..................................................................................................T",
"output": "YES"
},
{
"input": "100 33\nG..................................................................................................T",
"output": "YES"
},
{
"input": "100 33\nG.........#........#..........#..............#.................#............................#.#....T",
"output": "YES"
},
{
"input": "100 33\nG.......#..................#..............................#............................#..........T.",
"output": "NO"
},
{
"input": "100 33\nG#..........##...#.#.....................#.#.#.........##..#...........#....#...........##...#..###T",
"output": "YES"
},
{
"input": "100 33\nG..#.#..#..####......#......##...##...#.##........#...#...#.##....###..#...###..##.#.....#......#.T.",
"output": "NO"
},
{
"input": "100 33\nG#....#..#..##.##..#.##.#......#.#.##..##.#.#.##.##....#.#.....####..##...#....##..##..........#...T",
"output": "NO"
},
{
"input": "100 33\nG#######.#..##.##.#...#..#.###.#.##.##.#..#.###..####.##.#.##....####...##..####.#..##.##.##.#....#T",
"output": "NO"
},
{
"input": "100 33\nG#####.#.##.###########.##..##..#######..########..###.###..#.####.######.############..####..#####T",
"output": "NO"
},
{
"input": "100 99\nT..................................................................................................G",
"output": "YES"
},
{
"input": "100 99\nT..................................................................................................G",
"output": "YES"
},
{
"input": "100 99\nT.#...............................#............#..............................##...................G",
"output": "YES"
},
{
"input": "100 99\nT..#....#.##...##########.#.#.#.#...####..#.....#..##..#######.######..#.....###..###...#.......#.#G",
"output": "YES"
},
{
"input": "100 99\nG##################################################################################################T",
"output": "YES"
},
{
"input": "100 9\nT..................................................................................................G",
"output": "YES"
},
{
"input": "100 9\nT.................................................................................................G.",
"output": "NO"
},
{
"input": "100 9\nT................................................................................................G..",
"output": "NO"
},
{
"input": "100 1\nG..................................................................................................T",
"output": "YES"
},
{
"input": "100 1\nT..................................................................................................G",
"output": "YES"
},
{
"input": "100 1\n##########G.........T###############################################################################",
"output": "YES"
},
{
"input": "100 1\n#################################################################################################G.T",
"output": "YES"
},
{
"input": "100 17\n##########G################.################.################.################T#####################",
"output": "YES"
},
{
"input": "100 17\n####.#..#.G######.#########.##..##########.#.################.################T######.####.#########",
"output": "YES"
},
{
"input": "100 17\n.########.G##.####.#.######.###############..#.###########.##.#####.##.#####.#T.###..###.########.##",
"output": "YES"
},
{
"input": "100 1\nG.............................................#....................................................T",
"output": "NO"
},
{
"input": "100 1\nT.#................................................................................................G",
"output": "NO"
},
{
"input": "100 1\n##########G....#....T###############################################################################",
"output": "NO"
},
{
"input": "100 1\n#################################################################################################G#T",
"output": "NO"
},
{
"input": "100 17\nG################.#################################.################T###############################",
"output": "NO"
},
{
"input": "100 17\nG################.###############..###.######.#######.###.#######.##T######################.###.####",
"output": "NO"
},
{
"input": "100 17\nG####.##.##.#####.####....##.####.#########.##.#..#.###############.T############.#########.#.####.#",
"output": "NO"
},
{
"input": "48 1\nT..............................................G",
"output": "YES"
},
{
"input": "23 1\nT.....................G",
"output": "YES"
},
{
"input": "49 1\nG...............................................T",
"output": "YES"
},
{
"input": "3 1\nTG#",
"output": "YES"
},
{
"input": "6 2\n..TG..",
"output": "NO"
},
{
"input": "14 3\n...G.....#..T.",
"output": "NO"
},
{
"input": "5 4\n##GT#",
"output": "NO"
},
{
"input": "6 2\nT#..G.",
"output": "YES"
},
{
"input": "5 2\nT.G.#",
"output": "YES"
},
{
"input": "6 1\nT...G#",
"output": "YES"
},
{
"input": "5 1\nTG###",
"output": "YES"
},
{
"input": "5 4\n.G..T",
"output": "NO"
},
{
"input": "7 2\nT#...#G",
"output": "YES"
},
{
"input": "7 1\n##TG###",
"output": "YES"
},
{
"input": "7 1\n###GT##",
"output": "YES"
},
{
"input": "5 2\nG..T.",
"output": "NO"
},
{
"input": "5 1\nG.T##",
"output": "YES"
},
{
"input": "6 2\nG.T###",
"output": "YES"
},
{
"input": "6 2\nG#T###",
"output": "YES"
},
{
"input": "10 2\n####T..G..",
"output": "NO"
},
{
"input": "3 1\nGT#",
"output": "YES"
},
{
"input": "4 1\nTG##",
"output": "YES"
},
{
"input": "6 1\n.G..T.",
"output": "YES"
},
{
"input": "10 3\n......G..T",
"output": "YES"
},
{
"input": "3 2\nG.T",
"output": "YES"
},
{
"input": "4 1\n#G.T",
"output": "YES"
},
{
"input": "5 2\nT#G##",
"output": "YES"
},
{
"input": "4 2\nG#.T",
"output": "NO"
},
{
"input": "4 1\nGT##",
"output": "YES"
}
] | 1,694,688,593 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 12 | 78 | 0 | n, k = map(int, input().split())
cells = input()
hopper = cells.find('G')
insect = cells.find('T')
if insect < hopper:
cells = cells[::-1]
if k == 1:
print('NO' if '#' in cells else 'YES')
else:
for i in range(hopper, n, k):
if i == insect:
print('YES')
exit()
elif cells[i] == '#':
break
print('NO')
| Title: Ostap and Grasshopper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly *k* cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if *k*<==<=1 the grasshopper can jump to a neighboring cell only, and if *k*<==<=2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input Specification:
The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output Specification:
If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Demo Input:
['5 2\n#G#T#\n', '6 1\nT....G\n', '7 3\nT..#..G\n', '6 2\n..GT..\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n', 'NO\n']
Note:
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect. | ```python
n, k = map(int, input().split())
cells = input()
hopper = cells.find('G')
insect = cells.find('T')
if insect < hopper:
cells = cells[::-1]
if k == 1:
print('NO' if '#' in cells else 'YES')
else:
for i in range(hopper, n, k):
if i == insect:
print('YES')
exit()
elif cells[i] == '#':
break
print('NO')
``` | 0 |
|
765 | B | Code obfuscation | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"strings"
] | null | null | Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.
To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol *a*, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with *b*, and so on. Kostya is well-mannered, so he doesn't use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs.
You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya's obfuscation. | In the only line of input there is a string *S* of lowercase English letters (1<=≤<=|*S*|<=≤<=500) — the identifiers of a program with removed whitespace characters. | If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO". | [
"abacaba\n",
"jinotega\n"
] | [
"YES\n",
"NO\n"
] | In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program:
- replace all occurences of number with a, the result would be "a string a character a string a",- replace all occurences of string with b, the result would be "a b a character a b a",- replace all occurences of character with c, the result would be "a b a c a b a",- all identifiers have been replaced, thus the obfuscation is finished. | 1,000 | [
{
"input": "abacaba",
"output": "YES"
},
{
"input": "jinotega",
"output": "NO"
},
{
"input": "aaaaaaaaaaa",
"output": "YES"
},
{
"input": "aba",
"output": "YES"
},
{
"input": "bab",
"output": "NO"
},
{
"input": "a",
"output": "YES"
},
{
"input": "abcdefghijklmnopqrstuvwxyz",
"output": "YES"
},
{
"input": "fihyxmbnzq",
"output": "NO"
},
{
"input": "aamlaswqzotaanasdhcvjoaiwdhctezzawagkdgfffeqkyrvbcrfqgkdsvximsnvmkmjyofswmtjdoxgwamsaatngenqvsvrvwlbzuoeaolfcnmdacrmdleafbsmerwmxzyylfhemnkoayuhtpbikm",
"output": "NO"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "YES"
},
{
"input": "darbbbcwynbbbbaacbkvbakavabbbabzajlbajryaabbbccxraakgniagbtsswcfbkubdmcasccepybkaefcfsbzdddxgcjadybcfjtmqbspflqrdghgfwnccfveogdmifkociqscahdejctacwzbkhihajfilrgcjiofwfklifobozikcmvcfeqlidrgsgdfxffaaebzjxngsjxiclyolhjokqpdbfffooticxsezpgqkhhzmbmqgskkqvefzyijrwhpftcmbedmaflapmeljaudllojfpgfkpvgylaglrhrslxlprbhgknrctilngqccbddvpamhifsbmyowohczizjcbleehfrecjbqtxertnpfmalejmbxkhkkbyopuwlhkxuqellsybgcndvniyyxfoufalstdsdfjoxlnmigkqwmgojsppaannfstxytelluvvkdcezlqfsperwyjsdsmkvgjdbksswamhmoukcawiigkggztr",
"output": "NO"
},
{
"input": "bbbbbb",
"output": "NO"
},
{
"input": "aabbbd",
"output": "NO"
},
{
"input": "abdefghijklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "abcdeghijklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "abcdefghijklmnopqrsuvwxyz",
"output": "NO"
},
{
"input": "abcdefghijklmnopqrstuvwxy",
"output": "YES"
},
{
"input": "abcdefghijklmnopqrsutvwxyz",
"output": "NO"
},
{
"input": "acdef",
"output": "NO"
},
{
"input": "z",
"output": "NO"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaababaaababaabababccbabdbcbadccacdbdedabbeecbcabbdcaecdabbedddafeffaccgeacefbcahabfiiegecdbebabhhbdgfeghhbfahgagefbgghdbhadeicbdfgdchhefhigfcgdhcihecacfhadfgfejccibcjkfhbigbealjjkfldiecfdcafbamgfkbjlbifldghmiifkkglaflmjfmkfdjlbliijkgfdelklfnadbifgbmklfbqkhirhcadoadhmjrghlmelmjfpakqkdfcgqdkaeqpbcdoeqglqrarkipncckpfmajrqsfffldegbmahsfcqdfdqtrgrouqajgsojmmukptgerpanpcbejmergqtavwsvtveufdseuemwrhfmjqinxjodddnpcgqullrhmogflsxgsbapoghortiwcovejtinncozk",
"output": "NO"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "YES"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbabbbabbaaabbaaaaabaabbaa",
"output": "YES"
},
{
"input": "aababbabbaabbbbbaabababaabbbaaaaabbabbabbaabbbbabaabbaaababbaaacbbabbbbbbcbcababbccaaacbaccaccaababbccaacccaabaaccaaabacacbaabacbaacbaaabcbbbcbbaacaabcbcbccbacabbcbabcaccaaaaaabcbacabcbabbbbbabccbbcacbaaabbccbbaaaaaaaaaaaadbbbabdacabdaddddbaabbddbdabbdacbacbacaaaabbacadbcddddadaddabbdccaddbaaacbceebbceadbeaadecddbbbcaaecbdeaebaddbbdebbcbaabcacbdcdc",
"output": "YES"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbaabaabaababbbabbacacbbbacbbaaaabbccacbaabaaccbbbbbcbbbacabbccaaabbaaacabcbacbcabbbbecbecadcbacbaadeeadabeacdebccdbbcaecdbeeebbebcaaaeacdcbdeccdbbdcdebdcbdacebcecbacddeeaebcedffedfggbeedceacaecagdfedfabcfchffceachgcbicbcffeeebgcgiefcafhibhceiedgbfebbccegbehhibhhfedbaeedbghggffehggaeaidifhdhaggdjcfjhiaieaichjacedchejg",
"output": "NO"
},
{
"input": "b",
"output": "NO"
},
{
"input": "ac",
"output": "NO"
},
{
"input": "cde",
"output": "NO"
},
{
"input": "abd",
"output": "NO"
},
{
"input": "zx",
"output": "NO"
},
{
"input": "bcd",
"output": "NO"
},
{
"input": "aaac",
"output": "NO"
},
{
"input": "aacb",
"output": "NO"
},
{
"input": "acd",
"output": "NO"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz",
"output": "NO"
},
{
"input": "abcdefghijklmnopqrstuvwxyzz",
"output": "YES"
},
{
"input": "bc",
"output": "NO"
},
{
"input": "aaaaaaaaad",
"output": "NO"
},
{
"input": "abb",
"output": "YES"
},
{
"input": "abcb",
"output": "YES"
},
{
"input": "aac",
"output": "NO"
},
{
"input": "abcbcb",
"output": "YES"
},
{
"input": "bb",
"output": "NO"
},
{
"input": "abbb",
"output": "YES"
},
{
"input": "bbb",
"output": "NO"
},
{
"input": "x",
"output": "NO"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazz",
"output": "NO"
},
{
"input": "acbccccccccccc",
"output": "NO"
},
{
"input": "za",
"output": "NO"
},
{
"input": "ade",
"output": "NO"
},
{
"input": "bbbbbbbbbb",
"output": "NO"
},
{
"input": "bac",
"output": "NO"
},
{
"input": "bcddcb",
"output": "NO"
},
{
"input": "aaacb",
"output": "NO"
},
{
"input": "aaaaac",
"output": "NO"
},
{
"input": "aaaaaaaaaaad",
"output": "NO"
},
{
"input": "c",
"output": "NO"
},
{
"input": "abcccccccc",
"output": "YES"
},
{
"input": "aaaaaaac",
"output": "NO"
}
] | 1,691,978,136 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | string = input("inserte variables:")
variables = ""
for i in string:
if i not in variables:
variables += i
orden = sorted(variables)
if orden == variables:
print("YES")
else:
print("NO")
| Title: Code obfuscation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.
To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol *a*, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with *b*, and so on. Kostya is well-mannered, so he doesn't use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs.
You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya's obfuscation.
Input Specification:
In the only line of input there is a string *S* of lowercase English letters (1<=≤<=|*S*|<=≤<=500) — the identifiers of a program with removed whitespace characters.
Output Specification:
If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO".
Demo Input:
['abacaba\n', 'jinotega\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program:
- replace all occurences of number with a, the result would be "a string a character a string a",- replace all occurences of string with b, the result would be "a b a character a b a",- replace all occurences of character with c, the result would be "a b a c a b a",- all identifiers have been replaced, thus the obfuscation is finished. | ```python
string = input("inserte variables:")
variables = ""
for i in string:
if i not in variables:
variables += i
orden = sorted(variables)
if orden == variables:
print("YES")
else:
print("NO")
``` | 0 |
|
373 | B | Making Sequences is Fun | PROGRAMMING | 1,600 | [
"binary search",
"implementation",
"math"
] | null | null | We'll define *S*(*n*) for positive integer *n* as follows: the number of the *n*'s digits in the decimal base. For example, *S*(893)<==<=3, *S*(114514)<==<=6.
You want to make a consecutive integer sequence starting from number *m* (*m*,<=*m*<=+<=1,<=...). But you need to pay *S*(*n*)·*k* to add the number *n* to the sequence.
You can spend a cost up to *w*, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length. | The first line contains three integers *w* (1<=≤<=*w*<=≤<=1016), *m* (1<=≤<=*m*<=≤<=1016), *k* (1<=≤<=*k*<=≤<=109).
Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | The first line should contain a single integer — the answer to the problem. | [
"9 1 1\n",
"77 7 7\n",
"114 5 14\n",
"1 1 2\n"
] | [
"9\n",
"7\n",
"6\n",
"0\n"
] | none | 1,000 | [
{
"input": "9 1 1",
"output": "9"
},
{
"input": "77 7 7",
"output": "7"
},
{
"input": "114 5 14",
"output": "6"
},
{
"input": "1 1 2",
"output": "0"
},
{
"input": "462 183 8",
"output": "19"
},
{
"input": "462 183 8",
"output": "19"
},
{
"input": "462 183 8",
"output": "19"
},
{
"input": "462 183 8",
"output": "19"
},
{
"input": "462 183 8",
"output": "19"
},
{
"input": "462 183 8",
"output": "19"
},
{
"input": "462 183 8",
"output": "19"
},
{
"input": "10000000000000000 1 1",
"output": "674074074074073"
},
{
"input": "2155990066796462 2710473050636183 563261158",
"output": "239230"
},
{
"input": "552719169048748 7822730034794389 374302919",
"output": "92291"
},
{
"input": "6895788044242644 3474119895793364 732614708",
"output": "588285"
},
{
"input": "9230573804495452 8577408935470783 90893866",
"output": "6347082"
},
{
"input": "5363062262667637 2932858345469643 449197576",
"output": "746200"
},
{
"input": "1951414609070432 8979282171178729 260239468",
"output": "468658"
},
{
"input": "6289344232651169 4170875805886064 618522710",
"output": "635520"
},
{
"input": "111984789523940 8017182602114316 976839488",
"output": "7164"
},
{
"input": "3663662721733869 4845943245608254 787880219",
"output": "290626"
},
{
"input": "10000000000000000 10000000000000000 1",
"output": "588235294117647"
},
{
"input": "10000000000000000 9999999999999999 1",
"output": "588235294117647"
},
{
"input": "9999999999999999 1 1",
"output": "674074074074073"
},
{
"input": "3 1 4",
"output": "0"
},
{
"input": "9999999999999998 1 1",
"output": "674074074074072"
},
{
"input": "1 1000000000000000 1",
"output": "0"
},
{
"input": "1 1000000000000000 1000000000",
"output": "0"
},
{
"input": "10000000000000000 10000000000000000 1000000000",
"output": "588235"
},
{
"input": "10000000000000000 10000000000000000 1",
"output": "588235294117647"
},
{
"input": "121212121 3434343434 56",
"output": "216450"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "98 55 1",
"output": "47"
},
{
"input": "1 10000000000000000 123456",
"output": "0"
},
{
"input": "10000000000000000 1000000000000001 1000000000",
"output": "625000"
}
] | 1,572,056,848 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 307,200 | import math
s=input()
a=s.split()
count1=0
sum=0
a[0]=int(a[0])
a[1]=int(a[1])
a[2]=int(a[2])
z=str(a[1])
count1=len(z)
print(count1)
z=pow(10,count1)
z=z-a[1]
if z*count1*a[2]>=a[0]:
print(int(a[0]/(a[2]*count1)))
exit()
else:
a[0]=a[0]-z*count1*a[2]
sum=sum+z
while 1:
l=pow(10,count1)
count1=count1+1
z=pow(10,count1)
if a[0]-(z-l)*count1*a[2]>0:
a[0]=a[0]-(z-l)*count1*a[2]
sum=sum+z-l
else:
sum=sum+a[0]/(a[2]*count1)
break
sum=int(sum)
print(sum) | Title: Making Sequences is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We'll define *S*(*n*) for positive integer *n* as follows: the number of the *n*'s digits in the decimal base. For example, *S*(893)<==<=3, *S*(114514)<==<=6.
You want to make a consecutive integer sequence starting from number *m* (*m*,<=*m*<=+<=1,<=...). But you need to pay *S*(*n*)·*k* to add the number *n* to the sequence.
You can spend a cost up to *w*, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length.
Input Specification:
The first line contains three integers *w* (1<=≤<=*w*<=≤<=1016), *m* (1<=≤<=*m*<=≤<=1016), *k* (1<=≤<=*k*<=≤<=109).
Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output Specification:
The first line should contain a single integer — the answer to the problem.
Demo Input:
['9 1 1\n', '77 7 7\n', '114 5 14\n', '1 1 2\n']
Demo Output:
['9\n', '7\n', '6\n', '0\n']
Note:
none | ```python
import math
s=input()
a=s.split()
count1=0
sum=0
a[0]=int(a[0])
a[1]=int(a[1])
a[2]=int(a[2])
z=str(a[1])
count1=len(z)
print(count1)
z=pow(10,count1)
z=z-a[1]
if z*count1*a[2]>=a[0]:
print(int(a[0]/(a[2]*count1)))
exit()
else:
a[0]=a[0]-z*count1*a[2]
sum=sum+z
while 1:
l=pow(10,count1)
count1=count1+1
z=pow(10,count1)
if a[0]-(z-l)*count1*a[2]>0:
a[0]=a[0]-(z-l)*count1*a[2]
sum=sum+z-l
else:
sum=sum+a[0]/(a[2]*count1)
break
sum=int(sum)
print(sum)
``` | 0 |
|
841 | A | Generous Kefa | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons. | Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary. | [
"4 2\naabb\n",
"6 3\naacaab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | 500 | [
{
"input": "4 2\naabb",
"output": "YES"
},
{
"input": "6 3\naacaab",
"output": "NO"
},
{
"input": "2 2\nlu",
"output": "YES"
},
{
"input": "5 3\novvoo",
"output": "YES"
},
{
"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf",
"output": "YES"
},
{
"input": "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv",
"output": "NO"
},
{
"input": "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "YES"
},
{
"input": "100 1\nnubcvvjvbjgnjsdkajimdcxvewbcytvfkihunycdrlconddlwgzjasjlsrttlrzsumzpyumpveglfqzmaofbshbojmwuwoxxvrod",
"output": "NO"
},
{
"input": "100 13\nvyldolgryldqrvoldvzvrdrgorlorszddtgqvrlisxxrxdxlqtvtgsrqlzixoyrozxzogqxlsgzdddzqrgitxxritoolzolgrtvl",
"output": "YES"
},
{
"input": "18 6\njzwtnkvmscqhmdlsxy",
"output": "YES"
},
{
"input": "21 2\nfscegcqgzesefghhwcexs",
"output": "NO"
},
{
"input": "32 22\ncduamsptaklqtxlyoutlzepxgyfkvngc",
"output": "YES"
},
{
"input": "49 27\noxyorfnkzwsfllnyvdhdanppuzrnbxehugvmlkgeymqjlmfxd",
"output": "YES"
},
{
"input": "50 24\nxxutzjwbggcwvxztttkmzovtmuwttzcbwoztttohzzxghuuthv",
"output": "YES"
},
{
"input": "57 35\nglxshztrqqfyxthqamagvtmrdparhelnzrqvcwqxjytkbuitovkdxueul",
"output": "YES"
},
{
"input": "75 23\nittttiiuitutuiiuuututiuttiuiuutuuuiuiuuuuttuuttuutuiiuiuiiuiitttuututuiuuii",
"output": "NO"
},
{
"input": "81 66\nfeqevfqfebhvubhuuvfuqheuqhbeeuebehuvhffvbqvqvfbqqvvhevqffbqqhvvqhfeehuhqeqhueuqqq",
"output": "YES"
},
{
"input": "93 42\npqeiafraiavfcteumflpcbpozcomlvpovlzdbldvoopnhdoeqaopzthiuzbzmeieiatthdeqovaqfipqlddllmfcrrnhb",
"output": "YES"
},
{
"input": "100 53\nizszyqyndzwzyzgsdagdwdazadiawizinagqqgczaqqnawgijziziawzszdjdcqjdjqiwgadydcnqisaayjiqqsscwwzjzaycwwc",
"output": "YES"
},
{
"input": "100 14\nvkrdcqbvkwuckpmnbydmczdxoagdsgtqxvhaxntdcxhjcrjyvukhugoglbmyoaqexgtcfdgemmizoniwtmisqqwcwfusmygollab",
"output": "YES"
},
{
"input": "100 42\naaaaaiiiiaiiiaaiaiiaaiiiiiaaaaaiaiiiaiiiiaiiiaaaaaiiiaaaiiaaiiiaiiiaiaaaiaiiiiaaiiiaiiaiaiiaiiiaaaia",
"output": "NO"
},
{
"input": "100 89\ntjbkmydejporbqhcbztkcumxjjgsrvxpuulbhzeeckkbchpbxwhedrlhjsabcexcohgdzouvsgphjdthpuqrlkgzxvqbuhqxdsmf",
"output": "YES"
},
{
"input": "100 100\njhpyiuuzizhubhhpxbbhpyxzhbpjphzppuhiahihiappbhuypyauhizpbibzixjbzxzpbphuiaypyujappuxiyuyaajaxjupbahb",
"output": "YES"
},
{
"input": "100 3\nsszoovvzysavsvzsozzvoozvysozsaszayaszasaysszzzysosyayyvzozovavzoyavsooaoyvoozvvozsaosvayyovazzszzssa",
"output": "NO"
},
{
"input": "100 44\ndluthkxwnorabqsukgnxnvhmsmzilyulpursnxkdsavgemiuizbyzebhyjejgqrvuckhaqtuvdmpziesmpmewpvozdanjyvwcdgo",
"output": "YES"
},
{
"input": "100 90\ntljonbnwnqounictqqctgonktiqoqlocgoblngijqokuquoolciqwnctgoggcbojtwjlculoikbggquqncittwnjbkgkgubnioib",
"output": "YES"
},
{
"input": "100 79\nykxptzgvbqxlregvkvucewtydvnhqhuggdsyqlvcfiuaiddnrrnstityyehiamrggftsqyduwxpuldztyzgmfkehprrneyvtknmf",
"output": "YES"
},
{
"input": "100 79\naagwekyovbviiqeuakbqbqifwavkfkutoriovgfmittulhwojaptacekdirgqoovlleeoqkkdukpadygfwavppohgdrmymmulgci",
"output": "YES"
},
{
"input": "100 93\nearrehrehenaddhdnrdddhdahnadndheeennrearrhraharddreaeraddhehhhrdnredanndneheddrraaneerreedhnadnerhdn",
"output": "YES"
},
{
"input": "100 48\nbmmaebaebmmmbbmxvmammbvvebvaemvbbaxvbvmaxvvmveaxmbbxaaemxmxvxxxvxbmmxaaaevvaxmvamvvmaxaxavexbmmbmmev",
"output": "YES"
},
{
"input": "100 55\nhsavbkehaaesffaeeffakhkhfehbbvbeasahbbbvkesbfvkefeesesevbsvfkbffakvshsbkahfkfakebsvafkbvsskfhfvaasss",
"output": "YES"
},
{
"input": "100 2\ncscffcffsccffsfsfffccssfsscfsfsssffcffsscfccssfffcfscfsscsccccfsssffffcfcfsfffcsfsccffscffcfccccfffs",
"output": "NO"
},
{
"input": "100 3\nzrgznxgdpgfoiifrrrsjfuhvtqxjlgochhyemismjnanfvvpzzvsgajcbsulxyeoepjfwvhkqogiiwqxjkrpsyaqdlwffoockxnc",
"output": "NO"
},
{
"input": "100 5\njbltyyfjakrjeodqepxpkjideulofbhqzxjwlarufwzwsoxhaexpydpqjvhybmvjvntuvhvflokhshpicbnfgsqsmrkrfzcrswwi",
"output": "NO"
},
{
"input": "100 1\nfnslnqktlbmxqpvcvnemxcutebdwepoxikifkzaaixzzydffpdxodmsxjribmxuqhueifdlwzytxkklwhljswqvlejedyrgguvah",
"output": "NO"
},
{
"input": "100 21\nddjenetwgwmdtjbpzssyoqrtirvoygkjlqhhdcjgeurqpunxpupwaepcqkbjjfhnvgpyqnozhhrmhfwararmlcvpgtnopvjqsrka",
"output": "YES"
},
{
"input": "100 100\nnjrhiauqlgkkpkuvciwzivjbbplipvhslqgdkfnmqrxuxnycmpheenmnrglotzuyxycosfediqcuadklsnzjqzfxnbjwvfljnlvq",
"output": "YES"
},
{
"input": "100 100\nbbbbbbbtbbttbtbbbttbttbtbbttttbbbtbttbbbtbttbtbbttttbbbbbtbbttbtbbtbttbbbtbtbtbtbtbtbbbttbbtbtbtbbtb",
"output": "YES"
},
{
"input": "14 5\nfssmmsfffmfmmm",
"output": "NO"
},
{
"input": "2 1\nff",
"output": "NO"
},
{
"input": "2 1\nhw",
"output": "YES"
},
{
"input": "2 2\nss",
"output": "YES"
},
{
"input": "1 1\nl",
"output": "YES"
},
{
"input": "100 50\nfffffttttttjjjuuuvvvvvdddxxxxwwwwgggbsssncccczzyyyyyhhhhhkrreeeeeeaaaaaiiillllllllooooqqqqqqmmpppppp",
"output": "YES"
},
{
"input": "100 50\nbbbbbbbbgggggggggggaaaaaaaahhhhhhhhhhpppppppppsssssssrrrrrrrrllzzzzzzzeeeeeeekkkkkkkwwwwwwwwjjjjjjjj",
"output": "YES"
},
{
"input": "100 50\nwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxzzzzzzzzzzzzzzzzzzbbbbbbbbbbbbbbbbbbbbjjjjjjjjjjjjjjjjjjjjjjjj",
"output": "YES"
},
{
"input": "100 80\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "YES"
},
{
"input": "100 10\nbbttthhhhiiiiiiijjjjjvvvvpppssssseeeeeeewwwwgggkkkkkkkkmmmddddduuuzzzzllllnnnnnxxyyyffffccraaaaooooq",
"output": "YES"
},
{
"input": "100 20\nssssssssssbbbbbbbhhhhhhhyyyyyyyzzzzzzzzzzzzcccccxxxxxxxxxxddddmmmmmmmeeeeeeejjjjjjjjjwwwwwwwtttttttt",
"output": "YES"
},
{
"input": "1 2\na",
"output": "YES"
},
{
"input": "3 1\nabb",
"output": "NO"
},
{
"input": "2 1\naa",
"output": "NO"
},
{
"input": "2 1\nab",
"output": "YES"
},
{
"input": "6 2\naaaaaa",
"output": "NO"
},
{
"input": "8 4\naaaaaaaa",
"output": "NO"
},
{
"input": "4 2\naaaa",
"output": "NO"
},
{
"input": "4 3\naaaa",
"output": "NO"
},
{
"input": "1 3\na",
"output": "YES"
},
{
"input": "4 3\nzzzz",
"output": "NO"
},
{
"input": "4 1\naaaa",
"output": "NO"
},
{
"input": "3 4\nabc",
"output": "YES"
},
{
"input": "2 5\nab",
"output": "YES"
},
{
"input": "2 4\nab",
"output": "YES"
},
{
"input": "1 10\na",
"output": "YES"
},
{
"input": "5 2\nzzzzz",
"output": "NO"
},
{
"input": "53 26\naaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "NO"
},
{
"input": "4 1\nabab",
"output": "NO"
},
{
"input": "4 1\nabcb",
"output": "NO"
},
{
"input": "4 2\nabbb",
"output": "NO"
},
{
"input": "5 2\nabccc",
"output": "NO"
},
{
"input": "2 3\nab",
"output": "YES"
},
{
"input": "4 3\nbbbs",
"output": "YES"
},
{
"input": "10 2\nazzzzzzzzz",
"output": "NO"
},
{
"input": "1 2\nb",
"output": "YES"
},
{
"input": "1 3\nb",
"output": "YES"
},
{
"input": "4 5\nabcd",
"output": "YES"
},
{
"input": "4 6\naabb",
"output": "YES"
},
{
"input": "5 2\naaaab",
"output": "NO"
},
{
"input": "3 5\naaa",
"output": "YES"
},
{
"input": "5 3\nazzzz",
"output": "NO"
},
{
"input": "4 100\naabb",
"output": "YES"
},
{
"input": "3 10\naaa",
"output": "YES"
},
{
"input": "3 4\naaa",
"output": "YES"
},
{
"input": "12 5\naaaaabbbbbbb",
"output": "NO"
},
{
"input": "5 2\naabbb",
"output": "NO"
},
{
"input": "10 5\nzzzzzzzzzz",
"output": "NO"
},
{
"input": "2 4\naa",
"output": "YES"
},
{
"input": "1 5\na",
"output": "YES"
},
{
"input": "10 5\naaaaaaaaaa",
"output": "NO"
},
{
"input": "6 3\naaaaaa",
"output": "NO"
},
{
"input": "7 1\nabcdeee",
"output": "NO"
},
{
"input": "18 3\naaaaaabbbbbbcccccc",
"output": "NO"
},
{
"input": "8 2\naabbccdd",
"output": "YES"
},
{
"input": "4 2\nzzzz",
"output": "NO"
},
{
"input": "4 2\nabaa",
"output": "NO"
},
{
"input": "3 2\naaa",
"output": "NO"
},
{
"input": "3 1\nzzz",
"output": "NO"
},
{
"input": "5 4\nzzzzz",
"output": "NO"
},
{
"input": "6 2\naabbbc",
"output": "NO"
},
{
"input": "3 6\naaa",
"output": "YES"
},
{
"input": "2 1\nzz",
"output": "NO"
},
{
"input": "10 3\naaaeeeeeee",
"output": "NO"
},
{
"input": "4 5\naabb",
"output": "YES"
},
{
"input": "3 1\naaa",
"output": "NO"
},
{
"input": "5 2\naazzz",
"output": "NO"
},
{
"input": "6 2\nabbbbc",
"output": "NO"
},
{
"input": "4 2\nxxxx",
"output": "NO"
},
{
"input": "6 3\nzzzzzz",
"output": "NO"
},
{
"input": "3 2\nabb",
"output": "YES"
},
{
"input": "3 2\nzzz",
"output": "NO"
},
{
"input": "6 5\nzzzzzz",
"output": "NO"
},
{
"input": "6 3\nbcaaaa",
"output": "NO"
},
{
"input": "100 100\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "YES"
},
{
"input": "3 6\nabc",
"output": "YES"
}
] | 1,503,612,403 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | n,k=map(int,input().split(" "))
s=input().rstrip('\r')
a=[0]*26
for i in s:
a[ord(i)-97]+=1
flag=0
k=len(s)//2
for i in range(26):
if(a[i]>k):
flag=1
break
if(flag==1):
print('NO')
else:
print('YES')
| Title: Generous Kefa
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons.
Output Specification:
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
Demo Input:
['4 2\naabb\n', '6 3\naacaab\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | ```python
n,k=map(int,input().split(" "))
s=input().rstrip('\r')
a=[0]*26
for i in s:
a[ord(i)-97]+=1
flag=0
k=len(s)//2
for i in range(26):
if(a[i]>k):
flag=1
break
if(flag==1):
print('NO')
else:
print('YES')
``` | 0 |
|
994 | A | Fingerprints | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code. | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence.
The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints. | In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. | [
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"4 4\n3 4 1 0\n0 1 7 9\n"
] | [
"7 1 2\n",
"1 0\n"
] | In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important. | 500 | [
{
"input": "7 3\n3 5 7 1 6 2 8\n1 2 7",
"output": "7 1 2"
},
{
"input": "4 4\n3 4 1 0\n0 1 7 9",
"output": "1 0"
},
{
"input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8",
"output": "8 6 4 2"
},
{
"input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9",
"output": "3 7 4 9 0"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 0\n4 5 6 7 1 2 3 0 9 8",
"output": "1 2 3 4 5 6 7 8 9 0"
},
{
"input": "1 1\n4\n4",
"output": "4"
},
{
"input": "3 7\n6 3 4\n4 9 0 1 7 8 6",
"output": "6 4"
},
{
"input": "10 1\n9 0 8 1 7 4 6 5 2 3\n0",
"output": "0"
},
{
"input": "5 10\n6 0 3 8 1\n3 1 0 5 4 7 2 8 9 6",
"output": "6 0 3 8 1"
},
{
"input": "8 2\n7 2 9 6 1 0 3 4\n6 3",
"output": "6 3"
},
{
"input": "5 4\n7 0 1 4 9\n0 9 5 3",
"output": "0 9"
},
{
"input": "10 1\n9 6 2 0 1 8 3 4 7 5\n6",
"output": "6"
},
{
"input": "10 2\n7 1 0 2 4 6 5 9 3 8\n3 2",
"output": "2 3"
},
{
"input": "5 9\n3 7 9 2 4\n3 8 4 5 9 6 1 0 2",
"output": "3 9 2 4"
},
{
"input": "10 6\n7 1 2 3 8 0 6 4 5 9\n1 5 8 2 3 6",
"output": "1 2 3 8 6 5"
},
{
"input": "8 2\n7 4 8 9 2 5 6 1\n6 4",
"output": "4 6"
},
{
"input": "10 2\n1 0 3 5 8 9 4 7 6 2\n0 3",
"output": "0 3"
},
{
"input": "7 6\n9 2 8 6 1 3 7\n4 2 0 3 1 8",
"output": "2 8 1 3"
},
{
"input": "1 6\n3\n6 8 2 4 5 3",
"output": "3"
},
{
"input": "1 8\n0\n9 2 4 8 1 5 0 7",
"output": "0"
},
{
"input": "6 9\n7 3 9 4 1 0\n9 1 5 8 0 6 2 7 4",
"output": "7 9 4 1 0"
},
{
"input": "10 2\n4 9 6 8 3 0 1 5 7 2\n0 1",
"output": "0 1"
},
{
"input": "10 5\n5 2 8 0 9 7 6 1 4 3\n9 6 4 1 2",
"output": "2 9 6 1 4"
},
{
"input": "6 3\n8 3 9 2 7 6\n5 4 3",
"output": "3"
},
{
"input": "4 10\n8 3 9 6\n4 9 6 2 7 0 8 1 3 5",
"output": "8 3 9 6"
},
{
"input": "1 2\n1\n1 0",
"output": "1"
},
{
"input": "3 6\n1 2 3\n4 5 6 1 2 3",
"output": "1 2 3"
},
{
"input": "1 2\n2\n1 2",
"output": "2"
},
{
"input": "1 10\n9\n0 1 2 3 4 5 6 7 8 9",
"output": "9"
}
] | 1,533,032,699 | 599 | PyPy 3 | OK | TESTS | 31 | 140 | 0 | """."""
arr_len, prints_nr = (int(x) for x in input().split())
arr = [int(x) for x in input().split()]
prints = set(int(x) for x in input().split())
for elem in arr:
if elem in prints:
print(elem, end=" ")
| Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.
Input Specification:
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence.
The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints.
Output Specification:
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
Demo Input:
['7 3\n3 5 7 1 6 2 8\n1 2 7\n', '4 4\n3 4 1 0\n0 1 7 9\n']
Demo Output:
['7 1 2\n', '1 0\n']
Note:
In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important. | ```python
"""."""
arr_len, prints_nr = (int(x) for x in input().split())
arr = [int(x) for x in input().split()]
prints = set(int(x) for x in input().split())
for elem in arr:
if elem in prints:
print(elem, end=" ")
``` | 3 |
|
898 | A | Rounding | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct.
For given *n* find out to which integer will Vasya round it. | The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has. | Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer. | [
"5\n",
"113\n",
"1000000000\n",
"5432359\n"
] | [
"0\n",
"110\n",
"1000000000\n",
"5432360\n"
] | In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10. | 500 | [
{
"input": "5",
"output": "0"
},
{
"input": "113",
"output": "110"
},
{
"input": "1000000000",
"output": "1000000000"
},
{
"input": "5432359",
"output": "5432360"
},
{
"input": "999999994",
"output": "999999990"
},
{
"input": "10",
"output": "10"
},
{
"input": "9",
"output": "10"
},
{
"input": "1",
"output": "0"
},
{
"input": "0",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "6",
"output": "10"
},
{
"input": "7",
"output": "10"
},
{
"input": "8",
"output": "10"
},
{
"input": "19",
"output": "20"
},
{
"input": "100",
"output": "100"
},
{
"input": "997",
"output": "1000"
},
{
"input": "9994",
"output": "9990"
},
{
"input": "10002",
"output": "10000"
},
{
"input": "100000",
"output": "100000"
},
{
"input": "99999",
"output": "100000"
},
{
"input": "999999999",
"output": "1000000000"
},
{
"input": "999999998",
"output": "1000000000"
},
{
"input": "999999995",
"output": "999999990"
},
{
"input": "999999990",
"output": "999999990"
},
{
"input": "1000000",
"output": "1000000"
},
{
"input": "1000010",
"output": "1000010"
},
{
"input": "10000010",
"output": "10000010"
},
{
"input": "100000011",
"output": "100000010"
},
{
"input": "400000003",
"output": "400000000"
},
{
"input": "234234",
"output": "234230"
},
{
"input": "675621",
"output": "675620"
},
{
"input": "43532",
"output": "43530"
},
{
"input": "4576453",
"output": "4576450"
},
{
"input": "65754674",
"output": "65754670"
},
{
"input": "3245526",
"output": "3245530"
},
{
"input": "123445",
"output": "123440"
},
{
"input": "234217",
"output": "234220"
},
{
"input": "23451218",
"output": "23451220"
},
{
"input": "1231239",
"output": "1231240"
},
{
"input": "1923140",
"output": "1923140"
},
{
"input": "307910310",
"output": "307910310"
},
{
"input": "780961030",
"output": "780961030"
},
{
"input": "103509421",
"output": "103509420"
},
{
"input": "576560141",
"output": "576560140"
},
{
"input": "48851642",
"output": "48851640"
},
{
"input": "226935072",
"output": "226935070"
},
{
"input": "844450763",
"output": "844450760"
},
{
"input": "22534183",
"output": "22534180"
},
{
"input": "640049874",
"output": "640049870"
},
{
"input": "818133304",
"output": "818133300"
},
{
"input": "730616285",
"output": "730616280"
},
{
"input": "613732415",
"output": "613732410"
},
{
"input": "380991216",
"output": "380991220"
},
{
"input": "559074636",
"output": "559074640"
},
{
"input": "176590327",
"output": "176590330"
},
{
"input": "354673757",
"output": "354673760"
},
{
"input": "267156738",
"output": "267156740"
},
{
"input": "150272868",
"output": "150272870"
},
{
"input": "62755859",
"output": "62755860"
},
{
"input": "945871979",
"output": "945871980"
},
{
"input": "46",
"output": "50"
},
{
"input": "999",
"output": "1000"
},
{
"input": "1397",
"output": "1400"
}
] | 1,586,901,114 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | n = input()
if n[-1]!="0":
n = n.replace(n[-1],"0")
print(n)
| Title: Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct.
For given *n* find out to which integer will Vasya round it.
Input Specification:
The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has.
Output Specification:
Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer.
Demo Input:
['5\n', '113\n', '1000000000\n', '5432359\n']
Demo Output:
['0\n', '110\n', '1000000000\n', '5432360\n']
Note:
In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10. | ```python
n = input()
if n[-1]!="0":
n = n.replace(n[-1],"0")
print(n)
``` | 0 |
|
349 | B | Color the Fence | PROGRAMMING | 1,700 | [
"data structures",
"dp",
"greedy",
"implementation"
] | null | null | Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has.
Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d* requires *a**d* liters of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number.
Help Igor find the maximum number he can write on the fence. | The first line contains a positive integer *v* (0<=≤<=*v*<=≤<=106). The second line contains nine positive integers *a*1,<=*a*2,<=...,<=*a*9 (1<=≤<=*a**i*<=≤<=105). | Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1. | [
"5\n5 4 3 2 1 2 3 4 5\n",
"2\n9 11 1 12 5 8 9 10 6\n",
"0\n1 1 1 1 1 1 1 1 1\n"
] | [
"55555\n",
"33\n",
"-1\n"
] | none | 1,000 | [
{
"input": "5\n5 4 3 2 1 2 3 4 5",
"output": "55555"
},
{
"input": "2\n9 11 1 12 5 8 9 10 6",
"output": "33"
},
{
"input": "0\n1 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "50\n5 3 10 2 2 4 3 6 5",
"output": "5555555555555555555555555"
},
{
"input": "22\n405 343 489 474 385 23 100 94 276",
"output": "-1"
},
{
"input": "62800\n867 936 2 888 474 530 287 822 220",
"output": "3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333..."
},
{
"input": "27\n836 637 966 929 82 678 213 465 688",
"output": "-1"
},
{
"input": "1000000\n100000 100000 100000 100000 100000 100000 100000 100000 100000",
"output": "9999999999"
},
{
"input": "898207\n99745 99746 99748 99752 99760 99776 99808 99872 100000",
"output": "987654321"
},
{
"input": "80910\n64537 83748 97081 82722 12334 3056 9491 59130 28478",
"output": "66666666666666666666666666"
},
{
"input": "120081\n11268 36403 73200 12674 83919 74218 74172 91581 68432",
"output": "4444411111"
},
{
"input": "839851\n29926 55862 57907 51153 56350 86145 1909 22622 89861",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "751233\n69761 51826 91095 73642 98995 93262 377 38818 97480",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "306978\n95955 99204 81786 41258 96065 46946 64532 36297 70808",
"output": "88888888"
},
{
"input": "366313\n18486 12701 92334 95391 61480 14118 20465 69784 13592",
"output": "9999999999922222222222222222"
},
{
"input": "320671\n95788 46450 97582 95928 47742 15508 10466 10301 38822",
"output": "8888888888888888888888888888888"
},
{
"input": "913928\n80373 47589 53204 68236 44060 97485 82241 44149 59825",
"output": "99888888888888855555"
},
{
"input": "630384\n19652 11530 20316 3161 87360 64207 74067 77894 81452",
"output": "4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444"
},
{
"input": "95\n22076 12056 63350 12443 43123 585 52908 18372 96799",
"output": "-1"
},
{
"input": "271380\n19135 80309 23783 48534 98990 37278 85258 67602 40288",
"output": "11111111111111"
},
{
"input": "80085\n56973 29725 30219 17439 53162 6051 41388 35555 39392",
"output": "6666666666666"
},
{
"input": "201332\n20008 22829 30296 1967 32154 67760 11437 90972 79865",
"output": "444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444"
},
{
"input": "3402\n64151 98148 81468 82342 48823 93464 5989 58868 77138",
"output": "-1"
},
{
"input": "432544\n95724 98294 23292 24174 57778 95072 81898 50019 86824",
"output": "444444444444444333"
},
{
"input": "1000000\n1 1 1 1 1 1 1 1 1",
"output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999..."
},
{
"input": "1000000\n2 2 2 2 2 2 2 2 2",
"output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999..."
},
{
"input": "1000000\n2 3 2 2 3 2 2 3 2",
"output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999..."
},
{
"input": "999999\n2 3 2 2 3 2 2 3 3",
"output": "9777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "153\n85 91 28 53 29 30 92 36 89",
"output": "86653"
},
{
"input": "26531\n64 93 48 49 86 57 93 60 96",
"output": "8864433333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333..."
},
{
"input": "17186\n50 90 76 51 91 54 71 90 73",
"output": "9666411111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
},
{
"input": "11213\n51 82 49 50 99 52 69 96 85",
"output": "964433333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333"
},
{
"input": "20075\n57 42 99 45 56 80 76 71 63",
"output": "954422222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
},
{
"input": "21069\n31 19 49 30 28 43 21 25 28",
"output": "9872222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222..."
},
{
"input": "4822\n35 36 21 13 34 36 14 16 20",
"output": "9877444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444"
}
] | 1,648,354,586 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 184 | 102,400 | from sys import stdin
input = stdin.buffer.readline
def func():
dig = -1
curr = 0
if all(v < a[i] for i in range(9)):
print(-1)
return
for i in range(9):
if v // a[i] >= curr:
dig = i
curr = v // a[i]
rem = v % a[dig]
take = -1
for i in range(dig, 9):
if rem + a[dig] >= a[i]:
take = i
print(str(take+1) + str(dig+1)*(curr-1))
v = int(input())
a = list(map(int, input().split()))
func()
| Title: Color the Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has.
Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d* requires *a**d* liters of paint. Besides, Igor heard that Tanya doesn't like zeroes. That's why Igor won't use them in his number.
Help Igor find the maximum number he can write on the fence.
Input Specification:
The first line contains a positive integer *v* (0<=≤<=*v*<=≤<=106). The second line contains nine positive integers *a*1,<=*a*2,<=...,<=*a*9 (1<=≤<=*a**i*<=≤<=105).
Output Specification:
Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1.
Demo Input:
['5\n5 4 3 2 1 2 3 4 5\n', '2\n9 11 1 12 5 8 9 10 6\n', '0\n1 1 1 1 1 1 1 1 1\n']
Demo Output:
['55555\n', '33\n', '-1\n']
Note:
none | ```python
from sys import stdin
input = stdin.buffer.readline
def func():
dig = -1
curr = 0
if all(v < a[i] for i in range(9)):
print(-1)
return
for i in range(9):
if v // a[i] >= curr:
dig = i
curr = v // a[i]
rem = v % a[dig]
take = -1
for i in range(dig, 9):
if rem + a[dig] >= a[i]:
take = i
print(str(take+1) + str(dig+1)*(curr-1))
v = int(input())
a = list(map(int, input().split()))
func()
``` | 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,687,993,615 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n = int(input())
for i in range(n):
x = input()
if len(x) > 10:
print(x[0] + str(len(x) - 2) + x[len(x) - 1])
else:
print(x) | 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):
x = input()
if len(x) > 10:
print(x[0] + str(len(x) - 2) + x[len(x) - 1])
else:
print(x)
``` | 3.977 |
652 | A | Gabriel and Caterpillar | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height *h*1 cm from the ground. On the height *h*2 cm (*h*2<=><=*h*1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by *a* cm per hour by day and slips down by *b* cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple. | The first line contains two integers *h*1,<=*h*2 (1<=≤<=*h*1<=<<=*h*2<=≤<=105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour. | Print the only integer *k* — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer <=-<=1. | [
"10 30\n2 1\n",
"10 13\n1 1\n",
"10 19\n1 2\n",
"1 50\n5 4\n"
] | [
"1\n",
"0\n",
"-1\n",
"1\n"
] | In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day. | 0 | [
{
"input": "10 30\n2 1",
"output": "1"
},
{
"input": "10 13\n1 1",
"output": "0"
},
{
"input": "10 19\n1 2",
"output": "-1"
},
{
"input": "1 50\n5 4",
"output": "1"
},
{
"input": "1 1000\n2 1",
"output": "82"
},
{
"input": "999 1000\n1 1",
"output": "0"
},
{
"input": "999 1000\n1 1000",
"output": "0"
},
{
"input": "1 1000\n999 1",
"output": "0"
},
{
"input": "1 1000\n100 99",
"output": "17"
},
{
"input": "500 509\n1 1",
"output": "-1"
},
{
"input": "500 555\n6 1",
"output": "1"
},
{
"input": "1 100000\n2 1",
"output": "8332"
},
{
"input": "99990 100000\n1 1",
"output": "-1"
},
{
"input": "90000 100000\n2 1",
"output": "832"
},
{
"input": "10 100000\n1 100000",
"output": "-1"
},
{
"input": "1 41\n5 6",
"output": "0"
},
{
"input": "1 100000\n1 100000",
"output": "-1"
},
{
"input": "1 9\n1 1",
"output": "0"
},
{
"input": "8 16\n1 12",
"output": "0"
},
{
"input": "14 30\n2 1",
"output": "0"
},
{
"input": "7245 77828\n6224 92468",
"output": "-1"
},
{
"input": "43951 66098\n1604 35654",
"output": "-1"
},
{
"input": "1 2\n4 3",
"output": "0"
},
{
"input": "90493 94279\n468 49",
"output": "1"
},
{
"input": "1 50\n3 1",
"output": "2"
},
{
"input": "26300 88310\n7130 351",
"output": "1"
},
{
"input": "1 17\n2 2",
"output": "0"
},
{
"input": "10718 75025\n7083 6958",
"output": "6"
},
{
"input": "1 10\n1 100000",
"output": "-1"
},
{
"input": "1 190\n10 1",
"output": "2"
},
{
"input": "24951 85591\n3090 8945",
"output": "-1"
},
{
"input": "1 25\n3 2",
"output": "0"
},
{
"input": "27043 88418\n7273 7",
"output": "1"
},
{
"input": "35413 75637\n4087 30166",
"output": "-1"
},
{
"input": "1 18\n2 3",
"output": "-1"
},
{
"input": "1 16\n2 2",
"output": "0"
},
{
"input": "1 18\n2 1",
"output": "1"
},
{
"input": "1 10\n2 2",
"output": "0"
},
{
"input": "1 30\n2 1",
"output": "2"
},
{
"input": "1 100000\n10000 100000",
"output": "-1"
},
{
"input": "4444 33425\n2758 44",
"output": "1"
},
{
"input": "1 100000\n10 99910",
"output": "-1"
},
{
"input": "12 100\n6 11",
"output": "-1"
},
{
"input": "100 100000\n10 11",
"output": "-1"
},
{
"input": "28473 80380\n2568 95212",
"output": "-1"
},
{
"input": "10 105\n10 1",
"output": "1"
},
{
"input": "4642 39297\n3760 451",
"output": "1"
},
{
"input": "1 90\n10 1",
"output": "1"
},
{
"input": "2 100\n1 100000",
"output": "-1"
},
{
"input": "1 100000\n1000 100000",
"output": "-1"
},
{
"input": "1 45\n1 100000",
"output": "-1"
},
{
"input": "12 1000\n100 1",
"output": "1"
},
{
"input": "64635 76564\n100 34238",
"output": "-1"
},
{
"input": "10 90\n10 12",
"output": "0"
},
{
"input": "49238 81395\n3512 251",
"output": "1"
},
{
"input": "6497 62133\n309 50077",
"output": "-1"
},
{
"input": "1 100\n1 100000",
"output": "-1"
},
{
"input": "1 10000\n1 10000",
"output": "-1"
},
{
"input": "55674 93249\n846 1",
"output": "4"
},
{
"input": "10 90\n9 10",
"output": "-1"
},
{
"input": "23110 69794\n171 808",
"output": "-1"
},
{
"input": "1 100000\n1 10000",
"output": "-1"
},
{
"input": "1 9\n1 2",
"output": "0"
},
{
"input": "58750 81357\n2 98022",
"output": "-1"
},
{
"input": "82125 89348\n894 91369",
"output": "-1"
},
{
"input": "25401 53663\n957 30449",
"output": "-1"
},
{
"input": "2 12\n1 2",
"output": "-1"
},
{
"input": "1 10000\n1 100000",
"output": "-1"
},
{
"input": "1 100000\n1 99999",
"output": "-1"
},
{
"input": "1 149\n8 2",
"output": "2"
},
{
"input": "3 100\n1 1",
"output": "-1"
},
{
"input": "1 18\n2 2",
"output": "-1"
},
{
"input": "1 77\n9 1",
"output": "1"
},
{
"input": "7330 94486\n968 141",
"output": "9"
},
{
"input": "89778 98176\n863 61",
"output": "1"
},
{
"input": "1 70\n6 5",
"output": "2"
}
] | 1,458,911,451 | 651 | Python 3 | OK | TESTS | 76 | 62 | 5,120,000 | def solve():
h1, h2 = map(int, input().split())
a, b = map(int, input().split())
h3 = h1 + a * 8
if h3 >= h2:
print(0)
return
if b >= a:
print(-1)
return
h4 = h2 - h3
c = (a - b) * 12
ans = int((h4 + (c - 1)) / c)
print(ans)
if __name__ == '__main__':
solve()
| Title: Gabriel and Caterpillar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height *h*1 cm from the ground. On the height *h*2 cm (*h*2<=><=*h*1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by *a* cm per hour by day and slips down by *b* cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input Specification:
The first line contains two integers *h*1,<=*h*2 (1<=≤<=*h*1<=<<=*h*2<=≤<=105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output Specification:
Print the only integer *k* — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer <=-<=1.
Demo Input:
['10 30\n2 1\n', '10 13\n1 1\n', '10 19\n1 2\n', '1 50\n5 4\n']
Demo Output:
['1\n', '0\n', '-1\n', '1\n']
Note:
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day. | ```python
def solve():
h1, h2 = map(int, input().split())
a, b = map(int, input().split())
h3 = h1 + a * 8
if h3 >= h2:
print(0)
return
if b >= a:
print(-1)
return
h4 = h2 - h3
c = (a - b) * 12
ans = int((h4 + (c - 1)) / c)
print(ans)
if __name__ == '__main__':
solve()
``` | 3 |
|
382 | A | Ksenia and Pan Scales | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan. | The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.
The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.
It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters. | If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them. | [
"AC|T\nL\n",
"|ABC\nXYZ\n",
"W|T\nF\n",
"ABC|\nD\n"
] | [
"AC|TL\n",
"XYZ|ABC\n",
"Impossible\n",
"Impossible\n"
] | none | 500 | [
{
"input": "AC|T\nL",
"output": "AC|TL"
},
{
"input": "|ABC\nXYZ",
"output": "XYZ|ABC"
},
{
"input": "W|T\nF",
"output": "Impossible"
},
{
"input": "ABC|\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDEF",
"output": "ADF|BCE"
},
{
"input": "|\nABC",
"output": "Impossible"
},
{
"input": "|\nZXCVBANMIO",
"output": "XVAMO|ZCBNI"
},
{
"input": "|C\nA",
"output": "A|C"
},
{
"input": "|\nAB",
"output": "B|A"
},
{
"input": "A|XYZ\nUIOPL",
"output": "Impossible"
},
{
"input": "K|B\nY",
"output": "Impossible"
},
{
"input": "EQJWDOHKZRBISPLXUYVCMNFGT|\nA",
"output": "Impossible"
},
{
"input": "|MACKERIGZPVHNDYXJBUFLWSO\nQT",
"output": "Impossible"
},
{
"input": "ERACGIZOVPT|WXUYMDLJNQS\nKB",
"output": "ERACGIZOVPTB|WXUYMDLJNQSK"
},
{
"input": "CKQHRUZMISGE|FBVWPXDLTJYN\nOA",
"output": "CKQHRUZMISGEA|FBVWPXDLTJYNO"
},
{
"input": "V|CMOEUTAXBFWSK\nDLRZJGIYNQHP",
"output": "VDLRZJGIYNQHP|CMOEUTAXBFWSK"
},
{
"input": "QWHNMALDGKTJ|\nPBRYVXZUESCOIF",
"output": "QWHNMALDGKTJF|PBRYVXZUESCOI"
},
{
"input": "|\nFXCVMUEWZAHNDOSITPRLKQJYBG",
"output": "XVUWANOIPLQYG|FCMEZHDSTRKJB"
},
{
"input": "IB|PCGHZ\nFXWTJQNEKAUM",
"output": "Impossible"
},
{
"input": "EC|IWAXQ\nJUHSRKGZTOMYN",
"output": "ECJUHRGTMN|IWAXQSKZOY"
},
{
"input": "VDINYMA|UQKWBCLRHZJ\nXEGOF",
"output": "Impossible"
},
{
"input": "ZLTPSIQUBAR|XFDEMYC\nHNOJWG",
"output": "ZLTPSIQUBARG|XFDEMYCHNOJW"
},
{
"input": "R|FLZOTJNU\nGIYHKVX",
"output": "RGIYHKVX|FLZOTJNU"
},
{
"input": "W|TL\nQROFSADYPKHEJNMXBZVUCIG",
"output": "WQOSDPHJMBVCG|TLRFAYKENXZUI"
},
{
"input": "NRDFQSEKLAYMOT|ZH\nGUXIBJCVPW",
"output": "Impossible"
},
{
"input": "FGRT|\nAC",
"output": "Impossible"
},
{
"input": "|FGRT\nAC",
"output": "Impossible"
},
{
"input": "A|\nB",
"output": "A|B"
},
{
"input": "|A\nB",
"output": "B|A"
},
{
"input": "|\nA",
"output": "Impossible"
},
{
"input": "|\nQWERTYUIOPASDFGHJKLZXCVBNM",
"output": "WRYIPSFHKZCBM|QETUOADGJLXVN"
},
{
"input": "QWERTYUIOPASDFGHJKLZXCVBN|\nM",
"output": "Impossible"
},
{
"input": "QWERTY|VBN\nUIOPASDFGHJKLZXC",
"output": "Impossible"
},
{
"input": "ABC|D\nKSL",
"output": "Impossible"
},
{
"input": "A|BCDEF\nGH",
"output": "Impossible"
},
{
"input": "|ABC\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDE",
"output": "Impossible"
},
{
"input": "|ASD\nX",
"output": "Impossible"
},
{
"input": "AB|CDEF\nXYZRT",
"output": "Impossible"
}
] | 1,591,754,111 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | l, r = input().split("|")
ws = input()
need = max(len(l), len(r)) - min(len(l), len(r))
if need <= len(ws):
if (len(l) <= len(r)):
l += ws[:need]
else:
r += ws[:need]
else:
print("Impossible")
print(f"{l}|{r}") | Title: Ksenia and Pan Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.
Input Specification:
The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.
The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.
It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.
Output Specification:
If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them.
Demo Input:
['AC|T\nL\n', '|ABC\nXYZ\n', 'W|T\nF\n', 'ABC|\nD\n']
Demo Output:
['AC|TL\n', 'XYZ|ABC\n', 'Impossible\n', 'Impossible\n']
Note:
none | ```python
l, r = input().split("|")
ws = input()
need = max(len(l), len(r)) - min(len(l), len(r))
if need <= len(ws):
if (len(l) <= len(r)):
l += ws[:need]
else:
r += ws[:need]
else:
print("Impossible")
print(f"{l}|{r}")
``` | 0 |
|
177 | A1 | Good Matrix Elements | PROGRAMMING | 800 | [
"implementation"
] | null | null | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which has exactly rows above it and the same number of rows below it. - Elements of the "middle" column — the column that has exactly columns to the left of it and the same number of columns to the right of it.
Help the Smart Beaver count the sum of good elements of the given matrix. | The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
- 1<=≤<=*n*<=≤<=5
The input limitations for getting 100 points are:
- 1<=≤<=*n*<=≤<=101 | Print a single integer — the sum of good matrix elements. | [
"3\n1 2 3\n4 5 6\n7 8 9\n",
"5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n"
] | [
"45\n",
"17\n"
] | In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | 30 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "45"
},
{
"input": "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1",
"output": "17"
},
{
"input": "1\n3",
"output": "3"
},
{
"input": "5\n27 7 3 11 72\n19 49 68 19 59\n41 25 37 64 65\n8 39 96 62 90\n13 37 43 26 33",
"output": "756"
},
{
"input": "3\n19 7 16\n12 15 5\n15 15 5",
"output": "109"
},
{
"input": "3\n36 4 33\n11 46 32\n20 49 34",
"output": "265"
},
{
"input": "3\n79 91 74\n33 82 22\n18 28 54",
"output": "481"
},
{
"input": "5\n7 0 8 1 7\n5 1 1 0 4\n4 2 8 1 6\n1 2 3 2 7\n6 0 1 9 6",
"output": "65"
},
{
"input": "5\n27 20 28 11 17\n25 21 1 20 14\n14 22 28 1 6\n1 2 23 2 7\n6 0 1 29 6",
"output": "225"
},
{
"input": "5\n57 50 58 41 17\n25 21 1 50 44\n44 22 28 31 36\n31 32 23 32 37\n6 0 31 59 6",
"output": "495"
},
{
"input": "5\n57 80 28 41 47\n85 51 61 50 74\n44 82 28 31 36\n31 32 23 32 37\n66 60 31 59 6",
"output": "705"
},
{
"input": "5\n13 58 10 17 43\n61 73 100 0 9\n52 38 16 22 96\n11 4 14 67 62\n70 89 7 98 83",
"output": "708"
},
{
"input": "5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "5\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "5\n0 1 0 1 0\n0 0 0 0 1\n0 0 5 0 0\n0 0 0 0 1\n0 0 0 0 0",
"output": "5"
},
{
"input": "5\n0 0 0 0 1\n0 1 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 1 0 0 0",
"output": "3"
},
{
"input": "3\n0 0 0\n0 0 0\n0 0 0",
"output": "0"
}
] | 1,599,152,958 | 2,147,483,647 | Python 3 | OK | TESTS1 | 17 | 218 | 307,200 | n=int(input())
l=[]
for _ in range(n):
l.append(list(map(int,input().split())))
k=int((n/2))
s=0
#print('d1')
for i in range(0,n):
#print(l[i][i])
s+=l[i][i]
#x=0
#print('d2')
for i in range(0,n):
#print(l[n-1-i][i])
s+=l[n-i-1][i]
s+=sum(l[k])
#print('s2')
for i in range(0,n):
#print(l[i][k])
s+=l[i][k]
print(s-((l[k][k])*3))
| Title: Good Matrix Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which has exactly rows above it and the same number of rows below it. - Elements of the "middle" column — the column that has exactly columns to the left of it and the same number of columns to the right of it.
Help the Smart Beaver count the sum of good elements of the given matrix.
Input Specification:
The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
- 1<=≤<=*n*<=≤<=5
The input limitations for getting 100 points are:
- 1<=≤<=*n*<=≤<=101
Output Specification:
Print a single integer — the sum of good matrix elements.
Demo Input:
['3\n1 2 3\n4 5 6\n7 8 9\n', '5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n']
Demo Output:
['45\n', '17\n']
Note:
In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | ```python
n=int(input())
l=[]
for _ in range(n):
l.append(list(map(int,input().split())))
k=int((n/2))
s=0
#print('d1')
for i in range(0,n):
#print(l[i][i])
s+=l[i][i]
#x=0
#print('d2')
for i in range(0,n):
#print(l[n-1-i][i])
s+=l[n-i-1][i]
s+=sum(l[k])
#print('s2')
for i in range(0,n):
#print(l[i][k])
s+=l[i][k]
print(s-((l[k][k])*3))
``` | 3 |
|
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space. | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input": "1\nqvwli hz",
"output": "1"
},
{
"input": "4\nsrhk x\nsrhk x\nqfoe vnrjuab\nqfoe vnrjuab",
"output": "2"
},
{
"input": "4\nsddqllmmpk syded\nfprsq fnenjnaz\nn hdej\nsddqllmmpk syded",
"output": "3"
},
{
"input": "17\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw\njtbctslqq tosqzw",
"output": "1"
},
{
"input": "18\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp\nb d\nrfdb esp\nb d\nrfdb esp\nb d\nb d\nrfdb esp\nrfdb esp",
"output": "2"
},
{
"input": "13\nsvpzwtwn rykzfdce\nqweiyeck jkreouy\nhk nnli\ntwxrnbbdt vtuv\nxokqjtylly sz\nesdt dbfidjslq\ng ybqgomvw\nxcpfjmf zcqvz\nifajadhj invzueip\nvdemdnxifb hckwebmi\nsdpnhipam wvowzavh\nuqdlfskhgo vunbpghae\ne dtigwnb",
"output": "13"
},
{
"input": "20\nm vkfh\nvptikamead mvx\nitu mf\nklruxckw aqega\nekqkd enjllwol\ncc uybfdh\nimrfdngvo u\ne uh\ntwt jsslcfuogk\nbljwqsag tuqbdn\nqcv q\nasx gzhvwwmajj\nqcv q\nekqkd enjllwol\nasx gzhvwwmajj\nks vv\nkzyfi cn\ncc uybfdh\nitu mf\ncjbjhtbyvk vatwfmux",
"output": "15"
},
{
"input": "2\nab ab\na bab",
"output": "2"
}
] | 1,651,938,752 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 62 | 0 | m=[]
for i in range(int(input())):
a=str(input())
m.append(a)
d=set(m)
n=list(d)
print(len(n))
| Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.
Output Specification:
Output the single number — the number of Alyona's leaves.
Demo Input:
['5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n', '3\noak yellow\noak yellow\noak yellow\n']
Demo Output:
['4\n', '1\n']
Note:
none | ```python
m=[]
for i in range(int(input())):
a=str(input())
m.append(a)
d=set(m)
n=list(d)
print(len(n))
``` | 3.9845 |
454 | A | Little Pony and Crystal Mine | PROGRAMMING | 800 | [
"implementation"
] | null | null | Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=><=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it.
You are given an odd integer *n*. You need to draw a crystal of size *n*. The diamond cells of the matrix should be represented by character "D". All other cells of the matrix should be represented by character "*". Look at the examples to understand what you need to draw. | The only line contains an integer *n* (3<=≤<=*n*<=≤<=101; *n* is odd). | Output a crystal of size *n*. | [
"3\n",
"5\n",
"7\n"
] | [
"*D*\nDDD\n*D*\n",
"**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n",
"***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n"
] | none | 500 | [
{
"input": "3",
"output": "*D*\nDDD\n*D*"
},
{
"input": "5",
"output": "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**"
},
{
"input": "7",
"output": "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***"
},
{
"input": "11",
"output": "*****D*****\n****DDD****\n***DDDDD***\n**DDDDDDD**\n*DDDDDDDDD*\nDDDDDDDDDDD\n*DDDDDDDDD*\n**DDDDDDD**\n***DDDDD***\n****DDD****\n*****D*****"
},
{
"input": "15",
"output": "*******D*******\n******DDD******\n*****DDDDD*****\n****DDDDDDD****\n***DDDDDDDDD***\n**DDDDDDDDDDD**\n*DDDDDDDDDDDDD*\nDDDDDDDDDDDDDDD\n*DDDDDDDDDDDDD*\n**DDDDDDDDDDD**\n***DDDDDDDDD***\n****DDDDDDD****\n*****DDDDD*****\n******DDD******\n*******D*******"
},
{
"input": "21",
"output": "**********D**********\n*********DDD*********\n********DDDDD********\n*******DDDDDDD*******\n******DDDDDDDDD******\n*****DDDDDDDDDDD*****\n****DDDDDDDDDDDDD****\n***DDDDDDDDDDDDDDD***\n**DDDDDDDDDDDDDDDDD**\n*DDDDDDDDDDDDDDDDDDD*\nDDDDDDDDDDDDDDDDDDDDD\n*DDDDDDDDDDDDDDDDDDD*\n**DDDDDDDDDDDDDDDDD**\n***DDDDDDDDDDDDDDD***\n****DDDDDDDDDDDDD****\n*****DDDDDDDDDDD*****\n******DDDDDDDDD******\n*******DDDDDDD*******\n********DDDDD********\n*********DDD*********\n**********D**********"
},
{
"input": "33",
"output": "****************D****************\n***************DDD***************\n**************DDDDD**************\n*************DDDDDDD*************\n************DDDDDDDDD************\n***********DDDDDDDDDDD***********\n**********DDDDDDDDDDDDD**********\n*********DDDDDDDDDDDDDDD*********\n********DDDDDDDDDDDDDDDDD********\n*******DDDDDDDDDDDDDDDDDDD*******\n******DDDDDDDDDDDDDDDDDDDDD******\n*****DDDDDDDDDDDDDDDDDDDDDDD*****\n****DDDDDDDDDDDDDDDDDDDDDDDDD****\n***DDDDDDDDDDDDDDDDDDDDDDDDDDD***\n**DDDDDDDDDDDDDDDDDDD..."
},
{
"input": "57",
"output": "****************************D****************************\n***************************DDD***************************\n**************************DDDDD**************************\n*************************DDDDDDD*************************\n************************DDDDDDDDD************************\n***********************DDDDDDDDDDD***********************\n**********************DDDDDDDDDDDDD**********************\n*********************DDDDDDDDDDDDDDD*********************\n********************DDDDDDDDDDDDDDDDD**..."
},
{
"input": "69",
"output": "**********************************D**********************************\n*********************************DDD*********************************\n********************************DDDDD********************************\n*******************************DDDDDDD*******************************\n******************************DDDDDDDDD******************************\n*****************************DDDDDDDDDDD*****************************\n****************************DDDDDDDDDDDDD****************************\n**************..."
},
{
"input": "81",
"output": "****************************************D****************************************\n***************************************DDD***************************************\n**************************************DDDDD**************************************\n*************************************DDDDDDD*************************************\n************************************DDDDDDDDD************************************\n***********************************DDDDDDDDDDD***********************************\n*************..."
},
{
"input": "91",
"output": "*********************************************D*********************************************\n********************************************DDD********************************************\n*******************************************DDDDD*******************************************\n******************************************DDDDDDD******************************************\n*****************************************DDDDDDDDD*****************************************\n****************************************DDDDDD..."
},
{
"input": "101",
"output": "**************************************************D**************************************************\n*************************************************DDD*************************************************\n************************************************DDDDD************************************************\n***********************************************DDDDDDD***********************************************\n**********************************************DDDDDDDDD********************************************..."
}
] | 1,621,510,298 | 2,147,483,647 | Python 3 | OK | TESTS | 12 | 62 | 0 | n = int(input())
# n // 2 stars * first line
# decrease till 3 then increase
ans = n//2
woioi = n//2
j = 0
for i in range(n):
print('*'*ans + 'D'*(n-2*ans) + '*'*ans)
j += 1
if j <= woioi:
ans -= 1
continue
if j <= n:
ans += 1
| Title: Little Pony and Crystal Mine
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=><=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it.
You are given an odd integer *n*. You need to draw a crystal of size *n*. The diamond cells of the matrix should be represented by character "D". All other cells of the matrix should be represented by character "*". Look at the examples to understand what you need to draw.
Input Specification:
The only line contains an integer *n* (3<=≤<=*n*<=≤<=101; *n* is odd).
Output Specification:
Output a crystal of size *n*.
Demo Input:
['3\n', '5\n', '7\n']
Demo Output:
['*D*\nDDD\n*D*\n', '**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n', '***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n']
Note:
none | ```python
n = int(input())
# n // 2 stars * first line
# decrease till 3 then increase
ans = n//2
woioi = n//2
j = 0
for i in range(n):
print('*'*ans + 'D'*(n-2*ans) + '*'*ans)
j += 1
if j <= woioi:
ans -= 1
continue
if j <= n:
ans += 1
``` | 3 |
|
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value *w* equal to 0. | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "1\n1 2 3"
},
{
"input": "12\n3 3 3 3 3 3 3 3 1 3 3 2",
"output": "1\n9 12 2"
},
{
"input": "60\n3 3 1 2 2 1 3 1 1 1 3 2 2 2 3 3 1 3 2 3 2 2 1 3 3 2 3 1 2 2 2 1 3 2 1 1 3 3 1 1 1 3 1 2 1 1 3 3 3 2 3 2 3 2 2 2 1 1 1 2",
"output": "20\n6 60 1\n17 44 20\n3 5 33\n36 21 42\n59 14 2\n58 26 49\n9 29 48\n23 19 24\n10 30 37\n41 54 15\n45 31 27\n57 55 38\n39 12 25\n35 34 11\n32 52 7\n8 50 18\n43 4 53\n46 56 51\n40 22 16\n28 13 47"
},
{
"input": "12\n3 1 1 1 1 1 1 2 1 1 1 1",
"output": "1\n3 8 1"
},
{
"input": "22\n2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 1 2 2 2 2",
"output": "1\n18 2 11"
},
{
"input": "138\n2 3 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 3 2 2 2 1 2 3 2 2 2 3 1 3 2 3 2 3 2 2 2 2 3 2 2 2 2 2 1 2 2 3 2 2 3 2 1 2 2 2 2 2 3 1 2 2 2 2 2 3 2 2 3 2 2 2 2 2 1 1 2 3 2 2 2 2 3 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 3 2 3 2 2 2 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 3",
"output": "18\n13 91 84\n34 90 48\n11 39 77\n78 129 50\n137 68 119\n132 122 138\n19 12 96\n40 7 2\n22 88 69\n107 73 46\n115 15 52\n127 106 87\n93 92 66\n71 112 117\n63 124 42\n17 70 101\n109 121 57\n123 25 36"
},
{
"input": "203\n2 2 1 2 1 2 2 2 1 2 2 1 1 3 1 2 1 2 1 1 2 3 1 1 2 3 3 2 2 2 1 2 1 1 1 1 1 3 1 1 2 1 1 2 2 2 1 2 2 2 1 2 3 2 1 1 2 2 1 2 1 2 2 1 1 2 2 2 1 1 2 2 1 2 1 2 2 3 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 2 2 1 3 2 1 1 1 2 1 1 2 1 1 2 2 2 1 1 2 2 2 1 2 1 3 2 1 2 2 2 1 1 1 2 2 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 1 1 1 1 1 1 2 2 3 1 1 2 3 1 1 1 1 1 1 2 2 1 1 1 2 2 3 2 1 3 1 1 1",
"output": "13\n188 72 14\n137 4 197\n158 76 122\n152 142 26\n104 119 179\n40 63 38\n12 1 78\n17 30 27\n189 60 53\n166 190 144\n129 7 183\n83 41 22\n121 81 200"
},
{
"input": "220\n1 1 3 1 3 1 1 3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 1 1 1 3 1 1 1 3 2 3 3 3 1 1 3 3 1 1 3 3 3 3 1 3 3 1 1 1 2 3 1 1 1 2 3 3 3 2 3 1 1 3 1 1 1 3 2 1 3 2 3 1 1 3 3 3 1 3 1 1 1 3 3 2 1 3 2 1 1 3 3 1 1 1 2 1 1 3 2 1 2 1 1 1 3 1 3 3 1 2 3 3 3 3 1 3 1 1 1 1 2 3 1 1 1 1 1 1 3 2 3 1 3 1 3 1 1 3 1 3 1 3 1 3 1 3 3 2 3 1 3 3 1 3 3 3 3 1 1 3 3 3 3 1 1 3 3 3 2 1 1 1 3 3 1 3 3 3 1 1 1 3 1 3 3 1 1 1 2 3 1 1 3 1 1 1 1 2 3 1 1 2 3 3 1 3 1 3 3 3 3 1 3 2 3 1 1 3",
"output": "20\n198 89 20\n141 56 131\n166 204 19\n160 132 142\n111 112 195\n45 216 92\n6 31 109\n14 150 170\n199 60 18\n173 123 140\n134 69 156\n82 191 85\n126 200 80\n24 97 46\n62 86 149\n214 101 26\n79 171 78\n125 72 118\n172 103 162\n219 51 64"
},
{
"input": "61\n2 3 1 3 2 2 2 3 1 3 2 3 1 2 1 1 2 2 2 2 3 2 3 1 2 1 3 1 3 2 1 1 3 2 1 3 3 3 1 3 3 1 1 3 1 3 2 2 1 2 2 2 1 3 2 3 1 3 3 1 1",
"output": "20\n9 55 2\n24 34 27\n3 5 37\n35 17 41\n61 11 4\n60 19 54\n15 20 59\n26 14 29\n16 22 38\n43 50 12\n49 25 36\n57 51 40\n39 6 33\n32 30 10\n31 48 8\n13 47 23\n45 1 58\n53 52 56\n42 18 21\n28 7 44"
},
{
"input": "5\n1 2 2 3 3",
"output": "1\n1 3 4"
}
] | 1,678,618,283 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n = int(input())
kids = [int(l) for l in input().split()]
prog = []
math = []
sports = []
for i in range(n):
if kids[i] == 1:
prog.append(i)
if kids[i] == 2:
math.append(i)
if kids[i] == 3:
sports.append(i)
k = min(len(prog), len(math), len(sports))
print(k)
for i in range(k):
print(prog[i], math[i], sports[i])
| Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child.
Output Specification:
In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value *w* equal to 0.
Demo Input:
['7\n1 3 1 3 2 1 2\n', '4\n2 1 1 2\n']
Demo Output:
['2\n3 5 2\n6 7 4\n', '0\n']
Note:
none | ```python
n = int(input())
kids = [int(l) for l in input().split()]
prog = []
math = []
sports = []
for i in range(n):
if kids[i] == 1:
prog.append(i)
if kids[i] == 2:
math.append(i)
if kids[i] == 3:
sports.append(i)
k = min(len(prog), len(math), len(sports))
print(k)
for i in range(k):
print(prog[i], math[i], sports[i])
``` | 0 |
|
201 | A | Clear Symmetry | PROGRAMMING | 1,700 | [
"constructive algorithms",
"dp",
"math"
] | null | null | Consider some square matrix *A* with side *n* consisting of zeros and ones. There are *n* rows numbered from 1 to *n* from top to bottom and *n* columns numbered from 1 to *n* from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the *i*-row and the *j*-th column as *A**i*,<=*j*.
Let's call matrix *A* clear if no two cells containing ones have a common side.
Let's call matrix *A* symmetrical if it matches the matrices formed from it by a horizontal and/or a vertical reflection. Formally, for each pair (*i*,<=*j*) (1<=≤<=*i*,<=*j*<=≤<=*n*) both of the following conditions must be met: *A**i*,<=*j*<==<=*A**n*<=-<=*i*<=+<=1,<=*j* and *A**i*,<=*j*<==<=*A**i*,<=*n*<=-<=*j*<=+<=1.
Let's define the sharpness of matrix *A* as the number of ones in it.
Given integer *x*, your task is to find the smallest positive integer *n* such that there exists a clear symmetrical matrix *A* with side *n* and sharpness *x*. | The only line contains a single integer *x* (1<=≤<=*x*<=≤<=100) — the required sharpness of the matrix. | Print a single number — the sought value of *n*. | [
"4\n",
"9\n"
] | [
"3\n",
"5\n"
] | The figure below shows the matrices that correspond to the samples: | 1,000 | [
{
"input": "4",
"output": "3"
},
{
"input": "9",
"output": "5"
},
{
"input": "10",
"output": "5"
},
{
"input": "12",
"output": "5"
},
{
"input": "1",
"output": "1"
},
{
"input": "19",
"output": "7"
},
{
"input": "3",
"output": "5"
},
{
"input": "2",
"output": "3"
},
{
"input": "5",
"output": "3"
},
{
"input": "6",
"output": "5"
},
{
"input": "7",
"output": "5"
},
{
"input": "8",
"output": "5"
},
{
"input": "11",
"output": "5"
},
{
"input": "13",
"output": "5"
},
{
"input": "14",
"output": "7"
},
{
"input": "15",
"output": "7"
},
{
"input": "16",
"output": "7"
},
{
"input": "17",
"output": "7"
},
{
"input": "18",
"output": "7"
},
{
"input": "20",
"output": "7"
},
{
"input": "21",
"output": "7"
},
{
"input": "22",
"output": "7"
},
{
"input": "23",
"output": "7"
},
{
"input": "24",
"output": "7"
},
{
"input": "25",
"output": "7"
},
{
"input": "26",
"output": "9"
},
{
"input": "27",
"output": "9"
},
{
"input": "28",
"output": "9"
},
{
"input": "29",
"output": "9"
},
{
"input": "30",
"output": "9"
},
{
"input": "31",
"output": "9"
},
{
"input": "32",
"output": "9"
},
{
"input": "33",
"output": "9"
},
{
"input": "34",
"output": "9"
},
{
"input": "35",
"output": "9"
},
{
"input": "36",
"output": "9"
},
{
"input": "37",
"output": "9"
},
{
"input": "38",
"output": "9"
},
{
"input": "39",
"output": "9"
},
{
"input": "40",
"output": "9"
},
{
"input": "41",
"output": "9"
},
{
"input": "42",
"output": "11"
},
{
"input": "43",
"output": "11"
},
{
"input": "44",
"output": "11"
},
{
"input": "45",
"output": "11"
},
{
"input": "46",
"output": "11"
},
{
"input": "47",
"output": "11"
},
{
"input": "48",
"output": "11"
},
{
"input": "49",
"output": "11"
},
{
"input": "50",
"output": "11"
},
{
"input": "51",
"output": "11"
},
{
"input": "52",
"output": "11"
},
{
"input": "53",
"output": "11"
},
{
"input": "54",
"output": "11"
},
{
"input": "55",
"output": "11"
},
{
"input": "56",
"output": "11"
},
{
"input": "57",
"output": "11"
},
{
"input": "58",
"output": "11"
},
{
"input": "59",
"output": "11"
},
{
"input": "60",
"output": "11"
},
{
"input": "61",
"output": "11"
},
{
"input": "62",
"output": "13"
},
{
"input": "63",
"output": "13"
},
{
"input": "64",
"output": "13"
},
{
"input": "65",
"output": "13"
},
{
"input": "66",
"output": "13"
},
{
"input": "67",
"output": "13"
},
{
"input": "68",
"output": "13"
},
{
"input": "69",
"output": "13"
},
{
"input": "70",
"output": "13"
},
{
"input": "71",
"output": "13"
},
{
"input": "72",
"output": "13"
},
{
"input": "73",
"output": "13"
},
{
"input": "74",
"output": "13"
},
{
"input": "75",
"output": "13"
},
{
"input": "76",
"output": "13"
},
{
"input": "77",
"output": "13"
},
{
"input": "78",
"output": "13"
},
{
"input": "79",
"output": "13"
},
{
"input": "80",
"output": "13"
},
{
"input": "81",
"output": "13"
},
{
"input": "82",
"output": "13"
},
{
"input": "83",
"output": "13"
},
{
"input": "84",
"output": "13"
},
{
"input": "85",
"output": "13"
},
{
"input": "86",
"output": "15"
},
{
"input": "87",
"output": "15"
},
{
"input": "88",
"output": "15"
},
{
"input": "89",
"output": "15"
},
{
"input": "90",
"output": "15"
},
{
"input": "91",
"output": "15"
},
{
"input": "92",
"output": "15"
},
{
"input": "93",
"output": "15"
},
{
"input": "94",
"output": "15"
},
{
"input": "95",
"output": "15"
},
{
"input": "96",
"output": "15"
},
{
"input": "97",
"output": "15"
},
{
"input": "98",
"output": "15"
},
{
"input": "99",
"output": "15"
},
{
"input": "100",
"output": "15"
}
] | 1,648,456,703 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | from math import ceil,sqrt
x = int(input())
print(ceil(sqrt(2*x))) | Title: Clear Symmetry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider some square matrix *A* with side *n* consisting of zeros and ones. There are *n* rows numbered from 1 to *n* from top to bottom and *n* columns numbered from 1 to *n* from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the *i*-row and the *j*-th column as *A**i*,<=*j*.
Let's call matrix *A* clear if no two cells containing ones have a common side.
Let's call matrix *A* symmetrical if it matches the matrices formed from it by a horizontal and/or a vertical reflection. Formally, for each pair (*i*,<=*j*) (1<=≤<=*i*,<=*j*<=≤<=*n*) both of the following conditions must be met: *A**i*,<=*j*<==<=*A**n*<=-<=*i*<=+<=1,<=*j* and *A**i*,<=*j*<==<=*A**i*,<=*n*<=-<=*j*<=+<=1.
Let's define the sharpness of matrix *A* as the number of ones in it.
Given integer *x*, your task is to find the smallest positive integer *n* such that there exists a clear symmetrical matrix *A* with side *n* and sharpness *x*.
Input Specification:
The only line contains a single integer *x* (1<=≤<=*x*<=≤<=100) — the required sharpness of the matrix.
Output Specification:
Print a single number — the sought value of *n*.
Demo Input:
['4\n', '9\n']
Demo Output:
['3\n', '5\n']
Note:
The figure below shows the matrices that correspond to the samples: | ```python
from math import ceil,sqrt
x = int(input())
print(ceil(sqrt(2*x)))
``` | 0 |
|
142 | C | Help Caretaker | PROGRAMMING | 2,300 | [
"brute force",
"dp"
] | null | null | Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for the agricultural equipment in the warehouse.
He's got problems with some particularly large piece of equipment, which is, of course, turboplows. The problem is that when a turboplow is stored, it takes up not some simply rectangular space. It takes up a T-shaped space like on one of the four pictures below (here character "#" stands for the space occupied by the turboplow and character "." stands for the free space):
Simon faced a quite natural challenge: placing in the given *n*<=×<=*m* cells warehouse the maximum number of turboplows. As one stores the turboplows, he can rotate them in any manner (so that they take up the space like on one of the four pictures above). However, two turboplows cannot "overlap", that is, they cannot share the same cell in the warehouse.
Simon feels that he alone cannot find the optimal way of positioning the plugs in the warehouse that would maximize their quantity. Can you help him? | The only line contains two space-separated integers *n* and *m* — the sizes of the warehouse (1<=≤<=*n*,<=*m*<=≤<=9). | In the first line print the maximum number of turboplows that can be positioned in the warehouse. In each of the next *n* lines print *m* characters. Use "." (dot) to mark empty space and use successive capital Latin letters ("A" for the first turboplow, "B" for the second one and so on until you reach the number of turboplows in your scheme) to mark place for the corresponding turboplows considering that they are positioned in the optimal manner in the warehouse. The order in which you number places for the turboplows does not matter. If there are several optimal solutions for a warehouse of the given size, print any of them. | [
"3 3\n",
"5 6\n",
"2 2\n"
] | [
"1\nAAA\n.A.\n.A.\n",
"4\nA..C..\nAAAC..\nABCCCD\n.B.DDD\nBBB..D\n",
"0\n..\n..\n"
] | none | 1,500 | [
{
"input": "3 3",
"output": "1\nAAA\n.A.\n.A."
},
{
"input": "5 6",
"output": "4\nA..C..\nAAAC..\nABCCCD\n.B.DDD\nBBB..D"
},
{
"input": "2 2",
"output": "0\n..\n.."
},
{
"input": "4 2",
"output": "0\n..\n..\n..\n.."
},
{
"input": "3 4",
"output": "1\nA...\nAAA.\nA..."
},
{
"input": "5 3",
"output": "2\nAAA\n.A.\n.AB\nBBB\n..B"
},
{
"input": "4 4",
"output": "2\nAAA.\n.AB.\n.AB.\n.BBB"
},
{
"input": "3 6",
"output": "2\nA..B..\nAAAB..\nA.BBB."
},
{
"input": "5 4",
"output": "2\nAAA.\n.AB.\n.AB.\n.BBB\n...."
},
{
"input": "5 5",
"output": "4\nAAA.B\n.ABBB\nCA.DB\nCCCD.\nC.DDD"
},
{
"input": "1 1",
"output": "0\n."
},
{
"input": "1 2",
"output": "0\n.."
},
{
"input": "2 1",
"output": "0\n.\n."
},
{
"input": "1 3",
"output": "0\n..."
},
{
"input": "3 1",
"output": "0\n.\n.\n."
},
{
"input": "1 4",
"output": "0\n...."
},
{
"input": "4 1",
"output": "0\n.\n.\n.\n."
},
{
"input": "1 5",
"output": "0\n....."
},
{
"input": "5 1",
"output": "0\n.\n.\n.\n.\n."
},
{
"input": "1 6",
"output": "0\n......"
},
{
"input": "2 3",
"output": "0\n...\n..."
},
{
"input": "3 2",
"output": "0\n..\n..\n.."
},
{
"input": "6 1",
"output": "0\n.\n.\n.\n.\n.\n."
},
{
"input": "1 7",
"output": "0\n......."
},
{
"input": "7 1",
"output": "0\n.\n.\n.\n.\n.\n.\n."
},
{
"input": "1 8",
"output": "0\n........"
},
{
"input": "2 4",
"output": "0\n....\n...."
},
{
"input": "8 1",
"output": "0\n.\n.\n.\n.\n.\n.\n.\n."
},
{
"input": "1 9",
"output": "0\n........."
},
{
"input": "9 1",
"output": "0\n.\n.\n.\n.\n.\n.\n.\n.\n."
},
{
"input": "2 5",
"output": "0\n.....\n....."
},
{
"input": "5 2",
"output": "0\n..\n..\n..\n..\n.."
},
{
"input": "2 6",
"output": "0\n......\n......"
},
{
"input": "4 3",
"output": "1\nAAA\n.A.\n.A.\n..."
},
{
"input": "6 2",
"output": "0\n..\n..\n..\n..\n..\n.."
},
{
"input": "2 7",
"output": "0\n.......\n......."
},
{
"input": "7 2",
"output": "0\n..\n..\n..\n..\n..\n..\n.."
},
{
"input": "3 5",
"output": "2\nA..B.\nAAAB.\nA.BBB"
},
{
"input": "2 8",
"output": "0\n........\n........"
},
{
"input": "8 2",
"output": "0\n..\n..\n..\n..\n..\n..\n..\n.."
},
{
"input": "2 9",
"output": "0\n.........\n........."
},
{
"input": "6 3",
"output": "2\nAAA\n.A.\n.AB\nBBB\n..B\n..."
},
{
"input": "9 2",
"output": "0\n..\n..\n..\n..\n..\n..\n..\n..\n.."
},
{
"input": "4 5",
"output": "2\nA....\nAAAB.\nABBB.\n...B."
},
{
"input": "3 7",
"output": "3\nA..B..C\nAAABCCC\nA.BBB.C"
},
{
"input": "7 3",
"output": "3\nAAA\n.A.\n.AB\nBBB\n.CB\n.C.\nCCC"
},
{
"input": "3 8",
"output": "3\nA..B..C.\nAAABCCC.\nA.BBB.C."
},
{
"input": "4 6",
"output": "3\nA..CCC\nAAABC.\nABBBC.\n...B.."
},
{
"input": "6 4",
"output": "3\nAAA.\n.AB.\n.AB.\nCBBB\nCCC.\nC..."
},
{
"input": "8 3",
"output": "3\nAAA\n.A.\n.AB\nBBB\n.CB\n.C.\nCCC\n..."
},
{
"input": "3 9",
"output": "4\nA..BCCCD.\nAAAB.C.D.\nA.BBBCDDD"
},
{
"input": "9 3",
"output": "4\nAAA\n.A.\n.AB\nBBB\nC.B\nCCC\nC.D\nDDD\n..D"
},
{
"input": "4 7",
"output": "4\nA..CCC.\nAAABCD.\nABBBCD.\n...BDDD"
},
{
"input": "7 4",
"output": "4\nAAA.\n.AB.\n.AB.\nCBBB\nCCCD\nCDDD\n...D"
},
{
"input": "6 5",
"output": "4\nAAA.B\n.ABBB\n.AC.B\nCCCD.\n..CD.\n..DDD"
},
{
"input": "4 8",
"output": "4\nA..CCC..\nAAABCD..\nABBBCD..\n...BDDD."
},
{
"input": "8 4",
"output": "4\nAAA.\n.AB.\n.AB.\nCBBB\nCCCD\nCDDD\n...D\n...."
},
{
"input": "5 7",
"output": "5\nA..C..E\nAAACEEE\nABCCCDE\n.B.DDD.\nBBB..D."
},
{
"input": "7 5",
"output": "5\nAAA.B\n.ABBB\n.AC.B\nCCCD.\n.ECD.\n.EDDD\nEEE.."
},
{
"input": "4 9",
"output": "5\nA..CCCE..\nAAABCDEEE\nABBBCDE..\n...BDDD.."
},
{
"input": "6 6",
"output": "5\nAAA.B.\n.ABBB.\n.A.CB.\nDCCCE.\nDDDCE.\nD..EEE"
},
{
"input": "9 4",
"output": "5\nAAA.\n.AB.\n.AB.\nCBBB\nCCCD\nCDDD\nEEED\n.E..\n.E.."
},
{
"input": "5 8",
"output": "6\nA.CCC.E.\nAAACEEE.\nAB.CDFE.\n.BDDDFFF\nBBB.DF.."
},
{
"input": "8 5",
"output": "6\nAAA.B\n.ABBB\nCA.DB\nCCCD.\nCEDDD\n.EFFF\nEEEF.\n...F."
},
{
"input": "6 7",
"output": "6\nA..C..E\nAAACEEE\nABCCCFE\n.B.D.F.\nBBBDFFF\n..DDD.."
},
{
"input": "7 6",
"output": "6\nAAA.B.\n.ABBB.\n.AC.BD\nCCCDDD\n.EC.FD\n.EFFF.\nEEE.F."
},
{
"input": "5 9",
"output": "7\nA.CCC.GGG\nAAACEEEG.\nAB.CDEFG.\n.BDDDEF..\nBBB.DFFF."
},
{
"input": "9 5",
"output": "7\nAAA.B\n.ABBB\nCA.DB\nCCCD.\nCEDDD\n.EEEF\nGEFFF\nGGG.F\nG...."
},
{
"input": "6 8",
"output": "7\nA..C.FFF\nAAAC.EF.\nABCCCEF.\n.B.DEEEG\nBBBD.GGG\n..DDD..G"
},
{
"input": "8 6",
"output": "7\nAAA.B.\n.ABBB.\n.AC.BD\nCCCDDD\n..CE.D\nFEEEG.\nFFFEG.\nF..GGG"
},
{
"input": "7 7",
"output": "8\nAAABCCC\n.A.B.C.\nDABBBCE\nDDDFEEE\nDG.F.HE\n.GFFFH.\nGGG.HHH"
},
{
"input": "6 9",
"output": "8\nA..CEEE.G\nAAAC.EGGG\nABCCCEF.G\n.B.DFFFH.\nBBBD..FH.\n..DDD.HHH"
},
{
"input": "9 6",
"output": "8\nAAA.B.\n.ABBB.\n.AC.BD\nCCCDDD\nE.CF.D\nEEEF..\nEGFFFH\n.G.HHH\nGGG..H"
},
{
"input": "7 8",
"output": "9\nA.DDD..H\nAAADFHHH\nA.BDFFFH\nBBBEFIII\n.CBE.GI.\n.CEEEGI.\nCCC.GGG."
},
{
"input": "8 7",
"output": "9\nAAAB..C\n.A.BCCC\nDABBBEC\nDDDEEE.\nDFFF.EG\n.HFIGGG\n.HFIIIG\nHHHI..."
},
{
"input": "7 9",
"output": "10\nA..DFFF.H\nAAAD.FHHH\nABDDDFI.H\n.B.EEEIII\nBBBCEGI.J\n.CCCEGJJJ\n...CGGG.J"
},
{
"input": "9 7",
"output": "10\nAAA.B..\n.ABBBC.\n.AD.BC.\nDDDECCC\nF.DEEEG\nFFFEGGG\nFHIIIJG\n.H.I.J.\nHHHIJJJ"
},
{
"input": "8 8",
"output": "10\nAAA.BCCC\n.ABBBDC.\nEA.FBDC.\nEEEFDDDG\nEHFFFGGG\n.HIII.JG\nHHHIJJJ.\n...I..J."
},
{
"input": "8 9",
"output": "12\nA.EEE.JJJ\nAAAEHHHJ.\nAB.EFHKJ.\n.BFFFHKKK\nBBBDFIK..\nCDDDGIIIL\nCCCDGILLL\nC..GGG..L"
},
{
"input": "9 8",
"output": "12\nAAA.BCCC\n.ABBBDC.\nEA.FBDC.\nEEEFDDDG\nEHFFFGGG\n.HHHIIIG\nJHKKKIL.\nJJJK.IL.\nJ..K.LLL"
},
{
"input": "9 9",
"output": "13\nAAA.BCCC.\n.ABBB.CD.\n.AE.BFCD.\nEEEFFFDDD\nG.E.HFIII\nGGGJHHHI.\nGK.JHL.IM\n.KJJJLMMM\nKKK.LLL.M"
}
] | 1,514,845,405 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 154 | 5,632,000 | r={}
r[(1,1)]='''0
.
'''
r[(1,2)]='''0
..
'''
r[(1,3)]='''0
...
'''
r[(1,4)]='''0
....
'''
r[(1,5)]='''0
.....
'''
r[(1,6)]='''0
......
'''
r[(1,7)]='''0
.......
'''
r[(1,8)]='''0
........
'''
r[(1,9)]='''0
.........
'''
r[(2,2)]='''0
..
..
'''
r[(2,3)]='''0
...
...
'''
r[(2,4)]='''0
....
....
'''
r[(2,5)]='''0
.....
.....
'''
r[(2,6)]='''0
......
......
'''
r[(2,7)]='''0
.......
.......
'''
r[(2,8)]='''0
........
........
'''
r[(2,9)]='''0
.........
.........
'''
r[(3,3)]='''1
.A.
.A.
AAA
'''
r[(3,4)]='''1
.A..
.A..
AAA.
'''
r[(3,5)]='''2
BBBA.
.B.A.
.BAAA
'''
r[(3,6)]='''2
.B.A..
.B.AAA
BBBA..
'''
r[(3,7)]='''3
A.BBBC.
AAAB.C.
A..BCCC
'''
r[(3,8)]='''3
.BCCC.A.
.B.CAAA.
BBBC..A.
'''
r[(3,9)]='''4
BBBDAAA.C
.B.D.ACCC
.BDDDA..C
'''
r[(4,4)]='''2
BBB.
.BA.
.BA.
.AAA
'''
r[(4,5)]='''2
....A
.BAAA
.BBBA
.B...
'''
r[(4,6)]='''3
..A...
.CAAAB
.CABBB
CCC..B
'''
r[(4,7)]='''4
...ACCC
BAAADC.
BBBADC.
B..DDD.
'''
r[(4,8)]='''4
BBB.A...
.BD.AAAC
.BD.ACCC
.DDD...C
'''
r[(4,9)]='''5
...ACCC..
DAAAECBBB
DDDAEC.B.
D..EEE.B.
'''
r[(5,5)]='''4
D.BBB
DDDB.
DA.BC
.ACCC
AAA.C
'''
r[(5,6)]='''4
A..DDD
AAA.D.
ABBBDC
..BCCC
..B..C
'''
r[(5,7)]='''5
.A.EEE.
.AAAEB.
CA.DEB.
CCCDBBB
C.DDD..
'''
r[(5,8)]='''6
A..D.FFF
AAADDDF.
AB.DECF.
.BEEECCC
BBB.EC..
'''
r[(5,9)]='''7
..CAAAB..
CCC.AGBBB
F.CDAGBE.
FFFDGGGE.
F.DDD.EEE
'''
r[(6,6)]='''5
AAA...
.ABCCC
.AB.C.
DBBBCE
DDDEEE
D....E
'''
r[(6,7)]='''6
..A...B
AAA.BBB
E.ADDDB
EEECDF.
ECCCDF.
...CFFF
'''
r[(6,8)]='''7
F.DDD..G
FFFDBGGG
F.ADBBBG
AAAEBC..
..AE.CCC
..EEEC..
'''
r[(6,9)]='''8
F..AAAGGG
FFFCA.BG.
FCCCA.BG.
HHHCDBBBE
.HDDD.EEE
.H..D...E
'''
r[(7,7)]='''8
H..AEEE
HHHA.E.
HDAAAEC
.DDDCCC
BDFFFGC
BBBF.G.
B..FGGG
'''
r[(7,8)]='''9
F.III..G
FFFIAGGG
FH.IAAAG
.HHHADDD
EHBBBCD.
EEEB.CD.
E..BCCC.
'''
r[(7,9)]='''10
...BJJJ.A
.BBBGJAAA
E..BGJC.A
EEEGGGCCC
EHDDDFC.I
.H.D.FIII
HHHDFFF.I
'''
r[(8,8)]='''10
A..BBB..
AAAJBIII
AH.JB.I.
.HJJJGI.
HHHC.GGG
ECCCDG.F
EEECDFFF
E..DDD.F
'''
r[(8,9)]='''12
DDDLLL..H
.DC.LGHHH
.DC.LGGGH
ECCCBGKKK
EEEABBBK.
EI.ABJ.KF
.IAAAJFFF
III.JJJ.F
'''
r[(9,9)]='''13
K.DDDEMMM
KKKD.E.M.
KA.DEEEMF
.AAALGFFF
HALLLGGGF
HHHBLGCCC
HI.B..JC.
.IBBB.JC.
III..JJJ.
'''
n,m=map(int,input().split())
if n<m:
print(r[(n,m)]),
else:
s=r[(m,n)].strip().split('\n')
print(s[0])
s=s[1:]
s=zip(*s)
for t in s:
print(''.join(t))
| Title: Help Caretaker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for the agricultural equipment in the warehouse.
He's got problems with some particularly large piece of equipment, which is, of course, turboplows. The problem is that when a turboplow is stored, it takes up not some simply rectangular space. It takes up a T-shaped space like on one of the four pictures below (here character "#" stands for the space occupied by the turboplow and character "." stands for the free space):
Simon faced a quite natural challenge: placing in the given *n*<=×<=*m* cells warehouse the maximum number of turboplows. As one stores the turboplows, he can rotate them in any manner (so that they take up the space like on one of the four pictures above). However, two turboplows cannot "overlap", that is, they cannot share the same cell in the warehouse.
Simon feels that he alone cannot find the optimal way of positioning the plugs in the warehouse that would maximize their quantity. Can you help him?
Input Specification:
The only line contains two space-separated integers *n* and *m* — the sizes of the warehouse (1<=≤<=*n*,<=*m*<=≤<=9).
Output Specification:
In the first line print the maximum number of turboplows that can be positioned in the warehouse. In each of the next *n* lines print *m* characters. Use "." (dot) to mark empty space and use successive capital Latin letters ("A" for the first turboplow, "B" for the second one and so on until you reach the number of turboplows in your scheme) to mark place for the corresponding turboplows considering that they are positioned in the optimal manner in the warehouse. The order in which you number places for the turboplows does not matter. If there are several optimal solutions for a warehouse of the given size, print any of them.
Demo Input:
['3 3\n', '5 6\n', '2 2\n']
Demo Output:
['1\nAAA\n.A.\n.A.\n', '4\nA..C..\nAAAC..\nABCCCD\n.B.DDD\nBBB..D\n', '0\n..\n..\n']
Note:
none | ```python
r={}
r[(1,1)]='''0
.
'''
r[(1,2)]='''0
..
'''
r[(1,3)]='''0
...
'''
r[(1,4)]='''0
....
'''
r[(1,5)]='''0
.....
'''
r[(1,6)]='''0
......
'''
r[(1,7)]='''0
.......
'''
r[(1,8)]='''0
........
'''
r[(1,9)]='''0
.........
'''
r[(2,2)]='''0
..
..
'''
r[(2,3)]='''0
...
...
'''
r[(2,4)]='''0
....
....
'''
r[(2,5)]='''0
.....
.....
'''
r[(2,6)]='''0
......
......
'''
r[(2,7)]='''0
.......
.......
'''
r[(2,8)]='''0
........
........
'''
r[(2,9)]='''0
.........
.........
'''
r[(3,3)]='''1
.A.
.A.
AAA
'''
r[(3,4)]='''1
.A..
.A..
AAA.
'''
r[(3,5)]='''2
BBBA.
.B.A.
.BAAA
'''
r[(3,6)]='''2
.B.A..
.B.AAA
BBBA..
'''
r[(3,7)]='''3
A.BBBC.
AAAB.C.
A..BCCC
'''
r[(3,8)]='''3
.BCCC.A.
.B.CAAA.
BBBC..A.
'''
r[(3,9)]='''4
BBBDAAA.C
.B.D.ACCC
.BDDDA..C
'''
r[(4,4)]='''2
BBB.
.BA.
.BA.
.AAA
'''
r[(4,5)]='''2
....A
.BAAA
.BBBA
.B...
'''
r[(4,6)]='''3
..A...
.CAAAB
.CABBB
CCC..B
'''
r[(4,7)]='''4
...ACCC
BAAADC.
BBBADC.
B..DDD.
'''
r[(4,8)]='''4
BBB.A...
.BD.AAAC
.BD.ACCC
.DDD...C
'''
r[(4,9)]='''5
...ACCC..
DAAAECBBB
DDDAEC.B.
D..EEE.B.
'''
r[(5,5)]='''4
D.BBB
DDDB.
DA.BC
.ACCC
AAA.C
'''
r[(5,6)]='''4
A..DDD
AAA.D.
ABBBDC
..BCCC
..B..C
'''
r[(5,7)]='''5
.A.EEE.
.AAAEB.
CA.DEB.
CCCDBBB
C.DDD..
'''
r[(5,8)]='''6
A..D.FFF
AAADDDF.
AB.DECF.
.BEEECCC
BBB.EC..
'''
r[(5,9)]='''7
..CAAAB..
CCC.AGBBB
F.CDAGBE.
FFFDGGGE.
F.DDD.EEE
'''
r[(6,6)]='''5
AAA...
.ABCCC
.AB.C.
DBBBCE
DDDEEE
D....E
'''
r[(6,7)]='''6
..A...B
AAA.BBB
E.ADDDB
EEECDF.
ECCCDF.
...CFFF
'''
r[(6,8)]='''7
F.DDD..G
FFFDBGGG
F.ADBBBG
AAAEBC..
..AE.CCC
..EEEC..
'''
r[(6,9)]='''8
F..AAAGGG
FFFCA.BG.
FCCCA.BG.
HHHCDBBBE
.HDDD.EEE
.H..D...E
'''
r[(7,7)]='''8
H..AEEE
HHHA.E.
HDAAAEC
.DDDCCC
BDFFFGC
BBBF.G.
B..FGGG
'''
r[(7,8)]='''9
F.III..G
FFFIAGGG
FH.IAAAG
.HHHADDD
EHBBBCD.
EEEB.CD.
E..BCCC.
'''
r[(7,9)]='''10
...BJJJ.A
.BBBGJAAA
E..BGJC.A
EEEGGGCCC
EHDDDFC.I
.H.D.FIII
HHHDFFF.I
'''
r[(8,8)]='''10
A..BBB..
AAAJBIII
AH.JB.I.
.HJJJGI.
HHHC.GGG
ECCCDG.F
EEECDFFF
E..DDD.F
'''
r[(8,9)]='''12
DDDLLL..H
.DC.LGHHH
.DC.LGGGH
ECCCBGKKK
EEEABBBK.
EI.ABJ.KF
.IAAAJFFF
III.JJJ.F
'''
r[(9,9)]='''13
K.DDDEMMM
KKKD.E.M.
KA.DEEEMF
.AAALGFFF
HALLLGGGF
HHHBLGCCC
HI.B..JC.
.IBBB.JC.
III..JJJ.
'''
n,m=map(int,input().split())
if n<m:
print(r[(n,m)]),
else:
s=r[(m,n)].strip().split('\n')
print(s[0])
s=s[1:]
s=zip(*s)
for t in s:
print(''.join(t))
``` | 3 |
|
757 | A | Gotta Catch Em' All! | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.
Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.
Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?
Note: uppercase and lowercase letters are considered different. | Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*.
The string *s* contains lowercase and uppercase English letters, i.e. . | Output a single integer, the answer to the problem. | [
"Bulbbasaur\n",
"F\n",
"aBddulbasaurrgndgbualdBdsagaurrgndbb\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur". | 500 | [
{
"input": "Bulbbasaur",
"output": "1"
},
{
"input": "F",
"output": "0"
},
{
"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb",
"output": "2"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr",
"output": "5"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuussssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "BBBBBBBBBBssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrr",
"output": "0"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrr",
"output": "10"
},
{
"input": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBbbbbbbbbbbbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuullllllllllllllllllllssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"output": "20"
},
{
"input": "CeSlSwec",
"output": "0"
},
{
"input": "PnMrWPBGzVcmRcO",
"output": "0"
},
{
"input": "hHPWBQeEmCuhdCnzrqYtuFtwxokGhdGkFtsFICVqYfJeUrSBtSxEbzMCblOgqOvjXURhSKivPcseqgiNuUgIboEYMvVeRBbpzCGCfVydDvZNFGSFidwUtNbmPSfSYdMNmHgchIsiVswzFsGQewlMVEzicOagpWMdCWrCdPmexfnM",
"output": "0"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbbbuuuuuuuuuuuullllllllllllssssssssssssaaaaaaaaaaaarrrrrrrrrrrrZBphUC",
"output": "6"
},
{
"input": "bulsar",
"output": "0"
},
{
"input": "Bblsar",
"output": "0"
},
{
"input": "Bbusar",
"output": "0"
},
{
"input": "Bbular",
"output": "0"
},
{
"input": "Bbulsr",
"output": "0"
},
{
"input": "Bbulsa",
"output": "0"
},
{
"input": "Bbulsar",
"output": "0"
},
{
"input": "Bbulsar",
"output": "0"
},
{
"input": "CaQprCjTiQACZjUJjSmMHVTDorSUugvTtksEjptVzNLhClWaVVWszIixBlqFkvjDmbRjarQoUWhXHoCgYNNjvEgRTgKpbdEMFsmqcTyvJzupKgYiYMtrZWXIAGVhmDURtddbBZIMgIgXqQUmXpssLSaVCDGZDHimNthwiAWabjtcraAQugMCpBPQZbBGZyqUZmzDVSvJZmDWfZEUHGJVtiJANAIbvjTxtvvTbjWRpNQZlxAqpLCLRVwYWqLaHOTvzgeNGdxiBwsAVKKsewXMTwZUUfxYwrwsiaRBwEdvDDoPsQUtinvajBoRzLBUuQekhjsfDAOQzIABSVPitRuhvvqeAahsSELTGbCPh",
"output": "2"
},
{
"input": "Bulbasaur",
"output": "1"
},
{
"input": "BulbasaurBulbasaur",
"output": "2"
},
{
"input": "Bulbbasar",
"output": "0"
},
{
"input": "Bulbasur",
"output": "0"
},
{
"input": "Bulbsaur",
"output": "0"
},
{
"input": "BulbsurBulbsurBulbsurBulbsur",
"output": "0"
},
{
"input": "Blbbasar",
"output": "0"
},
{
"input": "Bulbasar",
"output": "0"
},
{
"input": "BBullllbbaassaauurr",
"output": "1"
},
{
"input": "BulbasaurBulbasar",
"output": "1"
},
{
"input": "BulbasaurBulbsaur",
"output": "1"
},
{
"input": "Bubasaur",
"output": "0"
},
{
"input": "ulbasaurulbasaur",
"output": "0"
},
{
"input": "Bulbasr",
"output": "0"
},
{
"input": "BBBuuulllbbbaaasssaaauuurrr",
"output": "3"
},
{
"input": "BBuuuullbbaaaassrr",
"output": "2"
},
{
"input": "BBBBBBBuuuuuuuullllllllllllbbbbaaaaaassssssssssssssssaaaaauuuuuuuuuuuuurrrrrrrrrrrrrrrr",
"output": "4"
},
{
"input": "BBuullbbaassaarr",
"output": "1"
},
{
"input": "Bulbasau",
"output": "0"
},
{
"input": "BBuullbbaassaauurr",
"output": "2"
},
{
"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasauBulbasau",
"output": "0"
},
{
"input": "Blbasaur",
"output": "0"
},
{
"input": "BulbasaurBulbasaurd",
"output": "2"
},
{
"input": "ulbasaur",
"output": "0"
},
{
"input": "Bulbaaur",
"output": "0"
},
{
"input": "BBuuuullbbbbbbbbbbbbbbbaassrr",
"output": "1"
},
{
"input": "Bulbasua",
"output": "0"
},
{
"input": "Bubbasaur",
"output": "0"
},
{
"input": "BulbasauBulbasauBulbasauBulbasauBulbasauBulbasaurrr",
"output": "3"
},
{
"input": "BulbasaurBubasaur",
"output": "1"
},
{
"input": "Baab",
"output": "0"
},
{
"input": "BulbasaurBulbasau",
"output": "1"
},
{
"input": "Bulbasauu",
"output": "0"
},
{
"input": "BulbasauBulbasau",
"output": "0"
},
{
"input": "BBBBBBBBBBB",
"output": "0"
},
{
"input": "Bulbbasau",
"output": "0"
},
{
"input": "BulbbasaurBulbbasar",
"output": "1"
},
{
"input": "Bulaaaasaur",
"output": "0"
},
{
"input": "BulbasaurBulbasauBulbasauBulbasau",
"output": "1"
}
] | 1,683,914,462 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 307,200 | from sys import stdin
from collections import Counter
rd = stdin.readline
s = rd().strip()
string = list('Bulbasaur')
s = Counter(s)
minl = 10**6
for i in string:
if s[i] < minl: minl = s[i]
print(minl)
| Title: Gotta Catch Em' All!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.
Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.
Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?
Note: uppercase and lowercase letters are considered different.
Input Specification:
Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*.
The string *s* contains lowercase and uppercase English letters, i.e. .
Output Specification:
Output a single integer, the answer to the problem.
Demo Input:
['Bulbbasaur\n', 'F\n', 'aBddulbasaurrgndgbualdBdsagaurrgndbb\n']
Demo Output:
['1\n', '0\n', '2\n']
Note:
In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur". | ```python
from sys import stdin
from collections import Counter
rd = stdin.readline
s = rd().strip()
string = list('Bulbasaur')
s = Counter(s)
minl = 10**6
for i in string:
if s[i] < minl: minl = s[i]
print(minl)
``` | 0 |
|
606 | A | Magic Spheres | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least *x* blue, *y* violet and *z* orange spheres. Can he get them (possible, in multiple actions)? | The first line of the input contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=1<=000<=000) — the number of blue, violet and orange spheres that are in the magician's disposal.
The second line of the input contains three integers, *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=1<=000<=000) — the number of blue, violet and orange spheres that he needs to get. | If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No". | [
"4 4 0\n2 1 2\n",
"5 6 1\n2 7 2\n",
"3 3 3\n2 2 2\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what he needs. | 500 | [
{
"input": "4 4 0\n2 1 2",
"output": "Yes"
},
{
"input": "5 6 1\n2 7 2",
"output": "No"
},
{
"input": "3 3 3\n2 2 2",
"output": "Yes"
},
{
"input": "0 0 0\n0 0 0",
"output": "Yes"
},
{
"input": "0 0 0\n0 0 1",
"output": "No"
},
{
"input": "0 1 0\n0 0 0",
"output": "Yes"
},
{
"input": "1 0 0\n1 0 0",
"output": "Yes"
},
{
"input": "2 2 1\n1 1 2",
"output": "No"
},
{
"input": "1 3 1\n2 1 1",
"output": "Yes"
},
{
"input": "1000000 1000000 1000000\n1000000 1000000 1000000",
"output": "Yes"
},
{
"input": "1000000 500000 500000\n0 750000 750000",
"output": "Yes"
},
{
"input": "500000 1000000 500000\n750001 0 750000",
"output": "No"
},
{
"input": "499999 500000 1000000\n750000 750000 0",
"output": "No"
},
{
"input": "500000 500000 0\n0 0 500000",
"output": "Yes"
},
{
"input": "0 500001 499999\n500000 0 0",
"output": "No"
},
{
"input": "1000000 500000 1000000\n500000 1000000 500000",
"output": "Yes"
},
{
"input": "1000000 1000000 499999\n500000 500000 1000000",
"output": "No"
},
{
"input": "500000 1000000 1000000\n1000000 500001 500000",
"output": "No"
},
{
"input": "1000000 500000 500000\n0 1000000 500000",
"output": "Yes"
},
{
"input": "500000 500000 1000000\n500001 1000000 0",
"output": "No"
},
{
"input": "500000 999999 500000\n1000000 0 500000",
"output": "No"
},
{
"input": "4 0 3\n2 2 1",
"output": "Yes"
},
{
"input": "0 2 4\n2 0 2",
"output": "Yes"
},
{
"input": "3 1 0\n1 1 1",
"output": "Yes"
},
{
"input": "4 4 1\n1 3 2",
"output": "Yes"
},
{
"input": "1 2 4\n2 1 3",
"output": "No"
},
{
"input": "1 1 0\n0 0 1",
"output": "No"
},
{
"input": "4 0 0\n0 1 1",
"output": "Yes"
},
{
"input": "0 3 0\n1 0 1",
"output": "No"
},
{
"input": "0 0 3\n1 0 1",
"output": "Yes"
},
{
"input": "1 12 1\n4 0 4",
"output": "Yes"
},
{
"input": "4 0 4\n1 2 1",
"output": "Yes"
},
{
"input": "4 4 0\n1 1 3",
"output": "No"
},
{
"input": "0 9 0\n2 2 2",
"output": "No"
},
{
"input": "0 10 0\n2 2 2",
"output": "Yes"
},
{
"input": "9 0 9\n0 8 0",
"output": "Yes"
},
{
"input": "0 9 9\n9 0 0",
"output": "No"
},
{
"input": "9 10 0\n0 0 9",
"output": "Yes"
},
{
"input": "10 0 9\n0 10 0",
"output": "No"
},
{
"input": "0 10 10\n10 0 0",
"output": "Yes"
},
{
"input": "10 10 0\n0 0 11",
"output": "No"
},
{
"input": "307075 152060 414033\n381653 222949 123101",
"output": "No"
},
{
"input": "569950 228830 153718\n162186 357079 229352",
"output": "No"
},
{
"input": "149416 303568 749016\n238307 493997 190377",
"output": "No"
},
{
"input": "438332 298094 225324\n194220 400244 245231",
"output": "No"
},
{
"input": "293792 300060 511272\n400687 382150 133304",
"output": "No"
},
{
"input": "295449 518151 368838\n382897 137148 471892",
"output": "No"
},
{
"input": "191789 291147 691092\n324321 416045 176232",
"output": "Yes"
},
{
"input": "286845 704749 266526\n392296 104421 461239",
"output": "Yes"
},
{
"input": "135522 188282 377041\n245719 212473 108265",
"output": "Yes"
},
{
"input": "404239 359124 133292\n180069 184791 332544",
"output": "No"
},
{
"input": "191906 624432 244408\n340002 367217 205432",
"output": "No"
},
{
"input": "275980 429361 101824\n274288 302579 166062",
"output": "No"
},
{
"input": "136092 364927 395302\n149173 343146 390922",
"output": "No"
},
{
"input": "613852 334661 146012\n363786 326286 275233",
"output": "No"
},
{
"input": "348369 104625 525203\n285621 215396 366411",
"output": "No"
},
{
"input": "225307 153572 114545\n154753 153282 149967",
"output": "Yes"
},
{
"input": "438576 124465 629784\n375118 276028 390116",
"output": "Yes"
},
{
"input": "447521 327510 158732\n395759 178458 259139",
"output": "Yes"
},
{
"input": "8 5 5\n5 5 5",
"output": "Yes"
},
{
"input": "100 100 100\n1 1 1",
"output": "Yes"
},
{
"input": "100 100 100\n0 0 0",
"output": "Yes"
},
{
"input": "3 2 3\n2 3 2",
"output": "No"
},
{
"input": "5 4 3\n2 2 2",
"output": "Yes"
},
{
"input": "14 9 8\n12 5 10",
"output": "Yes"
},
{
"input": "10 10 10\n1 1 1",
"output": "Yes"
},
{
"input": "6 3 3\n3 3 3",
"output": "Yes"
},
{
"input": "10 0 4\n2 4 2",
"output": "Yes"
},
{
"input": "100 100 100\n2 2 2",
"output": "Yes"
},
{
"input": "4 6 0\n2 1 2",
"output": "Yes"
},
{
"input": "4 6 3\n4 2 3",
"output": "Yes"
},
{
"input": "5 5 5\n1 1 1",
"output": "Yes"
},
{
"input": "41 17 34\n0 19 24",
"output": "Yes"
},
{
"input": "8 8 8\n3 3 3",
"output": "Yes"
},
{
"input": "7 7 1\n1 1 2",
"output": "Yes"
},
{
"input": "6 6 0\n2 2 2",
"output": "Yes"
},
{
"input": "5 5 5\n2 2 2",
"output": "Yes"
},
{
"input": "400 400 400\n1 1 1",
"output": "Yes"
},
{
"input": "4 4 4\n2 2 2",
"output": "Yes"
}
] | 1,458,370,813 | 2,147,483,647 | Python 3 | OK | TESTS | 79 | 62 | 5,017,600 | '''
二维数组转置,排序,lambda表达式函数
'''
mylist = [list(map(int, input().split())),list(map(int, input().split()))]
mylist = list(map(list,zip(*mylist)))
for my in mylist:
if my[0]<my[1]:
my[1]-=my[0]
my[0]=0
else:
my[0]-=my[1]
my[1]=0
# for i in range(len(mylist)):
# if mylist[i][0]<mylist[i][1]:
# mylist[i][1]-=mylist[i][0]
# mylist[i][0]=0
# else:
# mylist[i][0]-=mylist[i][1]
# mylist[i][1]=0
mylist.sort(key=lambda my:my[0], reverse=True)
i=0 #初始剩余资源
j=0 #目标资源量
while j<3 and i<3:
while mylist[j][1]>0 and i<3:
if mylist[i][0]<=mylist[j][1]*2:
mylist[j][1]-=mylist[i][0]//2
i+=1
else:
mylist[i][0]-=mylist[j][1]*2
mylist[j][1]=0
j+=1
if mylist[2][1]+mylist[1][1]+mylist[0][1]>0:
print("No")
else:
print("Yes")
| Title: Magic Spheres
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least *x* blue, *y* violet and *z* orange spheres. Can he get them (possible, in multiple actions)?
Input Specification:
The first line of the input contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=1<=000<=000) — the number of blue, violet and orange spheres that are in the magician's disposal.
The second line of the input contains three integers, *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=1<=000<=000) — the number of blue, violet and orange spheres that he needs to get.
Output Specification:
If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No".
Demo Input:
['4 4 0\n2 1 2\n', '5 6 1\n2 7 2\n', '3 3 3\n2 2 2\n']
Demo Output:
['Yes\n', 'No\n', 'Yes\n']
Note:
In the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what he needs. | ```python
'''
二维数组转置,排序,lambda表达式函数
'''
mylist = [list(map(int, input().split())),list(map(int, input().split()))]
mylist = list(map(list,zip(*mylist)))
for my in mylist:
if my[0]<my[1]:
my[1]-=my[0]
my[0]=0
else:
my[0]-=my[1]
my[1]=0
# for i in range(len(mylist)):
# if mylist[i][0]<mylist[i][1]:
# mylist[i][1]-=mylist[i][0]
# mylist[i][0]=0
# else:
# mylist[i][0]-=mylist[i][1]
# mylist[i][1]=0
mylist.sort(key=lambda my:my[0], reverse=True)
i=0 #初始剩余资源
j=0 #目标资源量
while j<3 and i<3:
while mylist[j][1]>0 and i<3:
if mylist[i][0]<=mylist[j][1]*2:
mylist[j][1]-=mylist[i][0]//2
i+=1
else:
mylist[i][0]-=mylist[j][1]*2
mylist[j][1]=0
j+=1
if mylist[2][1]+mylist[1][1]+mylist[0][1]>0:
print("No")
else:
print("Yes")
``` | 3 |
|
352 | B | Jeff and Periods | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, that *a**i*<==<=*x*). These numbers, sorted in the increasing order, must form an arithmetic progression.
Help Jeff, find all *x* that meet the problem conditions. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces. | In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in the order of increasing *x*. | [
"1\n2\n",
"8\n1 2 1 3 1 2 1 5\n"
] | [
"1\n2 0\n",
"4\n1 2\n2 4\n3 0\n5 0\n"
] | In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | 1,000 | [
{
"input": "1\n2",
"output": "1\n2 0"
},
{
"input": "8\n1 2 1 3 1 2 1 5",
"output": "4\n1 2\n2 4\n3 0\n5 0"
},
{
"input": "3\n1 10 5",
"output": "3\n1 0\n5 0\n10 0"
},
{
"input": "4\n9 9 3 5",
"output": "3\n3 0\n5 0\n9 1"
},
{
"input": "6\n1 2 2 1 1 2",
"output": "0"
},
{
"input": "6\n2 6 3 8 7 2",
"output": "5\n2 5\n3 0\n6 0\n7 0\n8 0"
},
{
"input": "7\n2 1 2 1 2 1 2",
"output": "2\n1 2\n2 2"
},
{
"input": "8\n1 1 1 1 1 1 1 1",
"output": "1\n1 1"
},
{
"input": "9\n2 3 3 3 2 1 2 3 2",
"output": "1\n1 0"
},
{
"input": "10\n3 1 1 1 1 3 1 2 2 1",
"output": "2\n2 1\n3 5"
},
{
"input": "12\n10 9 8 7 7 8 9 10 10 9 8 7",
"output": "0"
}
] | 1,630,036,582 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 154 | 20,172,800 | n=int(input())
a=list(map(int,input().split()))
b=sorted(set(a.copy()));dict={}
for x in b:dict[x]=len(a[:a[a.index(x)+1:].index(x)])+1 if a.count(x)>1 else 0
flag=True;d={}
for x in b:
diff=0;count=0
for y in range(n):
if x==a[y]:
diff=y-a.index(x)
count+=1
if diff-(count-1)*dict[x]!=0:flag=False;break
if flag:
for x,y in dict.items():print(x,y)
else:print(0) | Title: Jeff and Periods
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, that *a**i*<==<=*x*). These numbers, sorted in the increasing order, must form an arithmetic progression.
Help Jeff, find all *x* that meet the problem conditions.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces.
Output Specification:
In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in the order of increasing *x*.
Demo Input:
['1\n2\n', '8\n1 2 1 3 1 2 1 5\n']
Demo Output:
['1\n2 0\n', '4\n1 2\n2 4\n3 0\n5 0\n']
Note:
In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | ```python
n=int(input())
a=list(map(int,input().split()))
b=sorted(set(a.copy()));dict={}
for x in b:dict[x]=len(a[:a[a.index(x)+1:].index(x)])+1 if a.count(x)>1 else 0
flag=True;d={}
for x in b:
diff=0;count=0
for y in range(n):
if x==a[y]:
diff=y-a.index(x)
count+=1
if diff-(count-1)*dict[x]!=0:flag=False;break
if flag:
for x,y in dict.items():print(x,y)
else:print(0)
``` | 0 |
|
676 | C | Vasya and String | PROGRAMMING | 1,500 | [
"binary search",
"dp",
"strings",
"two pointers"
] | null | null | High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than *k* characters of the original string. What is the maximum beauty of the string he can achieve? | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only. | Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters. | [
"4 2\nabba\n",
"8 1\naabaabaa\n"
] | [
"4\n",
"5\n"
] | In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa". | 1,500 | [
{
"input": "4 2\nabba",
"output": "4"
},
{
"input": "8 1\naabaabaa",
"output": "5"
},
{
"input": "1 0\na",
"output": "1"
},
{
"input": "1 1\nb",
"output": "1"
},
{
"input": "1 0\nb",
"output": "1"
},
{
"input": "1 1\na",
"output": "1"
},
{
"input": "10 10\nbbbbbbbbbb",
"output": "10"
},
{
"input": "10 2\nbbbbbbbbbb",
"output": "10"
},
{
"input": "10 1\nbbabbabbba",
"output": "6"
},
{
"input": "10 10\nbbabbbaabb",
"output": "10"
},
{
"input": "10 9\nbabababbba",
"output": "10"
},
{
"input": "10 4\nbababbaaab",
"output": "9"
},
{
"input": "10 10\naabaaabaaa",
"output": "10"
},
{
"input": "10 10\naaaabbbaaa",
"output": "10"
},
{
"input": "10 1\nbaaaaaaaab",
"output": "9"
},
{
"input": "10 5\naaaaabaaaa",
"output": "10"
},
{
"input": "10 4\naaaaaaaaaa",
"output": "10"
},
{
"input": "100 10\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "100"
},
{
"input": "100 7\nbbbbabbbbbaabbbabbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbabbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbab",
"output": "93"
},
{
"input": "100 30\nbbaabaaabbbbbbbbbbaababababbbbbbaabaabbbbbbbbabbbbbabbbbabbbbbbbbaabbbbbbbbbabbbbbabbbbbbbbbaaaaabba",
"output": "100"
},
{
"input": "100 6\nbaababbbaabbabbaaabbabbaabbbbbbbbaabbbabbbbaabbabbbbbabababbbbabbbbbbabbbbbbbbbaaaabbabbbbaabbabaabb",
"output": "34"
},
{
"input": "100 45\naabababbabbbaaabbbbbbaabbbabbaabbbbbabbbbbbbbabbbbbbabbaababbaabbababbbbbbababbbbbaabbbbbbbaaaababab",
"output": "100"
},
{
"input": "100 2\nababaabababaaababbaaaabbaabbbababbbaaabbbbabababbbabababaababaaabaabbbbaaabbbabbbbbabbbbbbbaabbabbba",
"output": "17"
},
{
"input": "100 25\nbabbbaaababaaabbbaabaabaabbbabbabbbbaaaaaaabaaabaaaaaaaaaabaaaabaaabbbaaabaaababaaabaabbbbaaaaaaaaaa",
"output": "80"
},
{
"input": "100 14\naabaaaaabababbabbabaaaabbaaaabaaabbbaaabaaaaaaaabaaaaabbaaaaaaaaabaaaaaaabbaababaaaababbbbbabaaaabaa",
"output": "61"
},
{
"input": "100 8\naaaaabaaaabaabaaaaaaaabaaaabaaaaaaaaaaaaaabaaaaabaaaaaaaaaaaaaaaaabaaaababaabaaaaaaaaaaaaabbabaaaaaa",
"output": "76"
},
{
"input": "100 12\naaaaaaaaaaaaaaaabaaabaaaaaaaaaabbaaaabbabaaaaaaaaaaaaaaaaaaaaabbaaabaaaaaaaaaaaabaaaaaaaabaaaaaaaaaa",
"output": "100"
},
{
"input": "100 65\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "100"
},
{
"input": "10 0\nbbbbbbbbbb",
"output": "10"
},
{
"input": "10 0\nbbbbabbbbb",
"output": "5"
},
{
"input": "10 0\nbbabbbabba",
"output": "3"
},
{
"input": "10 0\nbaabbbbaba",
"output": "4"
},
{
"input": "10 0\naababbbbaa",
"output": "4"
},
{
"input": "10 2\nabbbbbaaba",
"output": "8"
},
{
"input": "10 0\nabbaaabaaa",
"output": "3"
},
{
"input": "10 0\naabbaaabaa",
"output": "3"
},
{
"input": "10 1\naaaaaababa",
"output": "8"
},
{
"input": "10 0\nbaaaaaaaaa",
"output": "9"
},
{
"input": "10 0\naaaaaaaaaa",
"output": "10"
},
{
"input": "100 0\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "100"
},
{
"input": "100 0\nbbbbbbbbbbabbbbaaabbbbbbbbbbbabbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbabbbbbbbbbbbbbab",
"output": "40"
},
{
"input": "100 11\nbaabbbbbababbbbabbbbbbbabbbbbbbbbbbbbbabbbbbbababbbbababbbbaaabbbbabbbbbabbbbbbbbabababbbabbbbbbbabb",
"output": "65"
},
{
"input": "100 8\nbbababbbbbaabbbaaababbbbababababbbbababbabbbabbbbbaabbbabbbababbabbbbabbbabbbbaabbbbabbbaabbbbaaaabb",
"output": "33"
},
{
"input": "100 21\nabbaaaabbbababaabbbababbbbbbbbabbaababababbbabbbaaabbaaabbbbabbabbbabbbabaababbbabbbbbabbbbbbabbbbab",
"output": "65"
},
{
"input": "100 9\nabbbaabaabaaaaaaabbabbbababbaaabbbaaabbaabaaaaabbbbbabbaabaabbbbbaaaaababbaaabbabaabaaabababbaababbb",
"output": "26"
},
{
"input": "100 5\naababababbaaaaaaaabbbabaaaabbabaaaabbaabaaaaabababbabaabaaabaaaaaaaabaababbabbaaabaabbabbaaaaabbabba",
"output": "22"
},
{
"input": "100 9\naababaabaaaaaaaaabbbaabaaaaaaabaaaaaaaaaaaaabaaabaabaabbbbabbaababbabbaaaabbababaabaababaabaaaaaaaaa",
"output": "49"
},
{
"input": "100 6\naaaaabbaaaaaaaaaaabaaaabaaaaaaaaabaaabaaaaaabaaaaaaaaaaabaabaaaabaaaaaaaaaaaaaaabaabbaaaaaaaaaaaaaaa",
"output": "56"
},
{
"input": "100 7\nabaaabaabaabaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaabaaaaaaabbabaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaba",
"output": "86"
},
{
"input": "100 0\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "100"
}
] | 1,613,206,447 | 2,147,483,647 | PyPy 3 | OK | TESTS | 117 | 124 | 2,457,600 | n, m = map(int, input().split())
s = input()
j = 0
ans = 0
d = {"a": 0, "b": 0}
a = 0
for i in s:
d[i] += 1
a +=1
if min(d.values()) > m:
d[s[j]] -= 1
j += 1
else:
ans= max(ans, a - j )
print(ans)
| Title: Vasya and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than *k* characters of the original string. What is the maximum beauty of the string he can achieve?
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only.
Output Specification:
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters.
Demo Input:
['4 2\nabba\n', '8 1\naabaabaa\n']
Demo Output:
['4\n', '5\n']
Note:
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa". | ```python
n, m = map(int, input().split())
s = input()
j = 0
ans = 0
d = {"a": 0, "b": 0}
a = 0
for i in s:
d[i] += 1
a +=1
if min(d.values()) > m:
d[s[j]] -= 1
j += 1
else:
ans= max(ans, a - j )
print(ans)
``` | 3 |
|
961 | E | Tufurama | PROGRAMMING | 1,900 | [
"data structures"
] | null | null | One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused — what if he decides to rewatch the entire series someday and won't be able to find the right episodes to watch? Polycarp now wants to count the number of times he will be forced to search for an episode using some different method.
TV series have *n* seasons (numbered 1 through *n*), the *i*-th season has *a**i* episodes (numbered 1 through *a**i*). Polycarp thinks that if for some pair of integers *x* and *y* (*x*<=<<=*y*) exist both season *x* episode *y* and season *y* episode *x* then one of these search queries will include the wrong results. Help Polycarp to calculate the number of such pairs! | The first line contains one integer *n* (1<=<=≤<=*n*<=<=≤<=<=2·105) — the number of seasons.
The second line contains *n* integers separated by space *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — number of episodes in each season. | Print one integer — the number of pairs *x* and *y* (*x*<=<<=*y*) such that there exist both season *x* episode *y* and season *y* episode *x*. | [
"5\n1 2 3 4 5\n",
"3\n8 12 7\n",
"3\n3 2 1\n"
] | [
"0\n",
"3\n",
"2\n"
] | Possible pairs in the second example:
1. *x* = 1, *y* = 2 (season 1 episode 2 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8774ca35b6e628888a4670e4539d47857e5e5841.png" style="max-width: 100.0%;max-height: 100.0%;"/> season 2 episode 1); 1. *x* = 2, *y* = 3 (season 2 episode 3 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8774ca35b6e628888a4670e4539d47857e5e5841.png" style="max-width: 100.0%;max-height: 100.0%;"/> season 3 episode 2); 1. *x* = 1, *y* = 3 (season 1 episode 3 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8774ca35b6e628888a4670e4539d47857e5e5841.png" style="max-width: 100.0%;max-height: 100.0%;"/> season 3 episode 1).
In the third example:
1. *x* = 1, *y* = 2 (season 1 episode 2 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8774ca35b6e628888a4670e4539d47857e5e5841.png" style="max-width: 100.0%;max-height: 100.0%;"/> season 2 episode 1); 1. *x* = 1, *y* = 3 (season 1 episode 3 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8774ca35b6e628888a4670e4539d47857e5e5841.png" style="max-width: 100.0%;max-height: 100.0%;"/> season 3 episode 1). | 0 | [
{
"input": "5\n1 2 3 4 5",
"output": "0"
},
{
"input": "3\n8 12 7",
"output": "3"
},
{
"input": "3\n3 2 1",
"output": "2"
},
{
"input": "5\n2 3 4 5 6",
"output": "4"
},
{
"input": "8\n7 2 6 6 5 1 4 9",
"output": "9"
},
{
"input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "45"
},
{
"input": "1\n1",
"output": "0"
}
] | 1,551,294,613 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 296 | 18,124,800 | N = int(input())
A = list(map(int, input().split()))
def getsum(BITTree,i):
s = 0
i = i+1
while i > 0:
s += BITTree[i]
i -= i & (-i)
return s
def updatebit(BITTree , n , i ,v):
i += 1
while i <= n:
BITTree[i] += v
i += i & (-i)
def construct(arr, n):
BITTree = [0]*(n+1)
for i in range(n):
updatebit(BITTree, n, i, arr[i])
return BITTree
BIT = construct([0]*(N+1), N+1)
ans = 0
for i in range(N):
a = min(A[i],N)
# s = ""
# for j in range(1,N+1):
# s += str(getsum(BIT,j)) + " "
# print(s)
#
k = getsum(BIT,i+1)
# print(i,a,k)
ans += min(a, k)
updatebit(BIT, N+1, 1,1)
updatebit(BIT, N+1, a+1,-1)
print(ans)
| Title: Tufurama
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused — what if he decides to rewatch the entire series someday and won't be able to find the right episodes to watch? Polycarp now wants to count the number of times he will be forced to search for an episode using some different method.
TV series have *n* seasons (numbered 1 through *n*), the *i*-th season has *a**i* episodes (numbered 1 through *a**i*). Polycarp thinks that if for some pair of integers *x* and *y* (*x*<=<<=*y*) exist both season *x* episode *y* and season *y* episode *x* then one of these search queries will include the wrong results. Help Polycarp to calculate the number of such pairs!
Input Specification:
The first line contains one integer *n* (1<=<=≤<=*n*<=<=≤<=<=2·105) — the number of seasons.
The second line contains *n* integers separated by space *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — number of episodes in each season.
Output Specification:
Print one integer — the number of pairs *x* and *y* (*x*<=<<=*y*) such that there exist both season *x* episode *y* and season *y* episode *x*.
Demo Input:
['5\n1 2 3 4 5\n', '3\n8 12 7\n', '3\n3 2 1\n']
Demo Output:
['0\n', '3\n', '2\n']
Note:
Possible pairs in the second example:
1. *x* = 1, *y* = 2 (season 1 episode 2 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8774ca35b6e628888a4670e4539d47857e5e5841.png" style="max-width: 100.0%;max-height: 100.0%;"/> season 2 episode 1); 1. *x* = 2, *y* = 3 (season 2 episode 3 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8774ca35b6e628888a4670e4539d47857e5e5841.png" style="max-width: 100.0%;max-height: 100.0%;"/> season 3 episode 2); 1. *x* = 1, *y* = 3 (season 1 episode 3 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8774ca35b6e628888a4670e4539d47857e5e5841.png" style="max-width: 100.0%;max-height: 100.0%;"/> season 3 episode 1).
In the third example:
1. *x* = 1, *y* = 2 (season 1 episode 2 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8774ca35b6e628888a4670e4539d47857e5e5841.png" style="max-width: 100.0%;max-height: 100.0%;"/> season 2 episode 1); 1. *x* = 1, *y* = 3 (season 1 episode 3 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8774ca35b6e628888a4670e4539d47857e5e5841.png" style="max-width: 100.0%;max-height: 100.0%;"/> season 3 episode 1). | ```python
N = int(input())
A = list(map(int, input().split()))
def getsum(BITTree,i):
s = 0
i = i+1
while i > 0:
s += BITTree[i]
i -= i & (-i)
return s
def updatebit(BITTree , n , i ,v):
i += 1
while i <= n:
BITTree[i] += v
i += i & (-i)
def construct(arr, n):
BITTree = [0]*(n+1)
for i in range(n):
updatebit(BITTree, n, i, arr[i])
return BITTree
BIT = construct([0]*(N+1), N+1)
ans = 0
for i in range(N):
a = min(A[i],N)
# s = ""
# for j in range(1,N+1):
# s += str(getsum(BIT,j)) + " "
# print(s)
#
k = getsum(BIT,i+1)
# print(i,a,k)
ans += min(a, k)
updatebit(BIT, N+1, 1,1)
updatebit(BIT, N+1, a+1,-1)
print(ans)
``` | 0 |
|
315 | A | Sereja and Bottles | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle. | In a single line print a single integer — the answer to the problem. | [
"4\n1 1\n2 2\n3 3\n4 4\n",
"4\n1 2\n2 3\n3 4\n4 1\n"
] | [
"4\n",
"0\n"
] | none | 500 | [
{
"input": "4\n1 1\n2 2\n3 3\n4 4",
"output": "4"
},
{
"input": "4\n1 2\n2 3\n3 4\n4 1",
"output": "0"
},
{
"input": "3\n2 828\n4 392\n4 903",
"output": "3"
},
{
"input": "4\n2 3\n1 772\n3 870\n3 668",
"output": "2"
},
{
"input": "5\n1 4\n6 6\n4 3\n3 4\n4 758",
"output": "2"
},
{
"input": "6\n4 843\n2 107\n10 943\n9 649\n7 806\n6 730",
"output": "6"
},
{
"input": "7\n351 955\n7 841\n102 377\n394 102\n549 440\n630 324\n624 624",
"output": "6"
},
{
"input": "8\n83 978\n930 674\n542 22\n834 116\n116 271\n640 930\n659 930\n705 987",
"output": "6"
},
{
"input": "9\n162 942\n637 967\n356 108\n768 53\n656 656\n575 32\n32 575\n53 53\n351 222",
"output": "6"
},
{
"input": "10\n423 360\n947 538\n507 484\n31 947\n414 351\n169 901\n901 21\n592 22\n763 200\n656 485",
"output": "8"
},
{
"input": "1\n1000 1000",
"output": "1"
},
{
"input": "1\n500 1000",
"output": "1"
},
{
"input": "11\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11",
"output": "11"
},
{
"input": "49\n1 758\n5 3\n5 3\n4 2\n4 36\n3 843\n5 107\n1 943\n1 649\n2 806\n3 730\n2 351\n2 102\n1 4\n3 4\n3 955\n2 841\n2 377\n5 2\n3 440\n4 324\n3 3\n3 83\n2 2\n2 1\n4 1\n1 931\n3 4\n2 5\n2 5\n4 73\n5 830\n3 4\n3 5\n5 291\n1 2\n5 3\n4 4\n2 3\n3 151\n4 2\n4 431\n5 1\n2 5\n2 4\n4 2\n4 4\n3 1\n5 2",
"output": "0"
},
{
"input": "50\n507 31\n31 250\n414 763\n169 304\n901 9\n592 610\n763 414\n656 789\n411 422\n360 468\n625 504\n538 201\n549 619\n484 797\n596 282\n42 310\n603 656\n351 623\n292 293\n837 180\n375 658\n21 192\n597 729\n22 512\n349 635\n200 56\n669 647\n485 887\n282 939\n735 808\n54 417\n1000 310\n419 652\n939 617\n901 669\n789 390\n128 549\n468 511\n729 837\n894 729\n649 894\n484 22\n808 586\n422 286\n311 427\n618 656\n814 933\n515 901\n310 894\n617 330",
"output": "30"
},
{
"input": "2\n7 7\n5 359",
"output": "2"
},
{
"input": "2\n465 706\n706 706",
"output": "1"
},
{
"input": "2\n1 1\n1 1",
"output": "0"
},
{
"input": "3\n1 1\n1 1\n2 2",
"output": "1"
},
{
"input": "5\n1 1\n1 2\n2 3\n3 4\n4 3",
"output": "1"
},
{
"input": "3\n1 2\n1 2\n1 1",
"output": "1"
}
] | 1,670,699,831 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n = int(input())
adj = dict()
vist = dict()
for i in range(n):
temp = input().split(" ")
u = int(temp[0])
v = int(temp[1])
if(u not in vist ):
vist[u] = -1
if(v not in vist ):
vist[v] = -1
if(u in adj):
adj[u].append(v)
else:
adj[u] = [v]
print(vist)
#print(adj)
for i in adj:
neigh = adj[i]
for j in neigh:
if(i != j):
vist[j] =1
count = 0
for i in vist:
if(vist[i] < 0):
count+=1
print(count) | Title: Sereja and Bottles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle.
Output Specification:
In a single line print a single integer — the answer to the problem.
Demo Input:
['4\n1 1\n2 2\n3 3\n4 4\n', '4\n1 2\n2 3\n3 4\n4 1\n']
Demo Output:
['4\n', '0\n']
Note:
none | ```python
n = int(input())
adj = dict()
vist = dict()
for i in range(n):
temp = input().split(" ")
u = int(temp[0])
v = int(temp[1])
if(u not in vist ):
vist[u] = -1
if(v not in vist ):
vist[v] = -1
if(u in adj):
adj[u].append(v)
else:
adj[u] = [v]
print(vist)
#print(adj)
for i in adj:
neigh = adj[i]
for j in neigh:
if(i != j):
vist[j] =1
count = 0
for i in vist:
if(vist[i] < 0):
count+=1
print(count)
``` | 0 |
|
742 | A | Arpa’s hard exam and Mehrdad’s naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat. | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": "8"
},
{
"input": "6",
"output": "4"
},
{
"input": "999999999",
"output": "2"
},
{
"input": "1378",
"output": "4"
},
{
"input": "13781378",
"output": "4"
},
{
"input": "51202278",
"output": "4"
},
{
"input": "999999998",
"output": "4"
},
{
"input": "999999997",
"output": "8"
},
{
"input": "12193721",
"output": "8"
},
{
"input": "0",
"output": "1"
},
{
"input": "989898989",
"output": "8"
},
{
"input": "7",
"output": "2"
},
{
"input": "8",
"output": "6"
},
{
"input": "9",
"output": "8"
},
{
"input": "10",
"output": "4"
},
{
"input": "11",
"output": "2"
},
{
"input": "12",
"output": "6"
},
{
"input": "13",
"output": "8"
},
{
"input": "14",
"output": "4"
},
{
"input": "15",
"output": "2"
},
{
"input": "16",
"output": "6"
},
{
"input": "999999996",
"output": "6"
},
{
"input": "999999995",
"output": "2"
},
{
"input": "999999994",
"output": "4"
}
] | 1,662,713,884 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 24,985,600 | n=int(input())
num=1378**n
st=num%10
print(st) | Title: Arpa’s hard exam and Mehrdad’s naive cheat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
Input Specification:
The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109).
Output Specification:
Print single integer — the last digit of 1378*n*.
Demo Input:
['1\n', '2\n']
Demo Output:
['8', '4']
Note:
In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | ```python
n=int(input())
num=1378**n
st=num%10
print(st)
``` | 0 |
|
859 | E | Desk Disorder | PROGRAMMING | 2,100 | [
"combinatorics",
"dfs and similar",
"dsu",
"graphs",
"trees"
] | null | null | A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out a survey to the engineering team asking each engineer the number of the desk they currently sit at, and the number of the desk they would like to sit at (which may be the same as their current desk). Each engineer must either remain where they sit, or move to the desired seat they indicated in the survey. No two engineers currently sit at the same desk, nor may any two engineers sit at the same desk in the new seating arrangement.
How many seating arrangements can you create that meet the specified requirements? The answer may be very large, so compute it modulo 1000000007<==<=109<=+<=7. | Input will begin with a line containing *N* (1<=≤<=*N*<=≤<=100000), the number of engineers.
*N* lines follow, each containing exactly two integers. The *i*-th line contains the number of the current desk of the *i*-th engineer and the number of the desk the *i*-th engineer wants to move to. Desks are numbered from 1 to 2·*N*. It is guaranteed that no two engineers sit at the same desk. | Print the number of possible assignments, modulo 1000000007<==<=109<=+<=7. | [
"4\n1 5\n5 2\n3 7\n7 3\n",
"5\n1 10\n2 10\n3 10\n4 10\n5 5\n"
] | [
"6\n",
"5\n"
] | These are the possible assignments for the first example:
- 1 5 3 7 - 1 2 3 7 - 5 2 3 7 - 1 5 7 3 - 1 2 7 3 - 5 2 7 3 | 2,000 | [
{
"input": "4\n1 5\n5 2\n3 7\n7 3",
"output": "6"
},
{
"input": "5\n1 10\n2 10\n3 10\n4 10\n5 5",
"output": "5"
},
{
"input": "1\n1 2",
"output": "2"
},
{
"input": "30\n22 37\n12 37\n37 58\n29 57\n43 57\n57 58\n58 53\n45 4\n1 4\n4 51\n35 31\n21 31\n31 51\n51 53\n53 48\n60 55\n52 55\n55 33\n36 9\n10 9\n9 33\n33 19\n5 23\n47 23\n23 32\n50 44\n26 44\n44 32\n32 19\n19 48",
"output": "31"
},
{
"input": "50\n73 1\n65 73\n16 65\n57 65\n33 16\n34 57\n98 16\n84 98\n55 34\n64 84\n80 55\n75 64\n28 75\n20 75\n42 75\n88 42\n50 20\n48 28\n32 48\n58 88\n92 76\n76 53\n53 15\n15 1\n1 10\n10 71\n71 37\n37 95\n95 63\n63 92\n45 97\n97 51\n51 96\n96 12\n12 62\n62 31\n31 5\n5 29\n29 19\n19 49\n49 6\n6 40\n40 18\n18 22\n22 17\n17 46\n46 72\n72 82\n82 14\n14 14",
"output": "2"
},
{
"input": "10\n15 8\n8 13\n13 3\n1 4\n14 3\n11 17\n9 10\n10 18\n19 20\n17 20",
"output": "120"
},
{
"input": "4\n5 6\n6 7\n7 8\n8 5",
"output": "2"
},
{
"input": "5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "2"
}
] | 1,679,629,111 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 102,400 | from collections import defaultdict #asignar valor por
#default a nuevos escritorios
import math
MOD = 1000000007 #módulo
def contar_asignaciones(n, movimientos):
grafo = defaultdict(set)
for escritorio_desde, escritorio_hasta in movimientos:
grafo[escritorio_desde].add(escritorio_hasta)
visitado = set()
componentes = []
#depth search
def dfs(nodo, componente):
visitado.add(nodo)
componente.append(nodo)
for vecino in grafo[nodo]:
if vecino not in visitado:
dfs(vecino, componente)
#recorrer nodos del grafo
for nodo in range(1, 2 * n + 1):
if nodo not in visitado:
componente = []
dfs(nodo, componente)
componentes.append(componente)
resultado = 1
#calcular el num de asignaciones posibles
for componente in componentes:
resultado = (resultado * (len(componente) - 1)) % MOD
resultado = (resultado * math.factorial(len(componente))) % MOD
return resultado
def main():
n = int(input())
movimientos = [tuple(map(int, input().split())) for _ in range(n)] #leer los movimientos de los escritorios
print(contar_asignaciones(n, movimientos))
if __name__ == "__main__":
main()
| Title: Desk Disorder
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out a survey to the engineering team asking each engineer the number of the desk they currently sit at, and the number of the desk they would like to sit at (which may be the same as their current desk). Each engineer must either remain where they sit, or move to the desired seat they indicated in the survey. No two engineers currently sit at the same desk, nor may any two engineers sit at the same desk in the new seating arrangement.
How many seating arrangements can you create that meet the specified requirements? The answer may be very large, so compute it modulo 1000000007<==<=109<=+<=7.
Input Specification:
Input will begin with a line containing *N* (1<=≤<=*N*<=≤<=100000), the number of engineers.
*N* lines follow, each containing exactly two integers. The *i*-th line contains the number of the current desk of the *i*-th engineer and the number of the desk the *i*-th engineer wants to move to. Desks are numbered from 1 to 2·*N*. It is guaranteed that no two engineers sit at the same desk.
Output Specification:
Print the number of possible assignments, modulo 1000000007<==<=109<=+<=7.
Demo Input:
['4\n1 5\n5 2\n3 7\n7 3\n', '5\n1 10\n2 10\n3 10\n4 10\n5 5\n']
Demo Output:
['6\n', '5\n']
Note:
These are the possible assignments for the first example:
- 1 5 3 7 - 1 2 3 7 - 5 2 3 7 - 1 5 7 3 - 1 2 7 3 - 5 2 7 3 | ```python
from collections import defaultdict #asignar valor por
#default a nuevos escritorios
import math
MOD = 1000000007 #módulo
def contar_asignaciones(n, movimientos):
grafo = defaultdict(set)
for escritorio_desde, escritorio_hasta in movimientos:
grafo[escritorio_desde].add(escritorio_hasta)
visitado = set()
componentes = []
#depth search
def dfs(nodo, componente):
visitado.add(nodo)
componente.append(nodo)
for vecino in grafo[nodo]:
if vecino not in visitado:
dfs(vecino, componente)
#recorrer nodos del grafo
for nodo in range(1, 2 * n + 1):
if nodo not in visitado:
componente = []
dfs(nodo, componente)
componentes.append(componente)
resultado = 1
#calcular el num de asignaciones posibles
for componente in componentes:
resultado = (resultado * (len(componente) - 1)) % MOD
resultado = (resultado * math.factorial(len(componente))) % MOD
return resultado
def main():
n = int(input())
movimientos = [tuple(map(int, input().split())) for _ in range(n)] #leer los movimientos de los escritorios
print(contar_asignaciones(n, movimientos))
if __name__ == "__main__":
main()
``` | 0 |
|
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.
Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement.
- The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1\n0 1\n1 0\n1 0",
"output": "2"
},
{
"input": "3\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "5\n0 73\n73 189\n189 766\n766 0\n0 0",
"output": "766"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 1\n1 0",
"output": "1"
},
{
"input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0",
"output": "1011"
},
{
"input": "5\n0 1\n1 2\n2 1\n1 2\n2 0",
"output": "2"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0",
"output": "22"
},
{
"input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0",
"output": "1776"
},
{
"input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0",
"output": "2"
},
{
"input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0",
"output": "1016"
},
{
"input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0",
"output": "3"
},
{
"input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0",
"output": "2071"
},
{
"input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0",
"output": "3"
},
{
"input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0",
"output": "1329"
},
{
"input": "2\n0 863\n863 0",
"output": "863"
},
{
"input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0",
"output": "8"
},
{
"input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0",
"output": "11"
},
{
"input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0",
"output": "7"
},
{
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "2\n0 900\n900 0",
"output": "900"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "2\n0 1000\n1000 0",
"output": "1000"
},
{
"input": "3\n0 802\n175 188\n815 0",
"output": "815"
},
{
"input": "3\n0 910\n910 976\n976 0",
"output": "976"
},
{
"input": "3\n0 2\n2 1\n1 0",
"output": "2"
}
] | 1,695,294,125 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 92 | 0 | n = int(input())
r = 0
s=0
m=[]
z=0
g=0
for i in range(n):
a, b = list(map(int, input().split()))
z+=b
r = a
s= b
c=s-r
g+=c
m.append(g)
if z==0:
print(0)
print(max(m))
| Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.
Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Input Specification:
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement.
- The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Output Specification:
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
Demo Input:
['4\n0 3\n2 5\n4 2\n4 0\n']
Demo Output:
['6\n']
Note:
For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | ```python
n = int(input())
r = 0
s=0
m=[]
z=0
g=0
for i in range(n):
a, b = list(map(int, input().split()))
z+=b
r = a
s= b
c=s-r
g+=c
m.append(g)
if z==0:
print(0)
print(max(m))
``` | 0 |
|
361 | A | Levko and Table | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them. | [
"2 4\n",
"4 7\n"
] | [
"1 3\n3 1\n",
"2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n"
] | In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | 500 | [
{
"input": "2 4",
"output": "4 0 \n0 4 "
},
{
"input": "4 7",
"output": "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 "
},
{
"input": "1 8",
"output": "8 "
},
{
"input": "9 3",
"output": "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0 0 0 0 \n0 0 0 0 0 3 0 0 0 \n0 0 0 0 0 0 3 0 0 \n0 0 0 0 0 0 0 3 0 \n0 0 0 0 0 0 0 0 3 "
},
{
"input": "31 581",
"output": "581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 1000",
"output": "1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ..."
},
{
"input": "100 999",
"output": "999 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 999 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 999 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "99 998",
"output": "998 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 998 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 998 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "100 997",
"output": "997 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 997 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 997 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "81 111",
"output": "111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 111 0 0..."
},
{
"input": "1 407",
"output": "407 "
},
{
"input": "54 341",
"output": "341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "92 460",
"output": "460 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 460 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 460 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "34 47",
"output": "47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 ..."
},
{
"input": "11 547",
"output": "547 0 0 0 0 0 0 0 0 0 0 \n0 547 0 0 0 0 0 0 0 0 0 \n0 0 547 0 0 0 0 0 0 0 0 \n0 0 0 547 0 0 0 0 0 0 0 \n0 0 0 0 547 0 0 0 0 0 0 \n0 0 0 0 0 547 0 0 0 0 0 \n0 0 0 0 0 0 547 0 0 0 0 \n0 0 0 0 0 0 0 547 0 0 0 \n0 0 0 0 0 0 0 0 547 0 0 \n0 0 0 0 0 0 0 0 0 547 0 \n0 0 0 0 0 0 0 0 0 0 547 "
},
{
"input": "100 1",
"output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 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..."
},
{
"input": "99 1",
"output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 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..."
},
{
"input": "99 2",
"output": "2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "2 7",
"output": "7 0 \n0 7 "
},
{
"input": "100 100",
"output": "100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "4 3",
"output": "3 0 0 0 \n0 3 0 0 \n0 0 3 0 \n0 0 0 3 "
},
{
"input": "3 2",
"output": "2 0 0 \n0 2 0 \n0 0 2 "
}
] | 1,384,103,234 | 434 | Python 3 | OK | TESTS | 22 | 62 | 102,400 | n, k = map(int, input().split())
for i in range(n):
if i != n-1:
print(*([0]*(n-i-1)), end = ' ')
print(k, end = ' ')
print(*([0]*(i))) | Title: Levko and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
Input Specification:
The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000).
Output Specification:
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them.
Demo Input:
['2 4\n', '4 7\n']
Demo Output:
['1 3\n3 1\n', '2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n']
Note:
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements. | ```python
n, k = map(int, input().split())
for i in range(n):
if i != n-1:
print(*([0]*(n-i-1)), end = ' ')
print(k, end = ' ')
print(*([0]*(i)))
``` | 3 |
|
831 | A | Unimodal Array | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Array of integers is unimodal, if:
- it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.
For example, the following three arrays are unimodal: [5,<=7,<=11,<=11,<=2,<=1], [4,<=4,<=2], [7], but the following three are not unimodal: [5,<=5,<=6,<=6,<=1], [1,<=2,<=1,<=2], [4,<=5,<=5,<=6].
Write a program that checks if an array is unimodal. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000) — the elements of the array. | Print "YES" if the given array is unimodal. Otherwise, print "NO".
You can output each letter in any case (upper or lower). | [
"6\n1 5 5 5 4 2\n",
"5\n10 20 30 20 10\n",
"4\n1 2 1 2\n",
"7\n3 3 3 3 3 3 3\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). | 500 | [
{
"input": "6\n1 5 5 5 4 2",
"output": "YES"
},
{
"input": "5\n10 20 30 20 10",
"output": "YES"
},
{
"input": "4\n1 2 1 2",
"output": "NO"
},
{
"input": "7\n3 3 3 3 3 3 3",
"output": "YES"
},
{
"input": "6\n5 7 11 11 2 1",
"output": "YES"
},
{
"input": "1\n7",
"output": "YES"
},
{
"input": "100\n527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527",
"output": "YES"
},
{
"input": "5\n5 5 6 6 1",
"output": "NO"
},
{
"input": "3\n4 4 2",
"output": "YES"
},
{
"input": "4\n4 5 5 6",
"output": "NO"
},
{
"input": "3\n516 516 515",
"output": "YES"
},
{
"input": "5\n502 503 508 508 507",
"output": "YES"
},
{
"input": "10\n538 538 538 538 538 538 538 538 538 538",
"output": "YES"
},
{
"input": "15\n452 454 455 455 450 448 443 442 439 436 433 432 431 428 426",
"output": "YES"
},
{
"input": "20\n497 501 504 505 509 513 513 513 513 513 513 513 513 513 513 513 513 513 513 513",
"output": "YES"
},
{
"input": "50\n462 465 465 465 463 459 454 449 444 441 436 435 430 429 426 422 421 418 417 412 408 407 406 403 402 399 395 392 387 386 382 380 379 376 374 371 370 365 363 359 358 354 350 349 348 345 342 341 338 337",
"output": "YES"
},
{
"input": "70\n290 292 294 297 299 300 303 305 310 312 313 315 319 320 325 327 328 333 337 339 340 341 345 350 351 354 359 364 367 372 374 379 381 382 383 384 389 393 395 397 398 400 402 405 409 411 416 417 422 424 429 430 434 435 440 442 445 449 451 453 458 460 465 470 474 477 482 482 482 479",
"output": "YES"
},
{
"input": "99\n433 435 439 444 448 452 457 459 460 464 469 470 471 476 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 479 478 477 476 474 469 468 465 460 457 453 452 450 445 443 440 438 433 432 431 430 428 425 421 418 414 411 406 402 397 396 393",
"output": "YES"
},
{
"input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543",
"output": "YES"
},
{
"input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521",
"output": "YES"
},
{
"input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 346 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504",
"output": "YES"
},
{
"input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 363 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496",
"output": "YES"
},
{
"input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 351 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173",
"output": "YES"
},
{
"input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 431 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333",
"output": "YES"
},
{
"input": "1\n1000",
"output": "YES"
},
{
"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": "YES"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1",
"output": "YES"
},
{
"input": "100\n1 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "NO"
},
{
"input": "100\n998 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999",
"output": "NO"
},
{
"input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 691 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543",
"output": "NO"
},
{
"input": "100\n527 527 527 527 527 527 527 527 872 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527",
"output": "NO"
},
{
"input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 208 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521",
"output": "NO"
},
{
"input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 921 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504",
"output": "NO"
},
{
"input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 119 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496",
"output": "NO"
},
{
"input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 335 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173",
"output": "NO"
},
{
"input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 525 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333",
"output": "NO"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "3\n3 2 1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "NO"
},
{
"input": "3\n2 1 1",
"output": "NO"
},
{
"input": "3\n2 1 2",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "NO"
},
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 497 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346",
"output": "YES"
},
{
"input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 333 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475",
"output": "YES"
},
{
"input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 498 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271",
"output": "YES"
},
{
"input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 32 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346",
"output": "NO"
},
{
"input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 247 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475",
"output": "NO"
},
{
"input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 497 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271",
"output": "YES"
},
{
"input": "2\n1 3",
"output": "YES"
},
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "5\n2 2 1 1 1",
"output": "NO"
},
{
"input": "4\n1 3 2 2",
"output": "NO"
},
{
"input": "6\n1 2 1 2 2 1",
"output": "NO"
},
{
"input": "2\n4 2",
"output": "YES"
},
{
"input": "3\n3 2 2",
"output": "NO"
},
{
"input": "9\n1 2 2 3 3 4 3 2 1",
"output": "NO"
},
{
"input": "4\n5 5 4 4",
"output": "NO"
},
{
"input": "2\n2 1",
"output": "YES"
},
{
"input": "5\n5 4 3 2 1",
"output": "YES"
},
{
"input": "7\n4 3 3 3 3 3 3",
"output": "NO"
},
{
"input": "5\n1 2 3 4 5",
"output": "YES"
},
{
"input": "3\n2 2 1",
"output": "YES"
},
{
"input": "3\n4 3 3",
"output": "NO"
},
{
"input": "7\n1 5 5 4 3 3 1",
"output": "NO"
},
{
"input": "6\n3 3 1 2 2 1",
"output": "NO"
},
{
"input": "5\n1 2 1 2 1",
"output": "NO"
},
{
"input": "2\n5 1",
"output": "YES"
},
{
"input": "9\n1 2 3 4 4 3 2 2 1",
"output": "NO"
},
{
"input": "3\n2 2 3",
"output": "NO"
},
{
"input": "2\n5 4",
"output": "YES"
},
{
"input": "5\n1 3 3 2 2",
"output": "NO"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 99",
"output": "YES"
},
{
"input": "4\n1 2 3 4",
"output": "YES"
},
{
"input": "3\n5 5 2",
"output": "YES"
},
{
"input": "4\n1 4 2 3",
"output": "NO"
},
{
"input": "2\n3 2",
"output": "YES"
},
{
"input": "5\n1 2 2 1 1",
"output": "NO"
},
{
"input": "4\n3 3 2 2",
"output": "NO"
},
{
"input": "5\n1 2 3 2 2",
"output": "NO"
},
{
"input": "5\n5 6 6 5 5",
"output": "NO"
},
{
"input": "4\n2 2 1 1",
"output": "NO"
},
{
"input": "5\n5 4 3 3 2",
"output": "NO"
},
{
"input": "7\n1 3 3 3 2 1 1",
"output": "NO"
},
{
"input": "9\n5 6 6 5 5 4 4 3 3",
"output": "NO"
},
{
"input": "6\n1 5 5 3 2 2",
"output": "NO"
},
{
"input": "5\n2 1 3 3 1",
"output": "NO"
},
{
"input": "2\n4 3",
"output": "YES"
},
{
"input": "5\n3 2 2 1 1",
"output": "NO"
},
{
"input": "4\n5 4 3 2",
"output": "YES"
},
{
"input": "4\n4 4 1 1",
"output": "NO"
},
{
"input": "4\n3 3 1 1",
"output": "NO"
},
{
"input": "4\n4 4 2 2",
"output": "NO"
},
{
"input": "5\n4 4 3 2 2",
"output": "NO"
},
{
"input": "8\n4 4 4 4 5 6 7 8",
"output": "NO"
},
{
"input": "5\n3 5 4 4 3",
"output": "NO"
},
{
"input": "6\n2 5 3 3 2 2",
"output": "NO"
},
{
"input": "4\n5 5 2 2",
"output": "NO"
},
{
"input": "5\n1 2 2 3 5",
"output": "NO"
}
] | 1,655,827,399 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 5 | 62 | 3,379,200 | n = int(input())
a =list(map(int, input().split()))
f = 0
for i in range(1, n):
if a[i-1]>a[i]: break
for j in range(i, n-1):
if a[j]<a[j+1]:
print("NO")
f = 1
break
if not f: print("YES") | Title: Unimodal Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Array of integers is unimodal, if:
- it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.
For example, the following three arrays are unimodal: [5,<=7,<=11,<=11,<=2,<=1], [4,<=4,<=2], [7], but the following three are not unimodal: [5,<=5,<=6,<=6,<=1], [1,<=2,<=1,<=2], [4,<=5,<=5,<=6].
Write a program that checks if an array is unimodal.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000) — the elements of the array.
Output Specification:
Print "YES" if the given array is unimodal. Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Demo Input:
['6\n1 5 5 5 4 2\n', '5\n10 20 30 20 10\n', '4\n1 2 1 2\n', '7\n3 3 3 3 3 3 3\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n', 'YES\n']
Note:
In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). | ```python
n = int(input())
a =list(map(int, input().split()))
f = 0
for i in range(1, n):
if a[i-1]>a[i]: break
for j in range(i, n-1):
if a[j]<a[j+1]:
print("NO")
f = 1
break
if not f: print("YES")
``` | -1 |
|
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle.
Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number. | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "2 2",
"output": "3"
},
{
"input": "3 2",
"output": "5"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "999 2",
"output": "1997"
},
{
"input": "1000 3",
"output": "1499"
},
{
"input": "1000 4",
"output": "1333"
},
{
"input": "1 1000",
"output": "1"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "10 4",
"output": "13"
},
{
"input": "4 3",
"output": "5"
},
{
"input": "91 5",
"output": "113"
},
{
"input": "777 17",
"output": "825"
},
{
"input": "100 4",
"output": "133"
},
{
"input": "5 3",
"output": "7"
},
{
"input": "6 4",
"output": "7"
},
{
"input": "26 8",
"output": "29"
},
{
"input": "9 4",
"output": "11"
},
{
"input": "20 3",
"output": "29"
},
{
"input": "17 3",
"output": "25"
}
] | 1,677,426,964 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | a, b = map(int, input().split())
ogr = a
time = a
while ogr >= b:
time += ogr // b
ogr //= b
print(time)
| Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle.
Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.
Input Specification:
The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000).
Output Specification:
Print a single integer — the number of hours Vasily can light up the room for.
Demo Input:
['4 2\n', '6 3\n']
Demo Output:
['7\n', '8\n']
Note:
Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | ```python
a, b = map(int, input().split())
ogr = a
time = a
while ogr >= b:
time += ogr // b
ogr //= b
print(time)
``` | 0 |
|
362 | B | Petya and Staircases | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.
Now Petya is on the first stair of the staircase, consisting of *n* stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number *n* without touching a dirty stair once.
One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty stairs (in an arbitrary order). | Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO". | [
"10 5\n2 4 8 3 6\n",
"10 5\n2 4 5 7 9\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "10 5\n2 4 8 3 6",
"output": "NO"
},
{
"input": "10 5\n2 4 5 7 9",
"output": "YES"
},
{
"input": "10 9\n2 3 4 5 6 7 8 9 10",
"output": "NO"
},
{
"input": "5 2\n4 5",
"output": "NO"
},
{
"input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37",
"output": "YES"
},
{
"input": "10 10\n7 6 4 2 5 10 8 3 9 1",
"output": "NO"
},
{
"input": "12312 0",
"output": "YES"
},
{
"input": "9817239 1\n6323187",
"output": "YES"
},
{
"input": "1 1\n1",
"output": "NO"
},
{
"input": "5 4\n4 2 5 1",
"output": "NO"
},
{
"input": "5 3\n4 3 5",
"output": "NO"
},
{
"input": "500 3\n18 62 445",
"output": "YES"
},
{
"input": "500 50\n72 474 467 241 442 437 336 234 410 120 438 164 405 177 142 114 27 20 445 235 46 176 88 488 242 391 28 414 145 92 206 334 152 343 367 254 100 243 155 348 148 450 461 483 97 34 471 69 416 362",
"output": "NO"
},
{
"input": "500 8\n365 313 338 410 482 417 325 384",
"output": "YES"
},
{
"input": "1000000000 10\n2 3 5 6 8 9 123 874 1230 1000000000",
"output": "NO"
},
{
"input": "1000000000 10\n1 2 3 5 6 8 9 123 874 1230",
"output": "NO"
},
{
"input": "10 1\n1",
"output": "NO"
},
{
"input": "10 4\n1 2 4 5",
"output": "NO"
},
{
"input": "50 20\n22 33 17 23 27 5 26 31 41 20 8 24 6 3 4 29 40 25 13 16",
"output": "NO"
},
{
"input": "50 40\n14 27 19 30 31 20 28 11 37 29 23 33 7 26 22 16 1 6 18 3 47 36 38 2 48 9 41 8 5 50 4 45 44 25 39 12 43 42 40 46",
"output": "NO"
},
{
"input": "123 12\n35 95 47 99 79 122 58 94 31 57 18 10",
"output": "YES"
},
{
"input": "10 5\n1 3 5 7 9",
"output": "NO"
},
{
"input": "100 7\n2 3 5 6 8 9 100",
"output": "NO"
},
{
"input": "100 3\n98 99 100",
"output": "NO"
},
{
"input": "100 3\n97 98 99",
"output": "NO"
},
{
"input": "100 3\n96 98 99",
"output": "YES"
},
{
"input": "10 6\n2 3 5 6 8 9",
"output": "YES"
},
{
"input": "1000000000 10\n2 4 10 18 40 42 49 58 59 60",
"output": "NO"
},
{
"input": "10 3\n1 4 6",
"output": "NO"
},
{
"input": "8 3\n2 3 4",
"output": "NO"
},
{
"input": "100 3\n4 5 6",
"output": "NO"
},
{
"input": "10 2\n10 1",
"output": "NO"
},
{
"input": "10 1\n10",
"output": "NO"
},
{
"input": "4 2\n2 3",
"output": "YES"
},
{
"input": "2 1\n1",
"output": "NO"
},
{
"input": "2 0",
"output": "YES"
},
{
"input": "4 3\n2 3 4",
"output": "NO"
},
{
"input": "5 3\n4 2 3",
"output": "NO"
}
] | 1,631,640,297 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 4 | 124 | 23,040,000 | n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
if(l[0]==1 or l[-1]==n):
print("NO")
else:
flag=0
for i in range(0,len(l)-2+1,2):
#print(i)
if(l[i+2]-l[i]<=2):
flag=1
print("NO")
break
if(flag==0):
print("YES")
| Title: Petya and Staircases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.
Now Petya is on the first stair of the staircase, consisting of *n* stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number *n* without touching a dirty stair once.
One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty stairs (in an arbitrary order).
Output Specification:
Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO".
Demo Input:
['10 5\n2 4 8 3 6\n', '10 5\n2 4 5 7 9\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
if(l[0]==1 or l[-1]==n):
print("NO")
else:
flag=0
for i in range(0,len(l)-2+1,2):
#print(i)
if(l[i+2]-l[i]<=2):
flag=1
print("NO")
break
if(flag==0):
print("YES")
``` | -1 |
|
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,661,358,514 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | n=input()
s="0000000"
s1="1111111"
if (s in n) or (s1 in n):
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
n=input()
s="0000000"
s1="1111111"
if (s in n) or (s1 in n):
print("YES")
else:
print("NO")
``` | 3.977 |
4 | B | Before an Exam | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy"
] | B. Before an Exam | 0 | 64 | Tomorrow Peter has a Biology exam. He does not like this subject much, but *d* days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than *minTime**i* and not more than *maxTime**i* hours per each *i*-th day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.
So, today is the day when Peter's parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hours *sumTime* spent him on preparation, and now he wants to know if he can show his parents a timetable *sсhedule* with *d* numbers, where each number *sсhedule**i* stands for the time in hours spent by Peter each *i*-th day on biology studies, and satisfying the limitations imposed by his parents, and at the same time the sum total of all *schedule**i* should equal to *sumTime*. | The first input line contains two integer numbers *d*,<=*sumTime* (1<=≤<=*d*<=≤<=30,<=0<=≤<=*sumTime*<=≤<=240) — the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following *d* lines contains two integer numbers *minTime**i*,<=*maxTime**i* (0<=≤<=*minTime**i*<=≤<=*maxTime**i*<=≤<=8), separated by a space — minimum and maximum amount of hours that Peter could spent in the *i*-th day. | In the first line print YES, and in the second line print *d* numbers (separated by a space), each of the numbers — amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents' instructions; or print NO in the unique line. If there are many solutions, print any of them. | [
"1 48\n5 7\n",
"2 5\n0 1\n3 5\n"
] | [
"NO\n",
"YES\n1 4 "
] | none | 0 | [
{
"input": "1 48\n5 7",
"output": "NO"
},
{
"input": "2 5\n0 1\n3 5",
"output": "YES\n1 4 "
},
{
"input": "1 1\n5 6",
"output": "NO"
},
{
"input": "1 4\n2 4",
"output": "YES\n4 "
},
{
"input": "2 5\n4 6\n0 0",
"output": "YES\n5 0 "
},
{
"input": "27 97\n2 8\n0 5\n5 6\n3 6\n5 5\n1 2\n3 5\n1 8\n0 4\n3 3\n0 2\n0 0\n4 8\n5 6\n5 8\n0 7\n1 4\n0 4\n1 5\n3 7\n2 5\n5 6\n4 7\n3 8\n0 1\n3 4\n5 7",
"output": "YES\n8 5 6 6 5 2 5 8 4 3 2 0 6 5 5 0 1 0 1 3 2 5 4 3 0 3 5 "
},
{
"input": "30 92\n4 5\n4 7\n2 6\n8 8\n7 8\n4 5\n1 5\n7 8\n1 2\n6 8\n2 7\n2 4\n0 0\n1 3\n4 5\n1 1\n0 7\n2 5\n2 5\n3 3\n1 2\n1 7\n5 5\n5 8\n6 7\n0 3\n2 6\n0 7\n5 6\n2 5",
"output": "YES\n5 7 2 8 7 4 1 7 1 6 2 2 0 1 4 1 0 2 2 3 1 1 5 5 6 0 2 0 5 2 "
},
{
"input": "30 178\n1 6\n2 7\n2 5\n2 8\n1 6\n2 8\n3 4\n2 7\n0 2\n0 8\n0 3\n0 2\n2 4\n4 8\n6 8\n0 8\n0 6\n1 8\n0 3\n6 7\n4 8\n2 7\n1 1\n3 7\n3 6\n2 5\n4 7\n2 2\n1 8\n5 6",
"output": "NO"
},
{
"input": "30 71\n1 3\n0 6\n3 5\n3 6\n2 4\n2 8\n2 4\n3 8\n3 5\n2 4\n2 3\n3 7\n0 0\n5 7\n0 2\n5 8\n0 8\n4 7\n0 3\n3 7\n2 3\n4 5\n7 8\n7 7\n2 7\n1 3\n0 1\n1 5\n6 7\n5 8",
"output": "NO"
},
{
"input": "30 119\n2 7\n1 3\n0 3\n3 4\n7 7\n7 7\n0 5\n2 3\n0 8\n0 8\n0 5\n5 7\n2 2\n2 6\n2 5\n3 7\n0 8\n0 2\n1 3\n2 3\n1 4\n0 1\n3 7\n7 8\n1 2\n0 6\n1 8\n1 7\n4 8\n1 4",
"output": "YES\n7 3 3 4 7 7 5 3 8 8 5 7 2 6 5 7 8 2 1 2 1 0 3 7 1 0 1 1 4 1 "
},
{
"input": "1 0\n0 0",
"output": "YES\n0 "
},
{
"input": "30 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "YES\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 "
},
{
"input": "30 240\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8\n8 8",
"output": "YES\n8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 "
},
{
"input": "30 64\n7 7\n3 4\n0 4\n5 8\n1 3\n1 1\n0 2\n0 4\n7 7\n3 5\n4 4\n0 4\n4 5\n1 4\n4 6\n5 7\n1 4\n1 2\n3 3\n0 2\n3 7\n3 4\n0 3\n3 8\n0 8\n0 1\n0 3\n4 5\n1 5\n0 3",
"output": "YES\n7 3 0 5 1 1 0 0 7 3 4 0 4 1 4 5 1 1 3 0 3 3 0 3 0 0 0 4 1 0 "
},
{
"input": "30 189\n0 8\n3 8\n5 8\n2 2\n7 7\n2 8\n7 8\n2 5\n1 7\n0 1\n3 4\n1 7\n1 6\n5 6\n3 7\n4 7\n4 7\n4 7\n5 5\n0 5\n4 7\n3 5\n0 6\n4 8\n2 5\n5 6\n5 6\n2 8\n0 7\n7 8",
"output": "YES\n8 8 8 2 7 8 8 5 7 1 4 7 6 6 7 7 7 7 5 5 7 5 6 8 5 6 6 8 7 8 "
}
] | 1,689,531,697 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | d, sumTime = map(int, input().split())
days = []
for _ in range(d) :
days.append(tuple(map(int, input().split())))
minsum, maxsum = 0, 0
for day in days :
minsum += day[0]
maxsum += day[1]
if minsum > sumTime or sumTime > maxsum :
print("NO")
else :
print("YES")
k = minsum
i = 0
while k < sumTime :
ecart = days[i][1] - days[i][0]
if k + ecart <= sumTime :
k += ecart
print(days[i][1], end = " ")
else :
print(days[i][0] + sumTime - k, end=" ")
i += 1
break
i += 1
for j in range(i+1, d) :
print(days[j][0], end = " ") | Title: Before an Exam
Time Limit: 0 seconds
Memory Limit: 64 megabytes
Problem Description:
Tomorrow Peter has a Biology exam. He does not like this subject much, but *d* days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than *minTime**i* and not more than *maxTime**i* hours per each *i*-th day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.
So, today is the day when Peter's parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hours *sumTime* spent him on preparation, and now he wants to know if he can show his parents a timetable *sсhedule* with *d* numbers, where each number *sсhedule**i* stands for the time in hours spent by Peter each *i*-th day on biology studies, and satisfying the limitations imposed by his parents, and at the same time the sum total of all *schedule**i* should equal to *sumTime*.
Input Specification:
The first input line contains two integer numbers *d*,<=*sumTime* (1<=≤<=*d*<=≤<=30,<=0<=≤<=*sumTime*<=≤<=240) — the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following *d* lines contains two integer numbers *minTime**i*,<=*maxTime**i* (0<=≤<=*minTime**i*<=≤<=*maxTime**i*<=≤<=8), separated by a space — minimum and maximum amount of hours that Peter could spent in the *i*-th day.
Output Specification:
In the first line print YES, and in the second line print *d* numbers (separated by a space), each of the numbers — amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents' instructions; or print NO in the unique line. If there are many solutions, print any of them.
Demo Input:
['1 48\n5 7\n', '2 5\n0 1\n3 5\n']
Demo Output:
['NO\n', 'YES\n1 4 ']
Note:
none | ```python
d, sumTime = map(int, input().split())
days = []
for _ in range(d) :
days.append(tuple(map(int, input().split())))
minsum, maxsum = 0, 0
for day in days :
minsum += day[0]
maxsum += day[1]
if minsum > sumTime or sumTime > maxsum :
print("NO")
else :
print("YES")
k = minsum
i = 0
while k < sumTime :
ecart = days[i][1] - days[i][0]
if k + ecart <= sumTime :
k += ecart
print(days[i][1], end = " ")
else :
print(days[i][0] + sumTime - k, end=" ")
i += 1
break
i += 1
for j in range(i+1, d) :
print(days[j][0], end = " ")
``` | 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,541,440,180 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 0 | input();s=input().split();print(max((s.count(i) for i in set(s))),len(set(b))) | 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
input();s=input().split();print(max((s.count(i) for i in set(s))),len(set(b)))
``` | -1 |
940 | A | Points on the line | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"sortings"
] | null | null | We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
Diameter of multiset consisting of one point is 0.
You are given *n* points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed *d*? | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively.
The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points. | Output a single integer — the minimum number of points you have to remove. | [
"3 1\n2 1 4\n",
"3 0\n7 7 7\n",
"6 3\n1 3 4 6 9 10\n"
] | [
"1\n",
"0\n",
"3\n"
] | In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3. | 500 | [
{
"input": "3 1\n2 1 4",
"output": "1"
},
{
"input": "3 0\n7 7 7",
"output": "0"
},
{
"input": "6 3\n1 3 4 6 9 10",
"output": "3"
},
{
"input": "11 5\n10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "1 100\n1",
"output": "0"
},
{
"input": "100 10\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "84"
},
{
"input": "100 70\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "27"
},
{
"input": "1 10\n25",
"output": "0"
},
{
"input": "70 80\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",
"output": "0"
},
{
"input": "3 1\n25 26 27",
"output": "1"
},
{
"input": "100 5\n51 56 52 60 52 53 52 60 56 54 55 50 53 51 57 53 52 54 54 52 51 55 50 56 60 51 58 50 60 59 50 54 60 55 55 57 54 59 59 55 55 52 56 57 59 54 53 57 52 50 50 55 59 54 54 56 51 58 52 51 56 56 58 56 54 54 57 52 51 58 56 57 54 59 58 53 50 52 50 60 57 51 54 59 54 54 52 55 53 55 51 53 52 54 51 56 55 53 58 56",
"output": "34"
},
{
"input": "100 11\n44 89 57 64 94 96 73 96 55 52 91 73 73 93 51 62 63 85 43 75 60 78 98 55 80 84 65 75 61 88 62 71 53 57 94 85 60 96 66 96 61 72 97 64 51 44 63 82 67 86 60 57 74 85 57 79 61 94 86 78 84 56 60 75 91 91 92 62 89 85 79 57 76 97 65 56 46 78 51 69 50 52 85 80 76 71 81 51 90 71 77 60 63 62 84 59 79 84 69 81",
"output": "70"
},
{
"input": "100 0\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "96"
},
{
"input": "100 100\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "0"
},
{
"input": "76 32\n50 53 69 58 55 39 40 42 40 55 58 73 55 72 75 44 45 55 46 60 60 42 41 64 77 39 68 51 61 49 38 41 56 57 64 43 78 36 39 63 40 66 52 76 39 68 39 73 40 68 54 60 35 67 69 52 58 52 38 63 69 38 69 60 73 64 65 41 59 55 37 57 40 34 35 35",
"output": "13"
},
{
"input": "100 1\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "93"
},
{
"input": "100 5\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100",
"output": "89"
},
{
"input": "98 64\n2 29 36 55 58 15 25 33 7 16 61 1 4 24 63 26 36 16 16 3 57 39 56 7 11 24 20 12 22 10 56 5 11 39 61 52 27 54 21 6 61 36 40 52 54 5 15 52 58 23 45 39 65 16 27 40 13 64 47 24 51 29 9 18 49 49 8 47 2 64 7 63 49 10 20 26 34 3 45 66 8 46 16 32 16 38 3 6 15 17 35 48 36 5 57 29 61 15",
"output": "1"
},
{
"input": "100 56\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "43"
},
{
"input": "100 0\n14 13 14 13 14 13 13 13 13 14 13 13 14 14 13 14 14 14 14 13 13 13 14 13 13 14 14 14 14 14 14 13 13 13 13 14 13 14 13 14 13 14 14 14 14 13 13 14 14 13 13 13 13 14 13 14 13 14 13 14 13 13 13 14 13 13 14 13 14 14 13 13 13 14 14 14 14 13 13 14 14 14 14 14 14 14 13 14 13 13 13 14 14 13 13 13 13 13 14 14",
"output": "50"
},
{
"input": "100 0\n14 17 18 22 19 18 19 21 19 19 22 22 19 21 24 23 24 19 25 24 24 21 20 13 26 18 17 15 25 13 17 20 20 21 13 22 27 15 18 27 19 15 16 25 18 17 18 22 19 17 18 24 14 16 18 16 22 16 17 27 18 17 18 24 22 13 14 20 23 19 16 21 19 13 14 14 25 15 27 24 26 22 16 20 16 14 21 27 15 23 23 24 27 14 24 17 19 24 15 27",
"output": "89"
},
{
"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": "1 100\n22",
"output": "0"
},
{
"input": "1 0\n22",
"output": "0"
},
{
"input": "1 99\n99",
"output": "0"
},
{
"input": "1 5\n6",
"output": "0"
},
{
"input": "3 1\n10 20 30",
"output": "2"
},
{
"input": "3 0\n1 2 3",
"output": "2"
},
{
"input": "3 2\n1 50 99",
"output": "2"
},
{
"input": "7 4\n1 3 4 9 10 11 12",
"output": "3"
},
{
"input": "2 5\n67 23",
"output": "1"
},
{
"input": "4 2\n1 4 7 9",
"output": "2"
},
{
"input": "2 0\n1 2",
"output": "1"
},
{
"input": "8 1\n3 3 3 5 5 5 5 5",
"output": "3"
},
{
"input": "5 1\n3 5 5 5 6",
"output": "1"
}
] | 1,570,183,390 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 108 | 0 | n,d= map(int,input().split())
a= list(map(int,input().split()))
a.sort()
c=0
while a[-1]- a[0]> d:
a= a[:n-1]
n= n-1
c+=1
print(c)
| Title: Points on the line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
Diameter of multiset consisting of one point is 0.
You are given *n* points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed *d*?
Input Specification:
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively.
The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points.
Output Specification:
Output a single integer — the minimum number of points you have to remove.
Demo Input:
['3 1\n2 1 4\n', '3 0\n7 7 7\n', '6 3\n1 3 4 6 9 10\n']
Demo Output:
['1\n', '0\n', '3\n']
Note:
In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3. | ```python
n,d= map(int,input().split())
a= list(map(int,input().split()))
a.sort()
c=0
while a[-1]- a[0]> d:
a= a[:n-1]
n= n-1
c+=1
print(c)
``` | 0 |
|
441 | A | Valera and Antique Items | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him.
Unfortunately, Valera has only *v* units of money. Help him to determine which of the *n* sellers he can make a deal with. | The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has.
Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space-separated integers *s**i*1,<=*s**i*2,<=...,<=*s**ik**i* (104<=≤<=*s**ij*<=≤<=106) — the current prices of the items of the *i*-th seller. | In the first line, print integer *p* — the number of sellers with who Valera can make a deal.
In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order. | [
"3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n",
"3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n"
] | [
"3\n1 2 3\n",
"0\n\n"
] | In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.
In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the auction too big for him. | 500 | [
{
"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000",
"output": "3\n1 2 3"
},
{
"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000",
"output": "0"
},
{
"input": "2 100001\n1 895737\n1 541571",
"output": "0"
},
{
"input": "1 1000000\n1 1000000",
"output": "0"
},
{
"input": "1 1000000\n1 561774",
"output": "1\n1"
},
{
"input": "3 1000000\n5 1000000 568832 1000000 1000000 1000000\n13 1000000 1000000 1000000 596527 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n20 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000",
"output": "2\n1 2"
},
{
"input": "3 999999\n7 1000000 1000000 1000000 999999 1000000 999999 1000000\n6 999999 1000000 999999 1000000 999999 999999\n7 999999 1000000 1000000 999999 1000000 1000000 1000000",
"output": "0"
},
{
"input": "3 999999\n22 1000000 1000000 999999 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 999999 1000000 1000000 1000000 352800 999999 1000000\n14 999999 999999 999999 999999 999999 1000000 999999 999999 999999 999999 702638 999999 1000000 999999\n5 999999 1000000 1000000 999999 363236",
"output": "3\n1 2 3"
},
{
"input": "1 50001\n1 50000",
"output": "1\n1"
}
] | 1,651,328,630 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 15 | 0 | import sys
input = sys.stdin.readline
n, v = map(int, input().split())
d = []
for _ in range(n):
w = list(map(int, input().split()))
a = w[0]
b = sorted(w[1:])
if b[0] < v:
d.append(a)
print(len(d))
print(*d)
| Title: Valera and Antique Items
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him.
Unfortunately, Valera has only *v* units of money. Help him to determine which of the *n* sellers he can make a deal with.
Input Specification:
The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has.
Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space-separated integers *s**i*1,<=*s**i*2,<=...,<=*s**ik**i* (104<=≤<=*s**ij*<=≤<=106) — the current prices of the items of the *i*-th seller.
Output Specification:
In the first line, print integer *p* — the number of sellers with who Valera can make a deal.
In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
Demo Input:
['3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n', '3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n']
Demo Output:
['3\n1 2 3\n', '0\n\n']
Note:
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.
In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the auction too big for him. | ```python
import sys
input = sys.stdin.readline
n, v = map(int, input().split())
d = []
for _ in range(n):
w = list(map(int, input().split()))
a = w[0]
b = sorted(w[1:])
if b[0] < v:
d.append(a)
print(len(d))
print(*d)
``` | 0 |
|
315 | A | Sereja and Bottles | PROGRAMMING | 1,400 | [
"brute force"
] | null | null | Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle. | In a single line print a single integer — the answer to the problem. | [
"4\n1 1\n2 2\n3 3\n4 4\n",
"4\n1 2\n2 3\n3 4\n4 1\n"
] | [
"4\n",
"0\n"
] | none | 500 | [
{
"input": "4\n1 1\n2 2\n3 3\n4 4",
"output": "4"
},
{
"input": "4\n1 2\n2 3\n3 4\n4 1",
"output": "0"
},
{
"input": "3\n2 828\n4 392\n4 903",
"output": "3"
},
{
"input": "4\n2 3\n1 772\n3 870\n3 668",
"output": "2"
},
{
"input": "5\n1 4\n6 6\n4 3\n3 4\n4 758",
"output": "2"
},
{
"input": "6\n4 843\n2 107\n10 943\n9 649\n7 806\n6 730",
"output": "6"
},
{
"input": "7\n351 955\n7 841\n102 377\n394 102\n549 440\n630 324\n624 624",
"output": "6"
},
{
"input": "8\n83 978\n930 674\n542 22\n834 116\n116 271\n640 930\n659 930\n705 987",
"output": "6"
},
{
"input": "9\n162 942\n637 967\n356 108\n768 53\n656 656\n575 32\n32 575\n53 53\n351 222",
"output": "6"
},
{
"input": "10\n423 360\n947 538\n507 484\n31 947\n414 351\n169 901\n901 21\n592 22\n763 200\n656 485",
"output": "8"
},
{
"input": "1\n1000 1000",
"output": "1"
},
{
"input": "1\n500 1000",
"output": "1"
},
{
"input": "11\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11",
"output": "11"
},
{
"input": "49\n1 758\n5 3\n5 3\n4 2\n4 36\n3 843\n5 107\n1 943\n1 649\n2 806\n3 730\n2 351\n2 102\n1 4\n3 4\n3 955\n2 841\n2 377\n5 2\n3 440\n4 324\n3 3\n3 83\n2 2\n2 1\n4 1\n1 931\n3 4\n2 5\n2 5\n4 73\n5 830\n3 4\n3 5\n5 291\n1 2\n5 3\n4 4\n2 3\n3 151\n4 2\n4 431\n5 1\n2 5\n2 4\n4 2\n4 4\n3 1\n5 2",
"output": "0"
},
{
"input": "50\n507 31\n31 250\n414 763\n169 304\n901 9\n592 610\n763 414\n656 789\n411 422\n360 468\n625 504\n538 201\n549 619\n484 797\n596 282\n42 310\n603 656\n351 623\n292 293\n837 180\n375 658\n21 192\n597 729\n22 512\n349 635\n200 56\n669 647\n485 887\n282 939\n735 808\n54 417\n1000 310\n419 652\n939 617\n901 669\n789 390\n128 549\n468 511\n729 837\n894 729\n649 894\n484 22\n808 586\n422 286\n311 427\n618 656\n814 933\n515 901\n310 894\n617 330",
"output": "30"
},
{
"input": "2\n7 7\n5 359",
"output": "2"
},
{
"input": "2\n465 706\n706 706",
"output": "1"
},
{
"input": "2\n1 1\n1 1",
"output": "0"
},
{
"input": "3\n1 1\n1 1\n2 2",
"output": "1"
},
{
"input": "5\n1 1\n1 2\n2 3\n3 4\n4 3",
"output": "1"
},
{
"input": "3\n1 2\n1 2\n1 1",
"output": "1"
}
] | 1,615,154,298 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 409,600 | from collections import Counter
n = int(input())
a, b = [], []
for i in range(n):
x, y =map(int, input().split())
a.append(x)
b.append(y)
check = [1]*n
for i in range(n):
for j in range(n):
if a[j] == b[i] and i!=j:
check[j] = 0
print(sum(check)) | Title: Sereja and Bottles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle.
Output Specification:
In a single line print a single integer — the answer to the problem.
Demo Input:
['4\n1 1\n2 2\n3 3\n4 4\n', '4\n1 2\n2 3\n3 4\n4 1\n']
Demo Output:
['4\n', '0\n']
Note:
none | ```python
from collections import Counter
n = int(input())
a, b = [], []
for i in range(n):
x, y =map(int, input().split())
a.append(x)
b.append(y)
check = [1]*n
for i in range(n):
for j in range(n):
if a[j] == b[i] and i!=j:
check[j] = 0
print(sum(check))
``` | 3 |
|
13 | A | Numbers | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10. | Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). | Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | 0 | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
"input": "386",
"output": "857/12"
},
{
"input": "277",
"output": "2864/55"
},
{
"input": "766",
"output": "53217/382"
},
{
"input": "28",
"output": "85/13"
},
{
"input": "406",
"output": "7560/101"
},
{
"input": "757",
"output": "103847/755"
},
{
"input": "6",
"output": "9/4"
},
{
"input": "239",
"output": "10885/237"
},
{
"input": "322",
"output": "2399/40"
},
{
"input": "98",
"output": "317/16"
},
{
"input": "208",
"output": "4063/103"
},
{
"input": "786",
"output": "55777/392"
},
{
"input": "879",
"output": "140290/877"
},
{
"input": "702",
"output": "89217/700"
},
{
"input": "948",
"output": "7369/43"
},
{
"input": "537",
"output": "52753/535"
},
{
"input": "984",
"output": "174589/982"
},
{
"input": "934",
"output": "157951/932"
},
{
"input": "726",
"output": "95491/724"
},
{
"input": "127",
"output": "3154/125"
},
{
"input": "504",
"output": "23086/251"
},
{
"input": "125",
"output": "3080/123"
},
{
"input": "604",
"output": "33178/301"
},
{
"input": "115",
"output": "2600/113"
},
{
"input": "27",
"output": "167/25"
},
{
"input": "687",
"output": "85854/685"
},
{
"input": "880",
"output": "69915/439"
},
{
"input": "173",
"output": "640/19"
},
{
"input": "264",
"output": "6438/131"
},
{
"input": "785",
"output": "111560/783"
},
{
"input": "399",
"output": "29399/397"
},
{
"input": "514",
"output": "6031/64"
},
{
"input": "381",
"output": "26717/379"
},
{
"input": "592",
"output": "63769/590"
},
{
"input": "417",
"output": "32002/415"
},
{
"input": "588",
"output": "62723/586"
},
{
"input": "852",
"output": "131069/850"
},
{
"input": "959",
"output": "5059/29"
},
{
"input": "841",
"output": "127737/839"
},
{
"input": "733",
"output": "97598/731"
},
{
"input": "692",
"output": "87017/690"
},
{
"input": "69",
"output": "983/67"
},
{
"input": "223",
"output": "556/13"
},
{
"input": "93",
"output": "246/13"
},
{
"input": "643",
"output": "75503/641"
},
{
"input": "119",
"output": "2833/117"
},
{
"input": "498",
"output": "1459/16"
},
{
"input": "155",
"output": "4637/153"
},
{
"input": "305",
"output": "17350/303"
},
{
"input": "454",
"output": "37893/452"
},
{
"input": "88",
"output": "1529/86"
},
{
"input": "850",
"output": "32645/212"
},
{
"input": "474",
"output": "20581/236"
},
{
"input": "309",
"output": "17731/307"
},
{
"input": "762",
"output": "105083/760"
},
{
"input": "591",
"output": "63761/589"
},
{
"input": "457",
"output": "38317/455"
},
{
"input": "141",
"output": "3832/139"
},
{
"input": "385",
"output": "27232/383"
},
{
"input": "387",
"output": "27628/385"
},
{
"input": "469",
"output": "40306/467"
},
{
"input": "624",
"output": "35285/311"
},
{
"input": "330",
"output": "487/8"
},
{
"input": "31",
"output": "222/29"
},
{
"input": "975",
"output": "171679/973"
},
{
"input": "584",
"output": "62183/582"
},
{
"input": "668",
"output": "81127/666"
},
{
"input": "331",
"output": "20297/329"
},
{
"input": "189",
"output": "6789/187"
},
{
"input": "251",
"output": "11939/249"
},
{
"input": "876",
"output": "69196/437"
},
{
"input": "615",
"output": "68987/613"
},
{
"input": "451",
"output": "37258/449"
},
{
"input": "499",
"output": "45727/497"
},
{
"input": "699",
"output": "89117/697"
},
{
"input": "619",
"output": "70019/617"
},
{
"input": "413",
"output": "10515/137"
},
{
"input": "197",
"output": "7399/195"
},
{
"input": "794",
"output": "14281/99"
},
{
"input": "659",
"output": "79403/657"
},
{
"input": "653",
"output": "77695/651"
},
{
"input": "23",
"output": "45/7"
},
{
"input": "430",
"output": "16985/214"
},
{
"input": "249",
"output": "11659/247"
},
{
"input": "837",
"output": "126869/835"
},
{
"input": "258",
"output": "12373/256"
},
{
"input": "995",
"output": "59665/331"
},
{
"input": "102",
"output": "504/25"
},
{
"input": "989",
"output": "177124/987"
},
{
"input": "376",
"output": "13008/187"
},
{
"input": "657",
"output": "15715/131"
},
{
"input": "746",
"output": "50509/372"
},
{
"input": "602",
"output": "13177/120"
}
] | 1,607,693,409 | 2,147,483,647 | PyPy 3 | OK | TESTS | 99 | 654 | 10,137,600 | from fractions import Fraction
s = 0
a = int(input())
for i in range(2, a):
k = a
while k:
s += k % i
k //= i
f = Fraction(s, (a - 2))
print(f.numerator, "/", f.denominator, sep="")
| Title: Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10.
Input Specification:
Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000).
Output Specification:
Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator.
Demo Input:
['5\n', '3\n']
Demo Output:
['7/3\n', '2/1\n']
Note:
In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | ```python
from fractions import Fraction
s = 0
a = int(input())
for i in range(2, a):
k = a
while k:
s += k % i
k //= i
f = Fraction(s, (a - 2))
print(f.numerator, "/", f.denominator, sep="")
``` | 3.597469 |
772 | A | Voltage Keepsake | PROGRAMMING | 1,800 | [
"binary search",
"math"
] | null | null | You have *n* devices that you want to use simultaneously.
The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-th device currently has *b**i* units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add *p* units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·*p* units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. | The first line contains two integers, *n* and *p* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*p*<=≤<=109) — the number of devices and the power of the charger.
This is followed by *n* lines which contain two integers each. Line *i* contains the integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100<=000) — the power of the device and the amount of power stored in the device in the beginning. | If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4.
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 1\n2 2\n2 1000\n",
"1 100\n1 1\n",
"3 5\n4 3\n5 2\n6 1\n"
] | [
"2.0000000000",
"-1\n",
"0.5000000000"
] | In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. | 500 | [
{
"input": "2 1\n2 2\n2 1000",
"output": "2.0000000000"
},
{
"input": "1 100\n1 1",
"output": "-1"
},
{
"input": "3 5\n4 3\n5 2\n6 1",
"output": "0.5000000000"
},
{
"input": "1 1\n1 87",
"output": "-1"
},
{
"input": "1 1\n100 77",
"output": "0.7777777778"
},
{
"input": "5 10\n3 81\n3 49\n1 20\n1 12\n1 30",
"output": "-1"
},
{
"input": "5 10\n4 3\n1 54\n2 57\n2 31\n1 99",
"output": "-1"
},
{
"input": "5 10\n2 81\n3 31\n4 49\n1 35\n1 67",
"output": "263.0000000000"
},
{
"input": "10 1\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92",
"output": "102.2222222222"
},
{
"input": "10 1\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16",
"output": "17.7777777778"
},
{
"input": "10 1\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40",
"output": "44.4444444444"
},
{
"input": "2 1\n1 10\n1 10",
"output": "20.0000000000"
},
{
"input": "20 16807\n75250 50074\n43659 8931\n11273 27545\n50879 77924\n37710 64441\n38166 84493\n43043 7988\n22504 82328\n31730 78841\n42613 44304\n33170 17710\n97158 29561\n70934 93100\n80279 51817\n95336 99098\n7827 13513\n29268 23811\n77634 80980\n79150 36580\n58822 11968",
"output": "0.2244225704"
}
] | 1,690,488,517 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | print("_RANDOM_GUESS_1690488517.8385348")# 1690488517.8385549 | Title: Voltage Keepsake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *n* devices that you want to use simultaneously.
The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-th device currently has *b**i* units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add *p* units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·*p* units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input Specification:
The first line contains two integers, *n* and *p* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*p*<=≤<=109) — the number of devices and the power of the charger.
This is followed by *n* lines which contain two integers each. Line *i* contains the integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100<=000) — the power of the device and the amount of power stored in the device in the beginning.
Output Specification:
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4.
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 1\n2 2\n2 1000\n', '1 100\n1 1\n', '3 5\n4 3\n5 2\n6 1\n']
Demo Output:
['2.0000000000', '-1\n', '0.5000000000']
Note:
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. | ```python
print("_RANDOM_GUESS_1690488517.8385348")# 1690488517.8385549
``` | 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,678,692,107 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 0 | s = input()
k = 0
m = 0
for i in s:
if i.isupper():
k += 1
else:
m += 1
if k > m:
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()
k = 0
m = 0
for i in s:
if i.isupper():
k += 1
else:
m += 1
if k > m:
print(s.upper())
else:
print(s.lower())
``` | 3.969 |
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,638,452,016 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | # Author : Ghulam Junaid
lenn = int(input())
string = input()
count = 0
list1 = []
iter1 = 0
for i in string:
iter1+=1
if i=='B':
count+=1
elif count>0:
list1.append(count)
count=0
if iter1==lenn:
if count>0:
list1.append(count)
print(len(list1))
ans = str(list1)
ans = ans.replace(',','')
ans = ans.replace(']','')
ans = ans.replace('[','')
if len(ans)>0:
print(ans)
| 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
# Author : Ghulam Junaid
lenn = int(input())
string = input()
count = 0
list1 = []
iter1 = 0
for i in string:
iter1+=1
if i=='B':
count+=1
elif count>0:
list1.append(count)
count=0
if iter1==lenn:
if count>0:
list1.append(count)
print(len(list1))
ans = str(list1)
ans = ans.replace(',','')
ans = ans.replace(']','')
ans = ans.replace('[','')
if len(ans)>0:
print(ans)
``` | 3 |
|
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.
Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement.
- The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1\n0 1\n1 0\n1 0",
"output": "2"
},
{
"input": "3\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "5\n0 73\n73 189\n189 766\n766 0\n0 0",
"output": "766"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 1\n1 0",
"output": "1"
},
{
"input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0",
"output": "1011"
},
{
"input": "5\n0 1\n1 2\n2 1\n1 2\n2 0",
"output": "2"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0",
"output": "22"
},
{
"input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0",
"output": "1776"
},
{
"input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0",
"output": "2"
},
{
"input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0",
"output": "1016"
},
{
"input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0",
"output": "3"
},
{
"input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0",
"output": "2071"
},
{
"input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0",
"output": "3"
},
{
"input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0",
"output": "1329"
},
{
"input": "2\n0 863\n863 0",
"output": "863"
},
{
"input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0",
"output": "8"
},
{
"input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0",
"output": "11"
},
{
"input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0",
"output": "7"
},
{
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "2\n0 900\n900 0",
"output": "900"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "2\n0 1000\n1000 0",
"output": "1000"
},
{
"input": "3\n0 802\n175 188\n815 0",
"output": "815"
},
{
"input": "3\n0 910\n910 976\n976 0",
"output": "976"
},
{
"input": "3\n0 2\n2 1\n1 0",
"output": "2"
}
] | 1,685,888,129 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 62 | 0 | n = int(input())
if n < 2 or n > 1000:
raise ValueError
stat=0
stats=[]
for i in range(n):
inp=input()
out=int(inp[0])
inc=int(inp[2])
if out < 0 or out > 1000:
raise ValueError
if inc < 0 or inc > 1000:
raise ValueError
stat=stat-out+inc
stats.append(stat)
print(max(stats)) | Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.
Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Input Specification:
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement.
- The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Output Specification:
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
Demo Input:
['4\n0 3\n2 5\n4 2\n4 0\n']
Demo Output:
['6\n']
Note:
For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | ```python
n = int(input())
if n < 2 or n > 1000:
raise ValueError
stat=0
stats=[]
for i in range(n):
inp=input()
out=int(inp[0])
inc=int(inp[2])
if out < 0 or out > 1000:
raise ValueError
if inc < 0 or inc > 1000:
raise ValueError
stat=stat-out+inc
stats.append(stat)
print(max(stats))
``` | -1 |
|
632 | C | The Smallest String Concatenation | PROGRAMMING | 1,700 | [
"sortings",
"strings"
] | null | null | You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list of strings, output the lexicographically smallest concatenation. | The first line contains integer *n* — the number of strings (1<=≤<=*n*<=≤<=5·104).
Each of the next *n* lines contains one string *a**i* (1<=≤<=|*a**i*|<=≤<=50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104. | Print the only string *a* — the lexicographically smallest string concatenation. | [
"4\nabba\nabacaba\nbcd\ner\n",
"5\nx\nxx\nxxa\nxxaa\nxxaaa\n",
"3\nc\ncb\ncba\n"
] | [
"abacabaabbabcder\n",
"xxaaaxxaaxxaxxx\n",
"cbacbc\n"
] | none | 0 | [
{
"input": "4\nabba\nabacaba\nbcd\ner",
"output": "abacabaabbabcder"
},
{
"input": "5\nx\nxx\nxxa\nxxaa\nxxaaa",
"output": "xxaaaxxaaxxaxxx"
},
{
"input": "3\nc\ncb\ncba",
"output": "cbacbc"
},
{
"input": "10\naba\nabaaca\naba\nacaaaabbac\nabaacac\nb\ncabbcccaab\nbaacbb\nbcab\ncc",
"output": "abaabaabaacaabaacacacaaaabbacbaacbbbbcabcabbcccaabcc"
},
{
"input": "13\nclgknjjojyuvdtv\nclgknjjojyuvdtvzxz\nclgknjjojyuvdtvzxzxradqhm\ngvzpnckalbaubfviyhijosiixvxaydxagvymq\nclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymt\nbvwzpuut\nclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymth\nclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymtlkdl\nrbwvaayhhunlvmwexvkmqbquypsnjbdkkeytthekttywypud\nqlvkfkshkxyrfefigtngifxsuhpjgkb\nlhxtkfjrrwcvzuamizotupjqckaq\nenngvhxvpaoiyhctddyscasyqtilvbvgfphayykjeoylcvmjz\nxkazwk",
"output": "bvwzpuutclgknjjojyuvdtvclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymtclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymthclgknjjojyuvdtvjgcwarwvgilcctdiytmvmvfxxkezymtlkdlclgknjjojyuvdtvzxzclgknjjojyuvdtvzxzxradqhmenngvhxvpaoiyhctddyscasyqtilvbvgfphayykjeoylcvmjzgvzpnckalbaubfviyhijosiixvxaydxagvymqlhxtkfjrrwcvzuamizotupjqckaqqlvkfkshkxyrfefigtngifxsuhpjgkbrbwvaayhhunlvmwexvkmqbquypsnjbdkkeytthekttywypudxkazwk"
}
] | 1,464,466,539 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 5,427,200 | from sys import stdin
from functools import cmp_to_key
def input() :
return stdin.readline()
n=int(input())
strings=[]
forsort=[]
ans=[]
for i in range(n) :
t=input().strip('\n')
strings.append(t)
lt=len(t)
t=t+t[lt-1]*(50-lt)
forsort.append((t,i))
forsort.sort()
forsort.append(('END',-1))
last=forsort[0][0]
tlist=[]
for i in range(n+1) :
now=forsort[i][0]
if not last==now :
tlist=[i[::-1] for i in tlist]
tlist.sort()
tlist=[i[::-1] for i in tlist]
ans+=tlist
tlist=[]
last=forsort[i][0]
tlist.append(strings[forsort[i][1]])
else :
tlist.append(strings[forsort[i][1]])
print(tlist)
print("".join(ans)) | Title: The Smallest String Concatenation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list of strings, output the lexicographically smallest concatenation.
Input Specification:
The first line contains integer *n* — the number of strings (1<=≤<=*n*<=≤<=5·104).
Each of the next *n* lines contains one string *a**i* (1<=≤<=|*a**i*|<=≤<=50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104.
Output Specification:
Print the only string *a* — the lexicographically smallest string concatenation.
Demo Input:
['4\nabba\nabacaba\nbcd\ner\n', '5\nx\nxx\nxxa\nxxaa\nxxaaa\n', '3\nc\ncb\ncba\n']
Demo Output:
['abacabaabbabcder\n', 'xxaaaxxaaxxaxxx\n', 'cbacbc\n']
Note:
none | ```python
from sys import stdin
from functools import cmp_to_key
def input() :
return stdin.readline()
n=int(input())
strings=[]
forsort=[]
ans=[]
for i in range(n) :
t=input().strip('\n')
strings.append(t)
lt=len(t)
t=t+t[lt-1]*(50-lt)
forsort.append((t,i))
forsort.sort()
forsort.append(('END',-1))
last=forsort[0][0]
tlist=[]
for i in range(n+1) :
now=forsort[i][0]
if not last==now :
tlist=[i[::-1] for i in tlist]
tlist.sort()
tlist=[i[::-1] for i in tlist]
ans+=tlist
tlist=[]
last=forsort[i][0]
tlist.append(strings[forsort[i][1]])
else :
tlist.append(strings[forsort[i][1]])
print(tlist)
print("".join(ans))
``` | 0 |
|
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,330,412 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | def lvlgame():
goalInt = int(input())
# Read the first line of numbers
li1 = input()
numbers1 = [int(x) for x in li1.split()]
# Read the second line of numbers
li2 = input()
numbers2 = [int(x) for x in li2.split()]
# Concatenate the two lists of numbers
num3 = numbers1 + numbers2
num3.sort()
y = len(num3)
if num3[y - 1] >= goalInt:
return "I become the guy."
return "Oh, my keyboard!"
# Call the function to test it
result = lvlgame()
print(result)
| 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
def lvlgame():
goalInt = int(input())
# Read the first line of numbers
li1 = input()
numbers1 = [int(x) for x in li1.split()]
# Read the second line of numbers
li2 = input()
numbers2 = [int(x) for x in li2.split()]
# Concatenate the two lists of numbers
num3 = numbers1 + numbers2
num3.sort()
y = len(num3)
if num3[y - 1] >= goalInt:
return "I become the guy."
return "Oh, my keyboard!"
# Call the function to test it
result = lvlgame()
print(result)
``` | 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,558,813,662 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 109 | 0 | a, b = map(int, input().split())
ans = 1
a += 1
while a <= b and ans > 0:
ans = (ans * a) % 10
a += 1
print(ans) | 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
a, b = map(int, input().split())
ans = 1
a += 1
while a <= b and ans > 0:
ans = (ans * a) % 10
a += 1
print(ans)
``` | 3 |
|
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*? | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a regular triangle, and in the last test case — a square. | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,647,455,806 | 2,147,483,647 | Python 3 | OK | TESTS | 3 | 92 | 0 | t=int(input())
for i in range(t):
a=int(input())
if a>=30 and a<180:
thet = 180-a
if 360%thet==0:
print("YES")
else:
print("NO")
else:
print("NO") | Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*?
Input Specification:
The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees.
Output Specification:
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
Demo Input:
['3\n30\n60\n90\n']
Demo Output:
['NO\nYES\nYES\n']
Note:
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a regular triangle, and in the last test case — a square. | ```python
t=int(input())
for i in range(t):
a=int(input())
if a>=30 and a<180:
thet = 180-a
if 360%thet==0:
print("YES")
else:
print("NO")
else:
print("NO")
``` | 3 |
|
812 | C | Sagheer and Nubian Market | PROGRAMMING | 1,500 | [
"binary search",
"sortings"
] | null | null | On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. The *i*-th item has base cost *a**i* Egyptian pounds. If Sagheer buys *k* items with indices *x*1,<=*x*2,<=...,<=*x**k*, then the cost of item *x**j* is *a**x**j*<=+<=*x**j*·*k* for 1<=≤<=*j*<=≤<=*k*. In other words, the cost of an item is equal to its base cost in addition to its index multiplied by the factor *k*.
Sagheer wants to buy as many souvenirs as possible without paying more than *S* Egyptian pounds. Note that he cannot buy a souvenir more than once. If there are many ways to maximize the number of souvenirs, he will choose the way that will minimize the total cost. Can you help him with this task? | The first line contains two integers *n* and *S* (1<=≤<=*n*<=≤<=105 and 1<=≤<=*S*<=≤<=109) — the number of souvenirs in the market and Sagheer's budget.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the base costs of the souvenirs. | On a single line, print two integers *k*, *T* — the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these *k* souvenirs. | [
"3 11\n2 3 5\n",
"4 100\n1 2 5 6\n",
"1 7\n7\n"
] | [
"2 11\n",
"4 54\n",
"0 0\n"
] | In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.
In the second example, he can buy all items as they will cost him [5, 10, 17, 22].
In the third example, there is only one souvenir in the market which will cost him 8 pounds, so he cannot buy it. | 1,500 | [
{
"input": "3 11\n2 3 5",
"output": "2 11"
},
{
"input": "4 100\n1 2 5 6",
"output": "4 54"
},
{
"input": "1 7\n7",
"output": "0 0"
},
{
"input": "1 7\n5",
"output": "1 6"
},
{
"input": "1 1\n1",
"output": "0 0"
},
{
"input": "4 33\n4 3 2 1",
"output": "3 27"
},
{
"input": "86 96\n89 48 14 55 5 35 7 79 49 70 74 18 64 63 35 93 63 97 90 77 33 11 100 75 60 99 54 38 3 6 55 1 7 64 56 90 21 76 35 16 61 78 38 78 93 21 89 1 58 53 34 77 56 37 46 59 30 5 85 1 52 87 84 99 97 9 15 66 29 60 17 16 59 23 88 93 32 2 98 89 63 42 9 86 70 80",
"output": "3 71"
},
{
"input": "9 2727\n73 41 68 90 51 7 20 48 69",
"output": "9 872"
},
{
"input": "35 792600\n61 11 82 29 3 50 65 60 62 86 83 78 15 82 7 77 38 87 100 12 93 86 96 79 14 58 60 47 94 39 36 23 69 93 18",
"output": "35 24043"
},
{
"input": "63 47677090\n53 4 59 68 6 12 47 63 28 93 9 53 61 63 53 70 77 63 49 76 70 23 4 40 4 34 24 70 42 83 84 95 11 46 38 83 26 85 34 29 67 96 3 62 97 7 42 65 49 45 50 54 81 74 83 59 10 87 95 87 89 27 3",
"output": "63 130272"
},
{
"input": "88 631662736\n93 75 25 7 6 55 92 23 22 32 4 48 61 29 91 79 16 18 18 9 66 9 57 62 3 81 48 16 21 90 93 58 30 8 31 47 44 70 34 85 52 71 58 42 99 53 43 54 96 26 6 13 38 4 13 60 1 48 32 100 52 8 27 99 66 34 98 45 19 50 37 59 31 56 58 70 61 14 100 66 74 85 64 57 92 89 7 92",
"output": "88 348883"
},
{
"input": "12 12\n1232 1848 2048 4694 5121 3735 9968 4687 2040 6033 5839 2507",
"output": "0 0"
},
{
"input": "37 5271\n368 6194 4856 8534 944 4953 2085 5350 788 7772 9786 1321 4310 4453 7078 9912 5799 4066 5471 5079 5161 9773 1300 5474 1202 1353 9499 9694 9020 6332 595 7619 1271 7430 1199 3127 8867",
"output": "5 4252"
},
{
"input": "65 958484\n9597 1867 5346 637 6115 5833 3318 6059 4430 9169 8155 7895 3534 7962 9900 9495 5694 3461 5370 1945 1724 9264 3475 618 3421 551 8359 6889 1843 6716 9216 2356 1592 6265 2945 6496 4947 2840 9057 6141 887 4823 4004 8027 1993 1391 796 7059 5500 4369 4012 4983 6495 8990 3633 5439 421 1129 6970 8796 7826 1200 8741 6555 5037",
"output": "65 468998"
},
{
"input": "90 61394040\n2480 6212 4506 829 8191 797 5336 6722 3178 1007 5849 3061 3588 6684 5983 5452 7654 5321 660 2569 2809 2179 679 4858 6887 2580 6880 6120 4159 5542 4999 8703 2386 8221 7046 1229 1662 4542 7089 3548 4298 1973 1854 2473 5507 241 359 5248 7907 5201 9624 4596 1723 2622 4800 4716 693 961 7402 9004 7994 8048 6590 5866 7502 3304 4331 5218 6906 1016 5342 6644 2205 5823 8525 4839 1914 2651 3940 7751 3489 4178 7234 6640 7602 9765 8559 7819 5827 163",
"output": "90 795634"
},
{
"input": "14 891190480\n1424 3077 9632 6506 4568 9650 5534 1085 6934 9340 2867 367 7075 618",
"output": "14 70147"
},
{
"input": "39 43\n22166 81842 15513 80979 39645 60168 96994 13493 12904 79871 49910 45356 93691 51829 18226 34288 11525 41944 40433 67295 30123 1081 55623 22279 75814 82316 2963 39329 38223 8445 43202 61912 15122 86367 37200 68113 57194 38541 49641",
"output": "0 0"
},
{
"input": "67 8824\n75515 67590 86373 34191 3446 27408 31581 24727 40005 23718 39738 30960 4786 51040 32590 80454 14335 47173 20079 41204 67289 58347 88969 88396 37681 43963 13886 85690 12259 14732 42036 62620 15011 41890 20150 59469 62104 30136 47163 19790 25699 27453 36151 52914 52684 20503 78622 81082 94500 55756 94030 54764 72763 37830 13210 64559 53600 87998 80472 19001 83769 79700 88794 10161 99980 95184 74439",
"output": "2 8268"
},
{
"input": "16 56532535\n84567 85265 99012 62115 58908 10120 27355 90226 17191 35588 43807 6327 89157 71156 16253 22387",
"output": "16 821610"
},
{
"input": "42 818723640\n57019 99450 43192 25131 80678 41786 52490 34454 51620 56132 41773 94622 23949 11597 96944 51420 44164 85727 72959 26622 1838 36302 99335 35572 92734 10651 22293 97601 38634 24066 81870 10904 5825 71968 2377 61198 3104 4191 97851 99920 65295 1385",
"output": "42 2094569"
}
] | 1,535,669,524 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 607 | 7,372,800 | from heapq import heappop, heapify
def main():
def helper(e):
if e:
l = [a + b for a, b in zip(aa, range(e, (e + 1) * n, e))]
heapify(l)
return sum(heappop(l) for _ in range(e))
return 0
n, s = map(int, input().split())
aa = list(map(int, input().split()))
lo, hi = 0, n
while lo < hi:
mid = (lo + hi + 1) // 2
t = helper(mid)
if s < t:
hi = mid - 1
else:
lo = mid
print(lo, helper(lo))
if __name__ == '__main__':
main()
| Title: Sagheer and Nubian Market
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. The *i*-th item has base cost *a**i* Egyptian pounds. If Sagheer buys *k* items with indices *x*1,<=*x*2,<=...,<=*x**k*, then the cost of item *x**j* is *a**x**j*<=+<=*x**j*·*k* for 1<=≤<=*j*<=≤<=*k*. In other words, the cost of an item is equal to its base cost in addition to its index multiplied by the factor *k*.
Sagheer wants to buy as many souvenirs as possible without paying more than *S* Egyptian pounds. Note that he cannot buy a souvenir more than once. If there are many ways to maximize the number of souvenirs, he will choose the way that will minimize the total cost. Can you help him with this task?
Input Specification:
The first line contains two integers *n* and *S* (1<=≤<=*n*<=≤<=105 and 1<=≤<=*S*<=≤<=109) — the number of souvenirs in the market and Sagheer's budget.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the base costs of the souvenirs.
Output Specification:
On a single line, print two integers *k*, *T* — the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these *k* souvenirs.
Demo Input:
['3 11\n2 3 5\n', '4 100\n1 2 5 6\n', '1 7\n7\n']
Demo Output:
['2 11\n', '4 54\n', '0 0\n']
Note:
In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.
In the second example, he can buy all items as they will cost him [5, 10, 17, 22].
In the third example, there is only one souvenir in the market which will cost him 8 pounds, so he cannot buy it. | ```python
from heapq import heappop, heapify
def main():
def helper(e):
if e:
l = [a + b for a, b in zip(aa, range(e, (e + 1) * n, e))]
heapify(l)
return sum(heappop(l) for _ in range(e))
return 0
n, s = map(int, input().split())
aa = list(map(int, input().split()))
lo, hi = 0, n
while lo < hi:
mid = (lo + hi + 1) // 2
t = helper(mid)
if s < t:
hi = mid - 1
else:
lo = mid
print(lo, helper(lo))
if __name__ == '__main__':
main()
``` | 3 |
|
625 | B | War of the Corporations | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol's artificial intelligence.
Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol's director decided to replace some characters in AI name with "#". As this operation is pretty expensive, you should find the minimum number of characters to replace with "#", such that the name of AI doesn't contain the name of the phone as a substring.
Substring is a continuous subsequence of a string. | The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100<=000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters. | Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring. | [
"intellect\ntell\n",
"google\napple\n",
"sirisiri\nsir\n"
] | [
"1",
"0",
"2"
] | In the first sample AI's name may be replaced with "int#llect".
In the second sample Gogol can just keep things as they are.
In the third sample one of the new possible names of AI may be "s#ris#ri". | 750 | [
{
"input": "intellect\ntell",
"output": "1"
},
{
"input": "google\napple",
"output": "0"
},
{
"input": "sirisiri\nsir",
"output": "2"
},
{
"input": "sirisiri\nsiri",
"output": "2"
},
{
"input": "aaaaaaa\naaaa",
"output": "1"
},
{
"input": "bbbbbb\nbb",
"output": "3"
},
{
"input": "abc\nabcabc",
"output": "0"
},
{
"input": "kek\nkekekek",
"output": "0"
},
{
"input": "aaaaa\naaa",
"output": "1"
},
{
"input": "abcdabcv\nabcd",
"output": "1"
},
{
"input": "abcabcabczabcabcabcz\ncab",
"output": "4"
},
{
"input": "aatopotopotopotaa\ntopot",
"output": "2"
},
{
"input": "abcabcabcabcabcabcabcabcabcabc\nabcabcabcabcabcabcabcabcabcabc",
"output": "1"
},
{
"input": "sosossosos\nsos",
"output": "2"
},
{
"input": "sosossosossosossosossosossosossosossosossosossosossosossosossosossosossosossosossosossosossosossosos\nsos",
"output": "20"
},
{
"input": "tatatx\ntatx",
"output": "1"
},
{
"input": "sxxsxxsxxd\nsxxsxxd",
"output": "1"
}
] | 1,464,789,357 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 4,608,000 | #busqueda de substring
import sys
def busqueda():
cadena=sys.stdin.readline().strip()
busqueda=sys.stdin.readline().strip()
container=[]
containerm=[]
for i in range(0,len(cadena)):
if cadena[i]==busqueda[0]:
container.append(i)
for j in range(len(container)):
containerm.append(cadena[container[j]:container[j]+len(busqueda)])
count=0
for h in range(0,len(containerm)):
if containerm[h]==busqueda:
count+=1
else:
count+=0
print(count)
busqueda()
| Title: War of the Corporations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol's artificial intelligence.
Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol's director decided to replace some characters in AI name with "#". As this operation is pretty expensive, you should find the minimum number of characters to replace with "#", such that the name of AI doesn't contain the name of the phone as a substring.
Substring is a continuous subsequence of a string.
Input Specification:
The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100<=000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters.
Output Specification:
Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring.
Demo Input:
['intellect\ntell\n', 'google\napple\n', 'sirisiri\nsir\n']
Demo Output:
['1', '0', '2']
Note:
In the first sample AI's name may be replaced with "int#llect".
In the second sample Gogol can just keep things as they are.
In the third sample one of the new possible names of AI may be "s#ris#ri". | ```python
#busqueda de substring
import sys
def busqueda():
cadena=sys.stdin.readline().strip()
busqueda=sys.stdin.readline().strip()
container=[]
containerm=[]
for i in range(0,len(cadena)):
if cadena[i]==busqueda[0]:
container.append(i)
for j in range(len(container)):
containerm.append(cadena[container[j]:container[j]+len(busqueda)])
count=0
for h in range(0,len(containerm)):
if containerm[h]==busqueda:
count+=1
else:
count+=0
print(count)
busqueda()
``` | 0 |
|
929 | B | Места в самолёте | PROGRAMMING | 1,300 | [
"*special",
"implementation"
] | null | null | В самолёте есть *n* рядов мест. Если смотреть на ряды сверху, то в каждом ряду есть 3 места слева, затем проход между рядами, затем 4 центральных места, затем ещё один проход между рядами, а затем ещё 3 места справа.
Известно, что некоторые места уже заняты пассажирами. Всего есть два вида пассажиров — статусные (те, которые часто летают) и обычные.
Перед вами стоит задача рассадить ещё *k* обычных пассажиров так, чтобы суммарное число соседей у статусных пассажиров было минимально возможным. Два пассажира считаются соседями, если они сидят в одном ряду и между ними нет других мест и прохода между рядами. Если пассажир является соседним пассажиром для двух статусных пассажиров, то его следует учитывать в сумме соседей дважды. | В первой строке следуют два целых числа *n* и *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10·*n*) — количество рядов мест в самолёте и количество пассажиров, которых нужно рассадить.
Далее следует описание рядов мест самолёта по одному ряду в строке. Если очередной символ равен '-', то это проход между рядами. Если очередной символ равен '.', то это свободное место. Если очередной символ равен 'S', то на текущем месте будет сидеть статусный пассажир. Если очередной символ равен 'P', то на текущем месте будет сидеть обычный пассажир.
Гарантируется, что количество свободных мест не меньше *k*. Гарантируется, что все ряды удовлетворяют описанному в условии формату. | В первую строку выведите минимальное суммарное число соседей у статусных пассажиров.
Далее выведите план рассадки пассажиров, который минимизирует суммарное количество соседей у статусных пассажиров, в том же формате, что и во входных данных. Если в свободное место нужно посадить одного из *k* пассажиров, выведите строчную букву 'x' вместо символа '.'. | [
"1 2\nSP.-SS.S-S.S\n",
"4 9\nPP.-PPPS-S.S\nPSP-PPSP-.S.\n.S.-S..P-SS.\nP.S-P.PP-PSP\n"
] | [
"5\nSPx-SSxS-S.S\n",
"15\nPPx-PPPS-S.S\nPSP-PPSP-xSx\nxSx-SxxP-SSx\nP.S-PxPP-PSP\n"
] | В первом примере нужно посадить ещё двух обычных пассажиров. Для минимизации соседей у статусных пассажиров, нужно посадить первого из них на третье слева место, а второго на любое из оставшихся двух мест, так как независимо от выбора места он станет соседом двух статусных пассажиров.
Изначально, у статусного пассажира, который сидит на самом левом месте уже есть сосед. Также на четвёртом и пятом местах слева сидят статусные пассажиры, являющиеся соседями друг для друга (что добавляет к сумме 2).
Таким образом, после посадки ещё двух обычных пассажиров, итоговое суммарное количество соседей у статусных пассажиров станет равно пяти. | 1,000 | [
{
"input": "1 2\nSP.-SS.S-S.S",
"output": "5\nSPx-SSxS-S.S"
},
{
"input": "4 9\nPP.-PPPS-S.S\nPSP-PPSP-.S.\n.S.-S..P-SS.\nP.S-P.PP-PSP",
"output": "15\nPPx-PPPS-S.S\nPSP-PPSP-xSx\nxSx-SxxP-SSx\nP.S-PxPP-PSP"
},
{
"input": "3 7\n.S.-SSSP-..S\nS..-.SPP-S.P\n.S.-PPPP-PSP",
"output": "13\nxSx-SSSP-xxS\nSxx-xSPP-S.P\n.S.-PPPP-PSP"
},
{
"input": "5 6\nPP.-PS.P-P..\nPPS-SP..-P.P\nP.P-....-S..\nSPP-.P.S-.S.\nSP.-S.PS-PPP",
"output": "6\nPPx-PS.P-Pxx\nPPS-SPxx-PxP\nP.P-....-S..\nSPP-.P.S-.S.\nSP.-S.PS-PPP"
},
{
"input": "1 1\n..S-PS..-.PP",
"output": "1\nx.S-PS..-.PP"
},
{
"input": "2 2\nPP.-S.SS-.S.\nSSP-SSSS-S.S",
"output": "12\nPPx-S.SS-xS.\nSSP-SSSS-S.S"
},
{
"input": "30 1\nPPP-PPP.-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP",
"output": "0\nPPP-PPPx-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP"
},
{
"input": "1 1\nSPS-....-P.P",
"output": "2\nSPS-x...-P.P"
},
{
"input": "2 1\nSSS-S.S.-SSS\nSSP-.PP.-S.S",
"output": "11\nSSS-S.S.-SSS\nSSP-xPP.-S.S"
},
{
"input": "30 1\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPP.-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP",
"output": "0\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPx-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP\nPPP-PPPP-PPP"
}
] | 1,678,958,873 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 93 | 1,331,200 | n,k=map(int,input().split())
s=[]
ans=0
p=[]
for i in range(n):
s.append(['-']+list(input())+['-'])
for j in range(1,13):
if s[i][j]=='S':
if s[i][j+1] in 'SP': ans+=1
if s[i][j-1] in 'SP': ans+=1
elif s[i][j]=='.':
p.append([0,i,j])
if s[i][j+1] =='S': p[-1][0]+=1
if s[i][j-1] == 'S': p[-1][0]+=1
p.sort()
for x in range(k):
pl,i,j=p[x]
ans+=pl
s[i][j]='x'
print(ans)
[print(''.join(i[1:-1])) for i in s] | Title: Места в самолёте
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
В самолёте есть *n* рядов мест. Если смотреть на ряды сверху, то в каждом ряду есть 3 места слева, затем проход между рядами, затем 4 центральных места, затем ещё один проход между рядами, а затем ещё 3 места справа.
Известно, что некоторые места уже заняты пассажирами. Всего есть два вида пассажиров — статусные (те, которые часто летают) и обычные.
Перед вами стоит задача рассадить ещё *k* обычных пассажиров так, чтобы суммарное число соседей у статусных пассажиров было минимально возможным. Два пассажира считаются соседями, если они сидят в одном ряду и между ними нет других мест и прохода между рядами. Если пассажир является соседним пассажиром для двух статусных пассажиров, то его следует учитывать в сумме соседей дважды.
Input Specification:
В первой строке следуют два целых числа *n* и *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10·*n*) — количество рядов мест в самолёте и количество пассажиров, которых нужно рассадить.
Далее следует описание рядов мест самолёта по одному ряду в строке. Если очередной символ равен '-', то это проход между рядами. Если очередной символ равен '.', то это свободное место. Если очередной символ равен 'S', то на текущем месте будет сидеть статусный пассажир. Если очередной символ равен 'P', то на текущем месте будет сидеть обычный пассажир.
Гарантируется, что количество свободных мест не меньше *k*. Гарантируется, что все ряды удовлетворяют описанному в условии формату.
Output Specification:
В первую строку выведите минимальное суммарное число соседей у статусных пассажиров.
Далее выведите план рассадки пассажиров, который минимизирует суммарное количество соседей у статусных пассажиров, в том же формате, что и во входных данных. Если в свободное место нужно посадить одного из *k* пассажиров, выведите строчную букву 'x' вместо символа '.'.
Demo Input:
['1 2\nSP.-SS.S-S.S\n', '4 9\nPP.-PPPS-S.S\nPSP-PPSP-.S.\n.S.-S..P-SS.\nP.S-P.PP-PSP\n']
Demo Output:
['5\nSPx-SSxS-S.S\n', '15\nPPx-PPPS-S.S\nPSP-PPSP-xSx\nxSx-SxxP-SSx\nP.S-PxPP-PSP\n']
Note:
В первом примере нужно посадить ещё двух обычных пассажиров. Для минимизации соседей у статусных пассажиров, нужно посадить первого из них на третье слева место, а второго на любое из оставшихся двух мест, так как независимо от выбора места он станет соседом двух статусных пассажиров.
Изначально, у статусного пассажира, который сидит на самом левом месте уже есть сосед. Также на четвёртом и пятом местах слева сидят статусные пассажиры, являющиеся соседями друг для друга (что добавляет к сумме 2).
Таким образом, после посадки ещё двух обычных пассажиров, итоговое суммарное количество соседей у статусных пассажиров станет равно пяти. | ```python
n,k=map(int,input().split())
s=[]
ans=0
p=[]
for i in range(n):
s.append(['-']+list(input())+['-'])
for j in range(1,13):
if s[i][j]=='S':
if s[i][j+1] in 'SP': ans+=1
if s[i][j-1] in 'SP': ans+=1
elif s[i][j]=='.':
p.append([0,i,j])
if s[i][j+1] =='S': p[-1][0]+=1
if s[i][j-1] == 'S': p[-1][0]+=1
p.sort()
for x in range(k):
pl,i,j=p[x]
ans+=pl
s[i][j]='x'
print(ans)
[print(''.join(i[1:-1])) for i in s]
``` | 3 |
|
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28",
"output": "1"
},
{
"input": "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 65\n42 57\n9 7\n25 63\n74 34\n96 84\n95 47\n12 23\n34 21\n71 6\n27 13\n15 47\n64 14\n12 77",
"output": "6"
},
{
"input": "30\n46 100\n87 53\n34 84\n44 66\n23 20\n50 34\n90 66\n17 39\n13 22\n94 33\n92 46\n63 78\n26 48\n44 61\n3 19\n41 84\n62 31\n65 89\n23 28\n58 57\n19 85\n26 60\n75 66\n69 67\n76 15\n64 15\n36 72\n90 89\n42 69\n45 35",
"output": "4"
},
{
"input": "2\n46 6\n6 46",
"output": "2"
},
{
"input": "29\n8 18\n33 75\n69 22\n97 95\n1 97\n78 10\n88 18\n13 3\n19 64\n98 12\n79 92\n41 72\n69 15\n98 31\n57 74\n15 56\n36 37\n15 66\n63 100\n16 42\n47 56\n6 4\n73 15\n30 24\n27 71\n12 19\n88 69\n85 6\n50 11",
"output": "10"
},
{
"input": "23\n43 78\n31 28\n58 80\n66 63\n20 4\n51 95\n40 20\n50 14\n5 34\n36 39\n77 42\n64 97\n62 89\n16 56\n8 34\n58 16\n37 35\n37 66\n8 54\n50 36\n24 8\n68 48\n85 33",
"output": "6"
},
{
"input": "13\n76 58\n32 85\n99 79\n23 58\n96 59\n72 35\n53 43\n96 55\n41 78\n75 10\n28 11\n72 7\n52 73",
"output": "0"
},
{
"input": "18\n6 90\n70 79\n26 52\n67 81\n29 95\n41 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 2",
"output": "1"
},
{
"input": "18\n6 90\n100 79\n26 100\n67 100\n29 100\n100 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 100",
"output": "8"
},
{
"input": "30\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "450"
},
{
"input": "30\n100 99\n58 59\n56 57\n54 55\n52 53\n50 51\n48 49\n46 47\n44 45\n42 43\n40 41\n38 39\n36 37\n34 35\n32 33\n30 31\n28 29\n26 27\n24 25\n22 23\n20 21\n18 19\n16 17\n14 15\n12 13\n10 11\n8 9\n6 7\n4 5\n2 3",
"output": "0"
},
{
"input": "15\n9 3\n2 6\n7 6\n5 10\n9 5\n8 1\n10 5\n2 8\n4 5\n9 8\n5 3\n3 8\n9 8\n4 10\n8 5",
"output": "20"
},
{
"input": "15\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2",
"output": "108"
},
{
"input": "25\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2",
"output": "312"
},
{
"input": "25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n91 57\n2 73\n91 2\n23 6\n2 73\n23 6",
"output": "96"
},
{
"input": "28\n31 66\n31 91\n91 31\n97 66\n31 66\n31 66\n66 91\n91 31\n97 31\n91 97\n97 31\n66 31\n66 97\n91 31\n31 66\n31 66\n66 31\n31 97\n66 97\n97 31\n31 91\n66 91\n91 66\n31 66\n91 66\n66 31\n66 31\n91 97",
"output": "210"
},
{
"input": "29\n78 27\n50 68\n24 26\n68 43\n38 78\n26 38\n78 28\n28 26\n27 24\n23 38\n24 26\n24 43\n61 50\n38 78\n27 23\n61 26\n27 28\n43 23\n28 78\n43 27\n43 78\n27 61\n28 38\n61 78\n50 26\n43 27\n26 78\n28 50\n43 78",
"output": "73"
},
{
"input": "29\n80 27\n69 80\n27 80\n69 80\n80 27\n80 27\n80 27\n80 69\n27 69\n80 69\n80 27\n27 69\n69 27\n80 69\n27 69\n69 80\n27 69\n80 69\n80 27\n69 27\n27 69\n27 80\n80 27\n69 80\n27 69\n80 69\n69 80\n69 80\n27 80",
"output": "277"
},
{
"input": "30\n19 71\n7 89\n89 71\n21 7\n19 21\n7 89\n19 71\n89 8\n89 21\n19 8\n21 7\n8 89\n19 89\n7 21\n19 8\n19 7\n7 19\n8 21\n71 21\n71 89\n7 19\n7 19\n21 7\n21 19\n21 19\n71 8\n21 8\n71 19\n19 71\n8 21",
"output": "154"
},
{
"input": "30\n44 17\n44 17\n44 17\n17 44\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n44 17\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n17 44\n44 17\n44 17\n44 17\n17 44\n17 44\n44 17\n17 44\n44 17\n44 17\n44 17",
"output": "418"
},
{
"input": "22\n78 92\n15 92\n92 78\n78 80\n92 16\n24 80\n92 16\n16 92\n78 16\n24 78\n80 78\n92 80\n16 80\n80 78\n15 78\n92 16\n24 15\n24 80\n80 16\n16 80\n92 80\n24 80",
"output": "74"
},
{
"input": "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9",
"output": "59"
},
{
"input": "30\n67 21\n85 39\n85 87\n21 39\n66 85\n10 95\n10 21\n87 85\n82 21\n67 21\n95 10\n21 39\n82 21\n21 66\n66 39\n95 30\n67 85\n66 82\n85 82\n21 66\n10 39\n67 10\n21 85\n10 82\n85 95\n10 85\n21 39\n85 39\n39 10\n95 67",
"output": "100"
},
{
"input": "4\n8 7\n8 7\n7 8\n7 8",
"output": "8"
},
{
"input": "6\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1",
"output": "10"
},
{
"input": "12\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "72"
},
{
"input": "4\n1 2\n1 2\n2 1\n2 1",
"output": "8"
}
] | 1,677,931,723 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | n = int(input())
# Create two lists to store the home and guest uniform colors for each team
home_colors = []
guest_colors = []
for i in range(n):
# Read the home and guest uniform colors for the i-th team
home, guest = map(int, input().split())
home_colors.append(home)
guest_colors.append(guest)
count = 0
# Check each game to see if the host team needs to wear the guest uniform
for i in range(n):
for j in range(n):
if i != j and home_colors[i] == guest_colors[j]:
count += 1
print(count)
| Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
Output Specification:
In a single line print the number of games where the host team is going to play in the guest uniform.
Demo Input:
['3\n1 2\n2 4\n3 4\n', '4\n100 42\n42 100\n5 42\n100 5\n', '2\n1 2\n1 2\n']
Demo Output:
['1\n', '5\n', '0\n']
Note:
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | ```python
n = int(input())
# Create two lists to store the home and guest uniform colors for each team
home_colors = []
guest_colors = []
for i in range(n):
# Read the home and guest uniform colors for the i-th team
home, guest = map(int, input().split())
home_colors.append(home)
guest_colors.append(guest)
count = 0
# Check each game to see if the host team needs to wear the guest uniform
for i in range(n):
for j in range(n):
if i != j and home_colors[i] == guest_colors[j]:
count += 1
print(count)
``` | 3 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,538,987,844 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 248 | 307,200 | s = input()
t = input()
print('NO' if len(s) != len(t) or t[::-1] != s else 'YES')
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
s = input()
t = input()
print('NO' if len(s) != len(t) or t[::-1] != s else 'YES')
``` | 3.937428 |
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system. | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10",
"output": "0"
},
{
"input": "8 20",
"output": "0"
},
{
"input": "2 8",
"output": "0"
},
{
"input": "20 11",
"output": "0"
},
{
"input": "57 447",
"output": "1"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "66 296",
"output": "1"
},
{
"input": "75 683",
"output": "1"
},
{
"input": "227 975",
"output": "1"
},
{
"input": "247 499",
"output": "1"
},
{
"input": "266 116",
"output": "1"
},
{
"input": "286 916",
"output": "1"
},
{
"input": "307 341",
"output": "1"
},
{
"input": "451 121",
"output": "1"
},
{
"input": "471 921",
"output": "1"
},
{
"input": "502 346",
"output": "1"
},
{
"input": "535 59",
"output": "1"
},
{
"input": "555 699",
"output": "1"
},
{
"input": "747 351",
"output": "1"
},
{
"input": "790 64",
"output": "1"
},
{
"input": "810 704",
"output": "1"
},
{
"input": "855 225",
"output": "1"
},
{
"input": "902 34",
"output": "1"
},
{
"input": "922 514",
"output": "1"
},
{
"input": "971 131",
"output": "1"
},
{
"input": "991 931",
"output": "1"
},
{
"input": "840 780",
"output": "0"
},
{
"input": "102 595",
"output": "0"
},
{
"input": "139 433",
"output": "0"
},
{
"input": "968 288",
"output": "0"
},
{
"input": "563 354",
"output": "0"
},
{
"input": "994 975",
"output": "0"
},
{
"input": "456 221",
"output": "0"
},
{
"input": "205 210",
"output": "0"
},
{
"input": "1 11",
"output": "0"
},
{
"input": "1000 1000",
"output": "0"
},
{
"input": "3 3",
"output": "0"
},
{
"input": "11 99",
"output": "0"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "11 1",
"output": "0"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "100 452",
"output": "0"
},
{
"input": "420 380",
"output": "0"
},
{
"input": "31 31",
"output": "0"
},
{
"input": "2 6",
"output": "0"
},
{
"input": "112 134",
"output": "0"
},
{
"input": "13 13",
"output": "0"
},
{
"input": "1 571",
"output": "0"
}
] | 1,656,430,279 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 92 | 0 | import math
def pairCount(n,m):
counting=0
for i in range(n+m):
a=(n-i)**0.5
if(a+(i**2)==m):
counting+=1
return counting
n,m=map(int,input().split())
numberOfPairs=pairCount(n,m)
print(numberOfPairs) | Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
Input Specification:
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
Output Specification:
On a single line print the answer to the problem.
Demo Input:
['9 3\n', '14 28\n', '4 20\n']
Demo Output:
['1\n', '1\n', '0\n']
Note:
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | ```python
import math
def pairCount(n,m):
counting=0
for i in range(n+m):
a=(n-i)**0.5
if(a+(i**2)==m):
counting+=1
return counting
n,m=map(int,input().split())
numberOfPairs=pairCount(n,m)
print(numberOfPairs)
``` | 3 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,646,917,807 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | word = list(map(str, input()))
re_word = list(map(str, input()))
re_word.reverse()
print('YES' if word == re_word else 'NO') | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
word = list(map(str, input()))
re_word = list(map(str, input()))
re_word.reverse()
print('YES' if word == re_word else 'NO')
``` | 3.977 |
979 | C | Kuro and Walking Route | PROGRAMMING | 1,600 | [
"dfs and similar",
"trees"
] | null | null | Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which he will choose a pair of towns $(u, v)$ ($u \neq v$) and walk from $u$ using the shortest path to $v$ (note that $(u, v)$ is considered to be different from $(v, u)$).
Oddly, there are 2 special towns in Uberland named Flowrisa (denoted with the index $x$) and Beetopia (denoted with the index $y$). Flowrisa is a town where there are many strong-scent flowers, and Beetopia is another town where many bees live. In particular, Kuro will avoid any pair of towns $(u, v)$ if on the path from $u$ to $v$, he reaches Beetopia after he reached Flowrisa, since the bees will be attracted with the flower smell on Kuro’s body and sting him.
Kuro wants to know how many pair of city $(u, v)$ he can take as his route. Since he’s not really bright, he asked you to help him with this problem. | The first line contains three integers $n$, $x$ and $y$ ($1 \leq n \leq 3 \cdot 10^5$, $1 \leq x, y \leq n$, $x \ne y$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively.
$n - 1$ lines follow, each line contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), describes a road connecting two towns $a$ and $b$.
It is guaranteed that from each town, we can reach every other town in the city using the given roads. That is, the given map of towns and roads is a tree. | A single integer resembles the number of pair of towns $(u, v)$ that Kuro can use as his walking route. | [
"3 1 3\n1 2\n2 3\n",
"3 1 3\n1 2\n1 3\n"
] | [
"5",
"4"
] | On the first example, Kuro can choose these pairs:
- $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 3)$: his route would be $2 \rightarrow 3$, - $(3, 2)$: his route would be $3 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 1)$: his route would be $3 \rightarrow 2 \rightarrow 1$.
Kuro can't choose pair $(1, 3)$ since his walking route would be $1 \rightarrow 2 \rightarrow 3$, in which Kuro visits town $1$ (Flowrisa) and then visits town $3$ (Beetopia), which is not allowed (note that pair $(3, 1)$ is still allowed because although Kuro visited Flowrisa and Beetopia, he did not visit them in that order).
On the second example, Kuro can choose the following pairs:
- $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 2)$: his route would be $3 \rightarrow 1 \rightarrow 2$, - $(3, 1)$: his route would be $3 \rightarrow 1$. | 1,250 | [
{
"input": "3 1 3\n1 2\n2 3",
"output": "5"
},
{
"input": "3 1 3\n1 2\n1 3",
"output": "4"
},
{
"input": "61 26 12\n33 38\n32 8\n27 59\n1 21\n61 57\n61 22\n35 18\n61 14\n39 56\n50 10\n1 42\n21 43\n61 41\n31 30\n35 9\n23 28\n39 34\n39 4\n39 25\n27 60\n45 51\n1 11\n35 26\n29 15\n23 44\n31 2\n35 27\n39 20\n1 24\n1 53\n35 58\n39 37\n61 13\n61 16\n1 12\n32 17\n1 40\n33 47\n29 52\n1 39\n35 19\n39 50\n27 6\n26 3\n26 55\n35 31\n1 61\n1 23\n27 45\n39 7\n1 35\n39 29\n27 5\n39 32\n27 48\n35 49\n29 54\n1 46\n35 36\n31 33",
"output": "3657"
},
{
"input": "8 5 1\n5 8\n1 5\n1 3\n1 4\n5 6\n6 7\n1 2",
"output": "40"
},
{
"input": "31 29 20\n29 23\n29 18\n22 14\n29 20\n1 21\n29 10\n28 2\n1 17\n17 15\n1 11\n29 31\n28 6\n12 29\n12 26\n1 13\n22 4\n29 25\n28 22\n17 5\n28 30\n20 27\n29 8\n12 28\n1 12\n12 24\n22 7\n12 16\n12 3\n28 9\n1 19",
"output": "872"
},
{
"input": "8 6 4\n1 2\n1 4\n1 8\n1 3\n1 7\n2 6\n2 5",
"output": "55"
},
{
"input": "7 7 3\n3 2\n3 5\n3 7\n1 3\n1 4\n5 6",
"output": "36"
},
{
"input": "70 42 32\n25 50\n51 7\n39 61\n1 33\n20 5\n1 70\n1 63\n42 35\n64 16\n1 11\n39 42\n20 54\n11 14\n57 44\n1 59\n55 40\n25 3\n31 18\n38 68\n57 23\n39 57\n28 10\n39 20\n42 26\n58 6\n20 56\n57 2\n13 21\n15 69\n39 64\n1 39\n62 53\n39 13\n1 41\n22 12\n13 30\n68 67\n20 31\n51 15\n57 32\n59 34\n39 4\n31 65\n58 24\n20 55\n15 27\n25 46\n20 22\n57 49\n68 52\n39 8\n54 58\n39 28\n13 48\n15 43\n25 66\n1 29\n15 37\n31 60\n1 19\n62 38\n39 17\n64 36\n59 25\n57 45\n57 9\n11 62\n20 51\n54 47",
"output": "4827"
},
{
"input": "13 5 13\n2 5\n5 8\n1 2\n13 7\n2 3\n1 13\n13 11\n13 4\n10 6\n10 12\n7 9\n1 10",
"output": "146"
},
{
"input": "72 16 5\n1 20\n8 4\n23 19\n16 63\n45 65\n27 67\n58 21\n36 17\n20 52\n1 71\n8 59\n20 26\n28 16\n23 3\n45 42\n61 51\n6 31\n1 15\n1 11\n6 62\n43 60\n20 27\n20 32\n1 8\n68 25\n1 57\n20 70\n1 64\n1 13\n8 18\n8 46\n28 49\n8 39\n64 58\n28 47\n27 14\n8 10\n11 53\n1 24\n28 2\n72 30\n36 29\n1 45\n24 23\n1 72\n46 61\n45 56\n72 35\n11 50\n8 55\n8 28\n1 38\n61 41\n1 44\n61 40\n27 33\n72 69\n46 36\n43 66\n61 22\n45 5\n27 43\n46 12\n1 7\n16 68\n1 6\n1 9\n45 37\n27 34\n8 54\n20 48",
"output": "5108"
},
{
"input": "2 1 2\n1 2",
"output": "1"
},
{
"input": "2 1 2\n2 1",
"output": "1"
}
] | 1,526,390,843 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 53,350,400 | neighbors = dict()
vertices, first, second = map(int,input().split())
for i in range(1,vertices+1):
neighbors[i] = []
for _ in range(vertices-1):
u,v = map(int,input().split())
neighbors[u].append(v)
neighbors[v].append(u)
def treecomponent(a,b):
output = [b]
l = neighbors[b][:]
l.remove(a)
for x in l:
output += treecomponent(b,x)
return output
def treecomponentavoidingc(a,b,c):
if c == b:
return []
output = [b]
l = neighbors[b][:]
if c in l:
return []
l.remove(a)
for x in l:
if treecomponentavoidingc(b,x,c) == []:
return []
output += treecomponent(b,x)
return output
def branchesaway(a,b):
output = 1
for x in neighbors[a]:
output += len(treecomponentavoidingc(a,x,b))
return output
m = branchesaway(first,second)
n = branchesaway(second,first)
print(vertices*(vertices-1)-m*n) | Title: Kuro and Walking Route
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuro is living in a country called Uberland, consisting of $n$ towns, numbered from $1$ to $n$, and $n - 1$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $a$ and $b$. Kuro loves walking and he is planning to take a walking marathon, in which he will choose a pair of towns $(u, v)$ ($u \neq v$) and walk from $u$ using the shortest path to $v$ (note that $(u, v)$ is considered to be different from $(v, u)$).
Oddly, there are 2 special towns in Uberland named Flowrisa (denoted with the index $x$) and Beetopia (denoted with the index $y$). Flowrisa is a town where there are many strong-scent flowers, and Beetopia is another town where many bees live. In particular, Kuro will avoid any pair of towns $(u, v)$ if on the path from $u$ to $v$, he reaches Beetopia after he reached Flowrisa, since the bees will be attracted with the flower smell on Kuro’s body and sting him.
Kuro wants to know how many pair of city $(u, v)$ he can take as his route. Since he’s not really bright, he asked you to help him with this problem.
Input Specification:
The first line contains three integers $n$, $x$ and $y$ ($1 \leq n \leq 3 \cdot 10^5$, $1 \leq x, y \leq n$, $x \ne y$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively.
$n - 1$ lines follow, each line contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), describes a road connecting two towns $a$ and $b$.
It is guaranteed that from each town, we can reach every other town in the city using the given roads. That is, the given map of towns and roads is a tree.
Output Specification:
A single integer resembles the number of pair of towns $(u, v)$ that Kuro can use as his walking route.
Demo Input:
['3 1 3\n1 2\n2 3\n', '3 1 3\n1 2\n1 3\n']
Demo Output:
['5', '4']
Note:
On the first example, Kuro can choose these pairs:
- $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 3)$: his route would be $2 \rightarrow 3$, - $(3, 2)$: his route would be $3 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 1)$: his route would be $3 \rightarrow 2 \rightarrow 1$.
Kuro can't choose pair $(1, 3)$ since his walking route would be $1 \rightarrow 2 \rightarrow 3$, in which Kuro visits town $1$ (Flowrisa) and then visits town $3$ (Beetopia), which is not allowed (note that pair $(3, 1)$ is still allowed because although Kuro visited Flowrisa and Beetopia, he did not visit them in that order).
On the second example, Kuro can choose the following pairs:
- $(1, 2)$: his route would be $1 \rightarrow 2$, - $(2, 1)$: his route would be $2 \rightarrow 1$, - $(3, 2)$: his route would be $3 \rightarrow 1 \rightarrow 2$, - $(3, 1)$: his route would be $3 \rightarrow 1$. | ```python
neighbors = dict()
vertices, first, second = map(int,input().split())
for i in range(1,vertices+1):
neighbors[i] = []
for _ in range(vertices-1):
u,v = map(int,input().split())
neighbors[u].append(v)
neighbors[v].append(u)
def treecomponent(a,b):
output = [b]
l = neighbors[b][:]
l.remove(a)
for x in l:
output += treecomponent(b,x)
return output
def treecomponentavoidingc(a,b,c):
if c == b:
return []
output = [b]
l = neighbors[b][:]
if c in l:
return []
l.remove(a)
for x in l:
if treecomponentavoidingc(b,x,c) == []:
return []
output += treecomponent(b,x)
return output
def branchesaway(a,b):
output = 1
for x in neighbors[a]:
output += len(treecomponentavoidingc(a,x,b))
return output
m = branchesaway(first,second)
n = branchesaway(second,first)
print(vertices*(vertices-1)-m*n)
``` | 0 |
|
767 | A | Snacktower | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. | Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. | [
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] | [
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] | In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before. | 500 | [
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1 "
},
{
"input": "30\n16 10 4 29 5 28 12 21 11 30 18 6 14 3 17 22 20 15 9 1 27 19 24 26 13 25 2 23 8 7",
"output": "30 29 28 \n\n\n\n\n\n\n\n\n\n\n27 \n\n\n26 \n\n25 24 \n\n23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 \n8 \n7 6 5 4 3 2 1 "
},
{
"input": "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 4 80 72 39",
"output": "100 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n99 98 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 \n\n\n\n\n\n\n\n\n80 79 78 77 76 75 74 73 \n72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 \n39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 "
},
{
"input": "2\n2 1",
"output": "2 \n1 "
}
] | 1,671,036,115 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 218 | 14,643,200 | n=int(input())
size=list(map(int,input().split()))
freq=[0]*(n+1)
x=n
for i in size:
freq[i]=1
while freq[x]==1:
print(x,end=" ")
x-=1
print('')
| Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*.
Output Specification:
Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Demo Input:
['3\n3 1 2\n', '5\n4 5 1 2 3\n']
Demo Output:
['3\n\xa0\n2 1', '5 4\n\xa0\n\xa0\n3 2 1\n']
Note:
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before. | ```python
n=int(input())
size=list(map(int,input().split()))
freq=[0]*(n+1)
x=n
for i in size:
freq[i]=1
while freq[x]==1:
print(x,end=" ")
x-=1
print('')
``` | 3 |
|
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "6 0\n10\n102\n120\n1032\n1212103\n1999999",
"output": "5"
},
{
"input": "1 3\n1000000000",
"output": "0"
},
{
"input": "1 9\n1000000000",
"output": "0"
},
{
"input": "1 0\n1",
"output": "0"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 3\n1",
"output": "0"
},
{
"input": "1 9\n1",
"output": "0"
},
{
"input": "2 8\n123456780\n123",
"output": "1"
},
{
"input": "2 8\n12345678\n1230",
"output": "0"
},
{
"input": "6 1\n10\n102\n120\n1032\n1212103\n1999999",
"output": "5"
},
{
"input": "6 2\n10\n102\n120\n1032\n1212103\n1999999",
"output": "4"
},
{
"input": "6 3\n10\n102\n120\n1032\n1212103\n1999999",
"output": "2"
},
{
"input": "6 9\n10\n102\n120\n1032\n1212103\n1999999",
"output": "0"
},
{
"input": "1 2\n2220",
"output": "0"
}
] | 1,691,842,221 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | def solve():
n, k = list(map(int, input().split()))
ss = ""
for i in range(k+1):
ss += str(i)
counter = 0
for _ in range(n):
pointer = 0
number = list(input())
number.sort()
for i in number:
if pointer > k-1: break
if i == ss[pointer]:
pointer += 1
else:
break
if pointer > k-1:
counter += 1
print(counter)
solve() | Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*).
Input Specification:
The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print a single integer — the number of *k*-good numbers in *a*.
Demo Input:
['10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n', '2 1\n1\n10\n']
Demo Output:
['10\n', '1\n']
Note:
none | ```python
def solve():
n, k = list(map(int, input().split()))
ss = ""
for i in range(k+1):
ss += str(i)
counter = 0
for _ in range(n):
pointer = 0
number = list(input())
number.sort()
for i in number:
if pointer > k-1: break
if i == ss[pointer]:
pointer += 1
else:
break
if pointer > k-1:
counter += 1
print(counter)
solve()
``` | 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,563,147,368 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 109 | 0 | (a,b) = map(int, input().split())
val = 1
for i in range(a+1,b+1):
val = (val * (i%10)) % 10
if val == 0:
break
print(val)
| 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
(a,b) = map(int, input().split())
val = 1
for i in range(a+1,b+1):
val = (val * (i%10)) % 10
if val == 0:
break
print(val)
``` | 3 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,653,925,034 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | def solve(a,b):
len1=len(a)
len2=len(b)
if(len1!=len2):
return 'NO'
for i in range(0,len1):
if(a[i]!=b[len1-i-1]):
return 'NO'
return 'YES'
a,b=input().split()
print(a,b) | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
def solve(a,b):
len1=len(a)
len2=len(b)
if(len1!=len2):
return 'NO'
for i in range(0,len1):
if(a[i]!=b[len1-i-1]):
return 'NO'
return 'YES'
a,b=input().split()
print(a,b)
``` | -1 |
451 | B | Sort the Array | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array *a* (in increasing order) by reversing exactly one segment of *a*? See definitions of segment and reversing in the notes. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*.
The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | [
"3\n3 2 1\n",
"4\n2 1 3 4\n",
"4\n3 1 2 4\n",
"2\n1 2\n"
] | [
"yes\n1 3\n",
"yes\n1 2\n",
"no\n",
"yes\n1 1\n"
] | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*].
If you have an array *a* of size *n* and you reverse its segment [*l*, *r*], the array will become:
*a*[1], *a*[2], ..., *a*[*l* - 2], *a*[*l* - 1], *a*[*r*], *a*[*r* - 1], ..., *a*[*l* + 1], *a*[*l*], *a*[*r* + 1], *a*[*r* + 2], ..., *a*[*n* - 1], *a*[*n*]. | 1,000 | [
{
"input": "3\n3 2 1",
"output": "yes\n1 3"
},
{
"input": "4\n2 1 3 4",
"output": "yes\n1 2"
},
{
"input": "4\n3 1 2 4",
"output": "no"
},
{
"input": "2\n1 2",
"output": "yes\n1 1"
},
{
"input": "2\n58 4",
"output": "yes\n1 2"
},
{
"input": "5\n69 37 27 4 2",
"output": "yes\n1 5"
},
{
"input": "9\n6 78 63 59 28 24 8 96 99",
"output": "yes\n2 7"
},
{
"input": "6\n19517752 43452931 112792556 68417469 779722934 921694415",
"output": "yes\n3 4"
},
{
"input": "6\n169793171 335736854 449917902 513287332 811627074 938727967",
"output": "yes\n1 1"
},
{
"input": "6\n509329 173849943 297546987 591032670 796346199 914588283",
"output": "yes\n1 1"
},
{
"input": "25\n46 45 37 35 26 25 21 19 11 3 1 51 54 55 57 58 59 62 66 67 76 85 88 96 100",
"output": "yes\n1 11"
},
{
"input": "46\n10 12 17 19 20 21 22 24 25 26 27 28 29 30 32 37 42 43 47 48 50 51 52 56 87 86 81 79 74 71 69 67 66 65 60 59 57 89 91 92 94 96 97 98 99 100",
"output": "yes\n25 37"
},
{
"input": "96\n1 2 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 68 69 70 71 72 73 74 75 76 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "yes\n3 22"
},
{
"input": "2\n404928771 698395106",
"output": "yes\n1 1"
},
{
"input": "2\n699573624 308238132",
"output": "yes\n1 2"
},
{
"input": "5\n75531609 242194958 437796493 433259361 942142185",
"output": "yes\n3 4"
},
{
"input": "5\n226959376 840957605 833410429 273566427 872976052",
"output": "yes\n2 4"
},
{
"input": "5\n373362086 994096202 767275079 734424844 515504383",
"output": "yes\n2 5"
},
{
"input": "5\n866379155 593548704 259097686 216134784 879911740",
"output": "yes\n1 4"
},
{
"input": "5\n738083041 719956102 420866851 307749161 257917459",
"output": "yes\n1 5"
},
{
"input": "5\n90786760 107075352 139104198 424911569 858427981",
"output": "yes\n1 1"
},
{
"input": "6\n41533825 525419745 636375901 636653266 879043107 967434399",
"output": "yes\n1 1"
},
{
"input": "40\n22993199 75843013 76710455 99749069 105296587 122559115 125881005 153961749 163646706 175409222 185819807 214465092 264449243 278246513 295514446 322935239 370349154 375773209 390474983 775646826 767329655 740310077 718820037 708508595 693119912 680958422 669537382 629123011 607511013 546574974 546572137 511951383 506996390 493995578 458256840 815612821 881161983 901337648 962275390 986568907",
"output": "yes\n20 35"
},
{
"input": "40\n3284161 23121669 24630274 33434127 178753820 231503277 271972002 272578266 346450638 355655265 372217434 376132047 386622863 387235708 389799554 427160037 466577363 491873718 492746058 502535866 535768673 551570285 557477055 583643014 586216753 588981593 592960633 605923775 611051145 643142759 632768011 634888864 736715552 750574599 867737742 924365786 927179496 934453020 954090860 977765165",
"output": "no"
},
{
"input": "40\n42131757 49645896 49957344 78716964 120937785 129116222 172128600 211446903 247833196 779340466 717548386 709969818 696716905 636153997 635635467 614115746 609201167 533608141 521874836 273044950 291514539 394083281 399369419 448830087 485128983 487192341 488673105 497678164 501864738 265305156 799595875 831638598 835155840 845617770 847736630 851436542 879757553 885618675 964068808 969215471",
"output": "no"
},
{
"input": "40\n25722567 28250400 47661056 108729970 119887370 142272261 145287693 178946020 182917658 187405805 209478929 278713296 312035195 393514697 403876943 410188367 413061616 420619615 477231590 511200584 560288373 571690007 603093961 615463729 631624043 723138759 726089658 728151980 756393077 785590533 809755752 823601179 828357990 866942019 869575503 877310377 881382070 901314141 929048602 947139655",
"output": "yes\n1 1"
},
{
"input": "40\n17927221 33153935 60257083 110553879 114654567 119809916 163899753 167741765 182812464 188486743 220036903 220127072 227545828 229552200 244963635 248298934 299478582 354141058 371400641 430054473 452548736 458695269 466968129 469000714 478004472 478693873 509342093 750631027 609759323 669427158 688490225 690701652 696893030 704668825 749028408 557906039 545356441 926901326 955586118 972642992",
"output": "no"
},
{
"input": "4\n1 4 2 3",
"output": "no"
},
{
"input": "6\n1 2 5 4 3 6",
"output": "yes\n3 5"
},
{
"input": "1\n1",
"output": "yes\n1 1"
},
{
"input": "6\n1 5 3 4 2 6",
"output": "no"
},
{
"input": "4\n3 4 1 2",
"output": "no"
},
{
"input": "5\n2 5 4 3 1",
"output": "no"
},
{
"input": "4\n2 1 4 3",
"output": "no"
},
{
"input": "6\n2 1 4 3 5 6",
"output": "no"
}
] | 1,684,666,936 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 1 | 77 | 2,867,200 | n = int(input())
nums = list(map(int, input().split()))
can = 1
i = 0
happen = 0
a=b=0
while i<n-1 and can:
i+=1
if nums[i] < nums[i-1]:
happen+=1
if happen>1:
can = 0
break
a = i-1
while i<n-1 and can:
i+=1
if nums[i] > nums[i-1]:
if nums[max]> nums[i]:
can = 0
break
else:
b = i-1
b = i
if not can:
print('no')
else:
print('yes')
print(a+1,b+1)
| Title: Sort the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array *a* (in increasing order) by reversing exactly one segment of *a*? See definitions of segment and reversing in the notes.
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*.
The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109).
Output Specification:
Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them.
Demo Input:
['3\n3 2 1\n', '4\n2 1 3 4\n', '4\n3 1 2 4\n', '2\n1 2\n']
Demo Output:
['yes\n1 3\n', 'yes\n1 2\n', 'no\n', 'yes\n1 1\n']
Note:
Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*].
If you have an array *a* of size *n* and you reverse its segment [*l*, *r*], the array will become:
*a*[1], *a*[2], ..., *a*[*l* - 2], *a*[*l* - 1], *a*[*r*], *a*[*r* - 1], ..., *a*[*l* + 1], *a*[*l*], *a*[*r* + 1], *a*[*r* + 2], ..., *a*[*n* - 1], *a*[*n*]. | ```python
n = int(input())
nums = list(map(int, input().split()))
can = 1
i = 0
happen = 0
a=b=0
while i<n-1 and can:
i+=1
if nums[i] < nums[i-1]:
happen+=1
if happen>1:
can = 0
break
a = i-1
while i<n-1 and can:
i+=1
if nums[i] > nums[i-1]:
if nums[max]> nums[i]:
can = 0
break
else:
b = i-1
b = i
if not can:
print('no')
else:
print('yes')
print(a+1,b+1)
``` | -1 |
|
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281",
"output": "5464380"
},
{
"input": "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 241543 29353",
"output": "9535765"
},
{
"input": "3\n1 3 2",
"output": "3"
},
{
"input": "3\n2 1 3",
"output": "3"
},
{
"input": "3\n2 3 1",
"output": "3"
},
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "3\n3 2 1",
"output": "3"
},
{
"input": "1\n228503",
"output": "0"
},
{
"input": "2\n32576 550340",
"output": "517764"
},
{
"input": "3\n910648 542843 537125",
"output": "741328"
},
{
"input": "4\n751720 572344 569387 893618",
"output": "787403"
},
{
"input": "6\n433864 631347 597596 794426 713555 231193",
"output": "1364575"
},
{
"input": "9\n31078 645168 695751 126111 375934 150495 838412 434477 993107",
"output": "4647430"
},
{
"input": "30\n315421 772664 560686 654312 151528 356749 351486 707462 820089 226682 546700 136028 824236 842130 578079 337807 665903 764100 617900 822937 992759 591749 651310 742085 767695 695442 17967 515106 81059 186025",
"output": "13488674"
},
{
"input": "45\n908719 394261 815134 419990 926993 383792 772842 277695 527137 655356 684956 695716 273062 550324 106247 399133 442382 33076 462920 294674 846052 817752 421365 474141 290471 358990 109812 74492 543281 169434 919692 786809 24028 197184 310029 801476 699355 429672 51343 374128 776726 850380 293868 981569 550763",
"output": "21993384"
},
{
"input": "56\n100728 972537 13846 385421 756708 184642 259487 319707 376662 221694 675284 972837 499419 13846 38267 289898 901299 831197 954715 197515 514102 910423 127555 883934 362472 870788 538802 741008 973434 448124 391526 363321 947321 544618 68006 782313 955075 741981 815027 723297 585059 718114 700739 413489 454091 736144 308999 98065 3716 347323 9635 289003 986510 607065 60236 273351",
"output": "26984185"
},
{
"input": "70\n644488 5444 150441 714420 602059 335330 510670 196555 546346 740011 509449 850947 692874 524857 750434 952985 223744 374727 896124 753037 367352 679050 560202 172728 569291 778616 332116 286927 843598 372698 244906 498046 900681 709791 420904 724593 864493 813094 791377 39998 296710 625656 403891 579231 706693 984045 16901 574259 562265 761104 930361 256045 124461 538980 573508 372148 988722 108592 784354 55302 232524 277205 782251 299943 436488 743389 324618 742543 266915 99642",
"output": "32816391"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1000000",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100\n1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "99000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000",
"output": "99000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "99000000"
},
{
"input": "3\n0 0 0",
"output": "0"
},
{
"input": "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",
"output": "0"
},
{
"input": "3\n5 0 0",
"output": "10"
},
{
"input": "5\n2 10 0 0 0",
"output": "38"
}
] | 1,660,495,444 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 0 | n = int(input())
a = [int(i) for i in input().split()]
max_burley = max(a)
count = 0
for k in a:
if k < max_burley:
while k != max_burley:
k += 1
count += 1
print(count) | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input Specification:
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen.
Output Specification:
In the only line print the integer *S* — the minimum number of burles which are had to spend.
Demo Input:
['5\n0 1 2 3 4\n', '5\n1 1 0 1 1\n', '3\n1 3 1\n', '1\n12\n']
Demo Output:
['10', '1', '4', '0']
Note:
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | ```python
n = int(input())
a = [int(i) for i in input().split()]
max_burley = max(a)
count = 0
for k in a:
if k < max_burley:
while k != max_burley:
k += 1
count += 1
print(count)
``` | 0 |
|
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes).
The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>. | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "111010010111",
"output": "11110010111"
},
{
"input": "11110111011100000000",
"output": "1111111011100000000"
},
{
"input": "11110010010100001110110101110011110110100111101",
"output": "1111010010100001110110101110011110110100111101"
},
{
"input": "1001011111010010100111111",
"output": "101011111010010100111111"
},
{
"input": "1111111111",
"output": "111111111"
},
{
"input": "1111111111111111111100111101001110110111111000001111110101001101001110011000001011001111111000110101",
"output": "111111111111111111110111101001110110111111000001111110101001101001110011000001011001111111000110101"
},
{
"input": "11010110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100",
"output": "1110110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100"
},
{
"input": "11111111111111111111111110110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011",
"output": "1111111111111111111111111110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011"
},
{
"input": "11100010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011",
"output": "1110010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011"
},
{
"input": "11",
"output": "1"
},
{
"input": "111",
"output": "11"
},
{
"input": "111111",
"output": "11111"
},
{
"input": "11111",
"output": "1111"
},
{
"input": "1111",
"output": "111"
}
] | 1,481,272,256 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 186 | 409,600 | S=input()
c=0
for i in range(len(S)-1) :
if S[i]=='0' :
print(S[:i]+S[i+1:])
c=1
break
if c==0 :
print(S[:len(S)-1])
| Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes).
The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation.
Input Specification:
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
Output Specification:
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
Demo Input:
['101\n', '110010\n']
Demo Output:
['11\n', '11010\n']
Note:
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>. | ```python
S=input()
c=0
for i in range(len(S)-1) :
if S[i]=='0' :
print(S[:i]+S[i+1:])
c=1
break
if c==0 :
print(S[:len(S)-1])
``` | 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,693,223,481 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 31 | 0 | n=int(input())
x=list(map(int,input().split()))
x=set(x[1:])
y=list(map(int,input().split()))
y=set(y[1:])
the_set=x|y
if the_set.issuperset(set(range(1,n+1))):
print("I become the guy.")
else : print("Oh, my keyboard!") | 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())
x=list(map(int,input().split()))
x=set(x[1:])
y=list(map(int,input().split()))
y=set(y[1:])
the_set=x|y
if the_set.issuperset(set(range(1,n+1))):
print("I become the guy.")
else : print("Oh, my keyboard!")
``` | 3 |
|
35 | D | Animals | PROGRAMMING | 1,700 | [
"dp",
"greedy"
] | D. Animals | 2 | 64 | Once upon a time DravDe, an outstanding person famous for his professional achievements (as you must remember, he works in a warehouse storing Ogudar-Olok, a magical but non-alcoholic drink) came home after a hard day. That day he had to drink 9875 boxes of the drink and, having come home, he went to bed at once.
DravDe dreamt about managing a successful farm. He dreamt that every day one animal came to him and asked him to let it settle there. However, DravDe, being unimaginably kind, could send the animal away and it went, rejected. There were exactly *n* days in DravDe’s dream and the animal that came on the *i*-th day, ate exactly *c**i* tons of food daily starting from day *i*. But if one day the animal could not get the food it needed, it got really sad. At the very beginning of the dream there were exactly *X* tons of food on the farm.
DravDe woke up terrified...
When he retold the dream to you, he couldn’t remember how many animals were on the farm by the end of the *n*-th day any more, but he did remember that nobody got sad (as it was a happy farm) and that there was the maximum possible amount of the animals. That’s the number he wants you to find out.
It should be noticed that the animals arrived in the morning and DravDe only started to feed them in the afternoon, so that if an animal willing to join them is rejected, it can’t eat any farm food. But if the animal does join the farm, it eats daily from that day to the *n*-th. | The first input line contains integers *n* and *X* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*X*<=≤<=104) — amount of days in DravDe’s dream and the total amount of food (in tons) that was there initially. The second line contains integers *c**i* (1<=≤<=*c**i*<=≤<=300). Numbers in the second line are divided by a space. | Output the only number — the maximum possible amount of animals on the farm by the end of the *n*-th day given that the food was enough for everybody. | [
"3 4\n1 1 1\n",
"3 6\n1 1 1\n"
] | [
"2\n",
"3\n"
] | Note to the first example: DravDe leaves the second and the third animal on the farm. The second animal will eat one ton of food on the second day and one ton on the third day. The third animal will eat one ton of food on the third day. | 2,000 | [
{
"input": "3 4\n1 1 1",
"output": "2"
},
{
"input": "3 6\n1 1 1",
"output": "3"
},
{
"input": "1 12\n1",
"output": "1"
},
{
"input": "3 100\n1 1 1",
"output": "3"
},
{
"input": "5 75\n1 1 1 1 1",
"output": "5"
},
{
"input": "7 115\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "10 1055\n7 1 1 2 8 7 8 2 5 8",
"output": "10"
},
{
"input": "7 3623\n20 14 24 4 14 14 24",
"output": "7"
},
{
"input": "10 3234\n24 2 28 18 6 15 31 2 28 16",
"output": "10"
},
{
"input": "15 402\n3 3 3 3 2 2 3 3 3 3 3 3 2 2 1",
"output": "15"
},
{
"input": "25 5523\n24 29 6 35 11 7 24 10 17 43 2 25 15 36 31 8 22 40 23 23 7 24 5 16 24",
"output": "23"
},
{
"input": "50 473\n3 2 2 1 1 3 3 2 1 3 2 3 1 1 3 1 3 2 2 1 2 3 1 3 2 2 1 1 1 3 1 3 4 4 1 3 4 4 4 1 1 3 1 3 1 2 2 1 4 2",
"output": "22"
},
{
"input": "100 4923\n21 5 18 2 9 4 22 17 8 25 20 11 17 25 18 14 25 12 21 13 22 4 6 21 1 12 12 7 20 16 12 17 28 4 17 14 6 2 5 20 20 14 6 30 4 24 18 24 7 18 24 23 33 16 16 24 21 22 11 18 34 19 32 21 1 34 8 9 9 13 4 7 18 8 33 24 9 2 24 35 8 35 35 38 11 23 14 42 43 44 7 43 37 21 8 17 3 9 33 43",
"output": "29"
},
{
"input": "25 101\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",
"output": "13"
},
{
"input": "45 9343\n36 16 13 20 48 5 45 48 54 16 42 40 66 31 18 59 24 66 72 32 65 54 55 72 1 1 36 13 59 16 42 2 72 70 7 40 85 65 40 20 68 89 37 16 46",
"output": "25"
},
{
"input": "75 8333\n27 41 40 42 1 23 25 25 9 12 36 20 19 13 8 49 16 11 17 7 19 25 46 6 33 27 48 37 46 44 5 5 33 8 49 20 49 51 42 2 43 26 4 60 50 25 41 60 53 25 49 28 45 66 26 39 60 58 53 64 44 50 18 29 67 10 63 44 55 26 20 60 35 43 65",
"output": "26"
},
{
"input": "100 115\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": "14"
},
{
"input": "100 1150\n5 3 1 4 2 4 1 1 3 2 1 5 6 3 1 6 3 4 1 3 3 5 2 3 1 5 3 1 3 5 3 1 6 2 3 2 3 2 3 6 3 5 4 6 4 5 3 6 1 2 3 2 1 2 5 1 6 7 4 8 4 4 6 1 6 5 6 7 8 2 5 6 6 2 1 1 9 1 5 6 7 7 2 9 5 1 7 1 2 2 7 6 4 2 1 8 11 8 6 6",
"output": "28"
},
{
"input": "100 3454\n9 3 3 15 14 8 8 14 13 2 16 4 16 4 13 8 14 1 15 7 19 12 9 19 17 17 18 16 10 1 20 8 16 5 12 18 6 5 5 13 12 15 18 4 20 16 3 18 13 22 5 1 23 20 10 21 20 8 9 5 7 23 24 20 1 25 7 19 1 6 14 8 23 26 18 14 11 26 12 11 8 5 10 28 22 8 5 12 28 8 7 8 22 31 31 30 28 33 24 31",
"output": "27"
},
{
"input": "100 8777\n38 4 2 14 30 45 20 17 25 14 12 44 11 11 5 30 16 3 48 14 42 48 9 4 1 30 9 13 23 15 24 31 16 12 23 20 1 4 20 18 41 47 27 5 50 12 41 33 25 16 1 46 41 59 27 57 24 6 33 62 27 50 54 28 48 11 37 23 31 29 21 32 25 47 15 9 41 26 70 26 58 62 42 10 39 38 25 55 69 72 5 31 30 21 43 59 39 83 67 45",
"output": "30"
},
{
"input": "100 10\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": "4"
},
{
"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": "13"
},
{
"input": "100 1000\n3 2 4 5 3 4 5 3 2 5 3 3 1 1 1 3 5 1 2 2 5 3 2 4 4 1 5 1 1 3 4 4 1 4 3 5 2 1 1 6 6 2 2 6 5 1 6 4 5 2 1 2 2 5 5 2 1 5 7 4 4 1 4 4 5 3 4 4 1 6 3 2 4 5 2 6 3 6 5 5 2 4 6 3 7 1 5 4 7 2 5 5 6 3 8 5 9 9 3 3",
"output": "24"
},
{
"input": "100 10000\n9 24 4 16 15 28 18 5 16 52 19 12 52 31 6 53 20 44 17 3 51 51 21 53 27 3 40 15 42 34 54 6 55 24 32 53 35 25 38 2 19 7 26 8 46 32 10 25 24 50 65 6 21 26 25 62 12 67 45 34 50 46 59 40 18 55 41 36 48 13 29 76 52 46 57 30 10 60 43 26 73 21 19 68 20 76 67 29 8 46 27 33 22 74 58 91 27 89 50 42",
"output": "30"
},
{
"input": "100 9999\n31 26 2 16 41 42 44 30 28 9 15 49 19 8 34 52 19 36 30 43 53 53 43 18 38 3 56 3 4 51 6 44 41 46 43 43 14 44 37 53 3 39 25 63 22 14 40 36 40 45 44 14 54 29 56 39 42 65 59 28 34 53 16 14 31 33 28 9 42 43 41 54 27 1 60 47 79 52 72 55 1 16 56 75 81 46 50 58 32 34 73 26 19 25 2 31 18 40 91 17",
"output": "29"
},
{
"input": "100 1234\n1 5 6 5 6 5 2 3 2 1 4 1 6 6 4 5 3 6 5 1 1 5 2 2 3 3 6 1 1 4 6 2 1 3 5 2 7 6 6 2 2 1 1 2 1 4 1 2 1 2 2 5 1 8 8 8 2 2 4 8 1 8 4 1 1 5 5 9 9 2 6 4 7 2 5 3 7 6 7 10 9 9 1 2 5 8 5 7 1 1 8 10 2 6 7 9 5 2 10 6",
"output": "28"
},
{
"input": "100 4321\n7 2 18 4 10 1 11 12 4 22 2 10 5 19 12 3 6 16 20 22 12 2 1 3 15 2 1 13 4 14 11 1 24 12 6 23 18 20 10 7 23 15 24 16 3 15 24 14 18 22 27 18 9 9 10 21 14 21 23 5 5 25 4 23 9 17 16 30 7 14 3 25 23 21 7 19 12 8 14 29 28 21 28 24 29 32 27 10 16 8 3 8 40 3 18 28 23 24 42 40",
"output": "31"
},
{
"input": "100 2222\n10 4 1 2 7 1 2 8 10 6 5 9 9 5 6 5 9 3 4 6 5 7 6 6 11 4 10 6 3 2 5 9 13 2 6 3 4 10 7 7 1 9 7 14 13 13 6 3 12 5 13 9 15 2 5 10 3 4 7 7 5 11 8 15 14 11 4 4 7 3 3 15 4 13 1 13 7 12 4 7 1 4 16 1 9 5 16 14 2 4 7 17 7 4 7 20 11 2 15 9",
"output": "30"
},
{
"input": "5 54\n3 3 2 6 9",
"output": "5"
},
{
"input": "7 102\n2 6 1 3 4 8 7",
"output": "7"
},
{
"input": "4 43\n3 4 9 2",
"output": "3"
},
{
"input": "6 131\n2 9 7 9 7 6",
"output": "5"
},
{
"input": "11 362\n4 5 4 8 10 6 3 2 7 7 4",
"output": "11"
},
{
"input": "85 1121\n6 4 1 3 2 5 1 6 1 3 3 2 1 2 3 2 1 4 1 6 1 1 6 4 5 4 1 5 1 6 2 3 6 5 3 6 7 3 4 7 7 2 1 3 1 8 2 8 7 4 5 7 4 8 6 8 2 6 4 5 5 1 3 7 3 2 4 3 1 9 9 5 9 2 9 1 10 2 10 10 2 10 8 5 8",
"output": "25"
},
{
"input": "85 5801\n14 28 19 29 19 6 17 22 15 17 24 1 5 26 28 11 20 5 1 5 30 30 17 9 31 13 21 13 12 31 3 21 12 5 7 35 27 26 1 18 7 36 18 4 24 21 36 38 20 42 15 20 33 31 25 8 31 33 39 2 11 32 34 9 26 24 16 22 13 31 38 8 17 40 52 51 6 33 53 22 33 19 19 16 41",
"output": "29"
},
{
"input": "95 1191\n3 6 4 3 5 1 6 1 4 4 3 6 5 2 3 6 2 4 5 5 2 5 5 5 2 1 6 2 4 2 3 1 1 5 7 1 6 4 3 6 6 1 1 5 5 4 6 5 8 1 3 1 3 6 4 6 5 4 3 4 4 7 1 3 3 2 5 7 5 5 7 3 5 8 5 9 3 1 7 9 8 9 1 2 7 3 5 3 8 7 1 7 11 9 11",
"output": "27"
},
{
"input": "95 5201\n26 1 1 18 22 8 3 10 18 14 21 17 9 1 22 13 9 27 5 14 28 14 25 3 9 28 3 19 28 7 28 21 25 13 18 5 29 16 1 32 18 4 19 28 31 5 9 27 6 29 19 20 20 19 4 21 20 34 7 2 5 36 27 22 8 3 10 28 37 9 18 36 38 9 23 43 2 6 3 35 9 20 42 45 37 12 29 19 45 22 48 3 13 40 45",
"output": "33"
},
{
"input": "80 8101\n17 23 11 5 11 27 22 5 31 23 24 6 34 44 22 25 10 44 10 42 42 6 3 24 31 43 10 5 27 36 36 51 27 12 45 39 15 29 30 54 14 22 25 6 33 36 16 4 12 20 54 17 2 61 2 38 33 56 34 4 16 15 60 31 41 21 58 66 46 59 2 33 20 20 37 50 61 33 69 38",
"output": "30"
},
{
"input": "90 4411\n11 1 23 12 22 23 17 3 22 4 22 18 23 23 4 15 7 11 14 4 22 11 14 20 4 17 18 14 9 20 7 12 14 18 22 17 25 8 1 15 17 1 27 11 27 13 20 29 29 29 20 1 24 13 10 30 31 33 9 15 29 18 19 4 4 14 23 11 31 15 3 28 19 37 18 24 32 12 26 31 36 12 10 24 4 32 25 30 37 2",
"output": "27"
},
{
"input": "100 9898\n13 16 40 32 21 21 50 18 5 35 44 18 38 31 12 42 29 30 13 51 50 36 37 48 8 56 16 36 15 39 48 37 26 18 8 15 15 2 44 28 20 29 7 36 30 62 31 50 59 37 58 26 37 23 21 31 14 12 58 55 30 9 66 64 55 23 59 54 54 29 36 72 41 36 68 42 17 16 65 71 35 72 43 6 53 79 26 51 1 16 55 36 65 72 43 20 78 86 42 52",
"output": "26"
}
] | 1,536,154,202 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 280 | 1,024,000 | import sys
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
if __name__ == '__main__':
n, x = [int(__) for __ in input().strip().split()]
arr = [int(__) for __ in input().strip().split()]
l = []
for i in range(n):
l.append((n - i) * arr[i])
l.sort()
su = 0
co = 0
for i in range(n):
if su + l[i] <= x:
su += l[i]
co += 1
else:
break
print(co)
| Title: Animals
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Once upon a time DravDe, an outstanding person famous for his professional achievements (as you must remember, he works in a warehouse storing Ogudar-Olok, a magical but non-alcoholic drink) came home after a hard day. That day he had to drink 9875 boxes of the drink and, having come home, he went to bed at once.
DravDe dreamt about managing a successful farm. He dreamt that every day one animal came to him and asked him to let it settle there. However, DravDe, being unimaginably kind, could send the animal away and it went, rejected. There were exactly *n* days in DravDe’s dream and the animal that came on the *i*-th day, ate exactly *c**i* tons of food daily starting from day *i*. But if one day the animal could not get the food it needed, it got really sad. At the very beginning of the dream there were exactly *X* tons of food on the farm.
DravDe woke up terrified...
When he retold the dream to you, he couldn’t remember how many animals were on the farm by the end of the *n*-th day any more, but he did remember that nobody got sad (as it was a happy farm) and that there was the maximum possible amount of the animals. That’s the number he wants you to find out.
It should be noticed that the animals arrived in the morning and DravDe only started to feed them in the afternoon, so that if an animal willing to join them is rejected, it can’t eat any farm food. But if the animal does join the farm, it eats daily from that day to the *n*-th.
Input Specification:
The first input line contains integers *n* and *X* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*X*<=≤<=104) — amount of days in DravDe’s dream and the total amount of food (in tons) that was there initially. The second line contains integers *c**i* (1<=≤<=*c**i*<=≤<=300). Numbers in the second line are divided by a space.
Output Specification:
Output the only number — the maximum possible amount of animals on the farm by the end of the *n*-th day given that the food was enough for everybody.
Demo Input:
['3 4\n1 1 1\n', '3 6\n1 1 1\n']
Demo Output:
['2\n', '3\n']
Note:
Note to the first example: DravDe leaves the second and the third animal on the farm. The second animal will eat one ton of food on the second day and one ton on the third day. The third animal will eat one ton of food on the third day. | ```python
import sys
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
if __name__ == '__main__':
n, x = [int(__) for __ in input().strip().split()]
arr = [int(__) for __ in input().strip().split()]
l = []
for i in range(n):
l.append((n - i) * arr[i])
l.sort()
su = 0
co = 0
for i in range(n):
if su + l[i] <= x:
su += l[i]
co += 1
else:
break
print(co)
``` | 3.922371 |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip.
You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares? | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. | Print a single integer — the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
"input": "0 0 0 0\n4132",
"output": "0"
},
{
"input": "3163 5778 83 7640\n11141442444",
"output": "64270"
},
{
"input": "1809 1302 7164 6122\n3144121413113111223311232232114144321414421243443243422322144324121433444342231344234443332241322442",
"output": "420780"
},
{
"input": "0 0 0 0\n1",
"output": "0"
},
{
"input": "1 2 3 4\n4",
"output": "4"
},
{
"input": "2343 7653 1242 5432\n1",
"output": "2343"
},
{
"input": "2343 7653 1242 5432\n2",
"output": "7653"
},
{
"input": "2343 7653 1242 5432\n3",
"output": "1242"
},
{
"input": "2343 7653 1242 5432\n4",
"output": "5432"
},
{
"input": "1 2 3 4\n123412",
"output": "13"
},
{
"input": "50 50 50 50\n11111111111111111111111111111111111111111111111111111",
"output": "2650"
},
{
"input": "1 2 3 4\n11111111111111111111111111111111111111111111111111",
"output": "50"
},
{
"input": "1 2 3 4\n23123231321231231231231231221232123121312321",
"output": "87"
},
{
"input": "1 2 3 4\n1111111111111222222222233333333333444444444444444",
"output": "126"
},
{
"input": "2 3 1 4\n121321232412342112312313213123123412131231231232",
"output": "105"
}
] | 1,662,473,605 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 62 | 2,150,400 | l=list(map(int,input().split(' ')))
l1=list(input())
l1=list(map(int,l1))
x=l1.count(1)*l[0]
y=l1.count(2)*l[1]
z=l1.count(3)*l[2]
w=l1.count(4)*l[3]
print(x+y+z+w) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly *a**i* calories on touching the *i*-th strip.
You've got a string *s*, describing the process of the game and numbers *a*1,<=*a*2,<=*a*3,<=*a*4. Calculate how many calories Jury needs to destroy all the squares?
Input Specification:
The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=≤<=*a*1,<=*a*2,<=*a*3,<=*a*4<=≤<=104).
The second line contains string *s* (1<=≤<=|*s*|<=≤<=105), where the *і*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
Output Specification:
Print a single integer — the total number of calories that Jury wastes.
Demo Input:
['1 2 3 4\n123214\n', '1 5 3 2\n11221\n']
Demo Output:
['13\n', '13\n']
Note:
none | ```python
l=list(map(int,input().split(' ')))
l1=list(input())
l1=list(map(int,l1))
x=l1.count(1)*l[0]
y=l1.count(2)*l[1]
z=l1.count(3)*l[2]
w=l1.count(4)*l[3]
print(x+y+z+w)
``` | 3 |
|
957 | A | Tritonic Iridescence | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the colours.
Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them. | The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas.
The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one). | If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower). | [
"5\nCY??Y\n",
"5\nC?C?Y\n",
"5\n?CYC?\n",
"5\nC??MM\n",
"3\nMMY\n"
] | [
"Yes\n",
"Yes\n",
"Yes\n",
"No\n",
"No\n"
] | For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.
For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.
For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.
For the fourth example, no matter how the unpainted segments are coloured, the existing magenta segments will prevent the painting from satisfying the requirements. The similar is true for the fifth example. | 500 | [
{
"input": "5\nCY??Y",
"output": "Yes"
},
{
"input": "5\nC?C?Y",
"output": "Yes"
},
{
"input": "5\n?CYC?",
"output": "Yes"
},
{
"input": "5\nC??MM",
"output": "No"
},
{
"input": "3\nMMY",
"output": "No"
},
{
"input": "15\n??YYYYYY??YYYY?",
"output": "No"
},
{
"input": "100\nYCY?CMCMCYMYMYC?YMYMYMY?CMC?MCMYCMYMYCM?CMCM?CMYMYCYCMCMCMCMCMYM?CYCYCMCM?CY?MYCYCMYM?CYCYCYMY?CYCYC",
"output": "No"
},
{
"input": "1\nC",
"output": "No"
},
{
"input": "1\n?",
"output": "Yes"
},
{
"input": "2\nMY",
"output": "No"
},
{
"input": "2\n?M",
"output": "Yes"
},
{
"input": "2\nY?",
"output": "Yes"
},
{
"input": "2\n??",
"output": "Yes"
},
{
"input": "3\n??C",
"output": "Yes"
},
{
"input": "3\nM??",
"output": "Yes"
},
{
"input": "3\nYCM",
"output": "No"
},
{
"input": "3\n?C?",
"output": "Yes"
},
{
"input": "3\nMC?",
"output": "Yes"
},
{
"input": "4\nCYCM",
"output": "No"
},
{
"input": "4\nM?CM",
"output": "No"
},
{
"input": "4\n??YM",
"output": "Yes"
},
{
"input": "4\nC???",
"output": "Yes"
},
{
"input": "10\nMCYM?MYM?C",
"output": "Yes"
},
{
"input": "50\nCMCMCYM?MY?C?MC??YM?CY?YM??M?MCMCYCYMCYCMCM?MCM?MC",
"output": "Yes"
},
{
"input": "97\nMCM?YCMYM?YMY?MY?MYCY?CMCMCYC?YMY?MYCMC?M?YCMC?YM?C?MCMCMYMCMY?MCM?YC?YMYMY?MYCYCM?YC?YCY?MYMYMYC",
"output": "No"
},
{
"input": "100\nC?M?M?M?YM??YMYC?MCYMYM??Y??YC?CYC???YM?YM??MYMY?CYCYMYC?YC?C?CYCMY??CMC?YMCMYCYCYMYM?CYM?M?MCMCMY?Y",
"output": "Yes"
},
{
"input": "100\n?YYYYYYYYYYYYYYYYYYYYYYYYYYYYY??YYY?YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY?",
"output": "No"
},
{
"input": "100\n????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "Yes"
},
{
"input": "100\nY?CYMYMYMYCYMY?CMCYMYMC?MYCY?CMCYCYMCM?YCMCYMYCYCY?MYMYCYCYCM?CYMYMY?CY?MYCYCY?M?YMYCY?CMCMCY?CY?M?C",
"output": "No"
},
{
"input": "4\nM??C",
"output": "Yes"
},
{
"input": "6\nY?C??C",
"output": "Yes"
},
{
"input": "5\nC???Y",
"output": "Yes"
},
{
"input": "5\nC??MY",
"output": "Yes"
},
{
"input": "5\nCY??M",
"output": "Yes"
},
{
"input": "4\nC??Y",
"output": "Yes"
},
{
"input": "52\n??????????????????????????????????????????????????YY",
"output": "No"
},
{
"input": "3\nYY?",
"output": "No"
},
{
"input": "5\nCC??Y",
"output": "No"
},
{
"input": "8\nCMC??MCM",
"output": "Yes"
},
{
"input": "7\nM?YCM??",
"output": "Yes"
},
{
"input": "6\n?CC???",
"output": "No"
},
{
"input": "100\n??????????????????????????????????????????????????????????????????????????????????????????????????MM",
"output": "No"
},
{
"input": "4\nC??M",
"output": "Yes"
},
{
"input": "4\n?C?M",
"output": "Yes"
},
{
"input": "6\nMC??MC",
"output": "Yes"
}
] | 1,522,236,153 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 77 | 7,372,800 | n=int(input())
canvas=input()
if any(x in canvas for x in ["CC","YY","MM"]):
print("No")
else:
print("Yes") | Title: Tritonic Iridescence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the colours.
Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them.
Input Specification:
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas.
The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one).
Output Specification:
If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Demo Input:
['5\nCY??Y\n', '5\nC?C?Y\n', '5\n?CYC?\n', '5\nC??MM\n', '3\nMMY\n']
Demo Output:
['Yes\n', 'Yes\n', 'Yes\n', 'No\n', 'No\n']
Note:
For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.
For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.
For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.
For the fourth example, no matter how the unpainted segments are coloured, the existing magenta segments will prevent the painting from satisfying the requirements. The similar is true for the fifth example. | ```python
n=int(input())
canvas=input()
if any(x in canvas for x in ["CC","YY","MM"]):
print("No")
else:
print("Yes")
``` | 0 |
|
745 | A | Hongcow Learns the Cyclic Shift | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on.
Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted. | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z'). | Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. | [
"abcd\n",
"bbb\n",
"yzyz\n"
] | [
"4\n",
"1\n",
"2\n"
] | For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy". | 500 | [
{
"input": "abcd",
"output": "4"
},
{
"input": "bbb",
"output": "1"
},
{
"input": "yzyz",
"output": "2"
},
{
"input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy",
"output": "25"
},
{
"input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron",
"output": "14"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "1"
},
{
"input": "xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy",
"output": "2"
},
{
"input": "y",
"output": "1"
},
{
"input": "ervbfotfedpozygoumbmxeaqegouaqqzqerlykhmvxvvlcaos",
"output": "49"
},
{
"input": "zyzzzyyzyyyzyyzyzyzyzyzzzyyyzzyzyyzzzzzyyyzzzzyzyy",
"output": "50"
},
{
"input": "zzfyftdezzfyftdezzfyftdezzfyftdezzfyftdezzfyftde",
"output": "8"
},
{
"input": "yehcqdlllqpuxdsaicyjjxiylahgxbygmsopjbxhtimzkashs",
"output": "49"
},
{
"input": "yyyyzzzyzzzyzyzyzyyyyyzzyzyzyyyyyzyzyyyzyzzyyzzzz",
"output": "49"
},
{
"input": "zkqcrhzlzsnwzkqcrhzlzsnwzkqcrhzlzsnwzkqcrhzlzsnw",
"output": "12"
},
{
"input": "xxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxy",
"output": "3"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaab",
"output": "25"
},
{
"input": "aabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaaba",
"output": "4"
},
{
"input": "pqqpqqpqqpqqpqqpqqpqqpqqpqqpqqpqqppqppqppqppqppq",
"output": "48"
},
{
"input": "zxkljaqzxkljaqzxkljaqzxkljaqzxrljaqzxkljaqzxkljaq",
"output": "49"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx",
"output": "50"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz",
"output": "50"
},
{
"input": "abcddcba",
"output": "8"
},
{
"input": "aabaabaabaacaabaabaabaacaabaabaabaacaabaabaabaac",
"output": "12"
},
{
"input": "aabaabcaabaabcdaabaabcaabaabcd",
"output": "15"
},
{
"input": "ababaababaaababaababaaaababaababaaababaababaaaa",
"output": "47"
},
{
"input": "ababaababaaababaababaaaababaababaaababaababaaa",
"output": "23"
},
{
"input": "aaababaab",
"output": "9"
},
{
"input": "aba",
"output": "3"
}
] | 1,605,652,181 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 124 | 0 | s = input()
ans = lambda a: len({a[i:] + a[:i] for i in range(len(a))})
print(ans(s)) | Title: Hongcow Learns the Cyclic Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on.
Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted.
Input Specification:
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z').
Output Specification:
Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.
Demo Input:
['abcd\n', 'bbb\n', 'yzyz\n']
Demo Output:
['4\n', '1\n', '2\n']
Note:
For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy". | ```python
s = input()
ans = lambda a: len({a[i:] + a[:i] for i in range(len(a))})
print(ans(s))
``` | 3 |
Subsets and Splits