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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
981 | A | Antipalindrome | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$.
Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all.
Some time ago Ann read the word $s$. What is the word she changed it into? | The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. | If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique. | [
"mew\n",
"wuffuw\n",
"qqqqqqqq\n"
] | [
"3\n",
"5\n",
"0\n"
] | "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$. | 500 | [
{
"input": "mew",
"output": "3"
},
{
"input": "wuffuw",
"output": "5"
},
{
"input": "qqqqqqqq",
"output": "0"
},
{
"input": "ijvji",
"output": "4"
},
{
"input": "iiiiiii",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow",
"output": "49"
},
{
"input": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy",
"output": "50"
},
{
"input": "ijvxljt",
"output": "7"
},
{
"input": "fyhcncnchyf",
"output": "10"
},
{
"input": "ffffffffffff",
"output": "0"
},
{
"input": "fyhcncfsepqj",
"output": "12"
},
{
"input": "ybejrrlbcinttnicblrrjeby",
"output": "23"
},
{
"input": "yyyyyyyyyyyyyyyyyyyyyyyyy",
"output": "0"
},
{
"input": "ybejrrlbcintahovgjddrqatv",
"output": "25"
},
{
"input": "oftmhcmclgyqaojljoaqyglcmchmtfo",
"output": "30"
},
{
"input": "oooooooooooooooooooooooooooooooo",
"output": "0"
},
{
"input": "oftmhcmclgyqaojllbotztajglsmcilv",
"output": "32"
},
{
"input": "gxandbtgpbknxvnkjaajknvxnkbpgtbdnaxg",
"output": "35"
},
{
"input": "gggggggggggggggggggggggggggggggggggg",
"output": "0"
},
{
"input": "gxandbtgpbknxvnkjaygommzqitqzjfalfkk",
"output": "36"
},
{
"input": "fcliblymyqckxvieotjooojtoeivxkcqymylbilcf",
"output": "40"
},
{
"input": "fffffffffffffffffffffffffffffffffffffffffff",
"output": "0"
},
{
"input": "fcliblymyqckxvieotjootiqwtyznhhvuhbaixwqnsy",
"output": "43"
},
{
"input": "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr",
"output": "0"
},
{
"input": "rajccqwqnqmshmerpvjyfepxwpxyldzpzhctqjnstxyfmlhiy",
"output": "49"
},
{
"input": "a",
"output": "0"
},
{
"input": "abca",
"output": "4"
},
{
"input": "aaaaabaaaaa",
"output": "10"
},
{
"input": "aba",
"output": "2"
},
{
"input": "asaa",
"output": "4"
},
{
"input": "aabaa",
"output": "4"
},
{
"input": "aabbaa",
"output": "5"
},
{
"input": "abcdaaa",
"output": "7"
},
{
"input": "aaholaa",
"output": "7"
},
{
"input": "abcdefghijka",
"output": "12"
},
{
"input": "aaadcba",
"output": "7"
},
{
"input": "aaaabaaaa",
"output": "8"
},
{
"input": "abaa",
"output": "4"
},
{
"input": "abcbaa",
"output": "6"
},
{
"input": "ab",
"output": "2"
},
{
"input": "l",
"output": "0"
},
{
"input": "aaaabcaaaa",
"output": "10"
},
{
"input": "abbaaaaaabba",
"output": "11"
},
{
"input": "abaaa",
"output": "5"
},
{
"input": "baa",
"output": "3"
},
{
"input": "aaaaaaabbba",
"output": "11"
},
{
"input": "ccbcc",
"output": "4"
},
{
"input": "bbbaaab",
"output": "7"
},
{
"input": "abaaaaaaaa",
"output": "10"
},
{
"input": "abaaba",
"output": "5"
},
{
"input": "aabsdfaaaa",
"output": "10"
},
{
"input": "aaaba",
"output": "5"
},
{
"input": "aaabaaa",
"output": "6"
},
{
"input": "baaabbb",
"output": "7"
},
{
"input": "ccbbabbcc",
"output": "8"
},
{
"input": "cabc",
"output": "4"
},
{
"input": "aabcd",
"output": "5"
},
{
"input": "abcdea",
"output": "6"
},
{
"input": "bbabb",
"output": "4"
},
{
"input": "aaaaabababaaaaa",
"output": "14"
},
{
"input": "bbabbb",
"output": "6"
},
{
"input": "aababd",
"output": "6"
},
{
"input": "abaaaa",
"output": "6"
},
{
"input": "aaaaaaaabbba",
"output": "12"
},
{
"input": "aabca",
"output": "5"
},
{
"input": "aaabccbaaa",
"output": "9"
},
{
"input": "aaaaaaaaaaaaaaaaaaaab",
"output": "21"
},
{
"input": "babb",
"output": "4"
},
{
"input": "abcaa",
"output": "5"
},
{
"input": "qwqq",
"output": "4"
},
{
"input": "aaaaaaaaaaabbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaa",
"output": "48"
},
{
"input": "aaab",
"output": "4"
},
{
"input": "aaaaaabaaaaa",
"output": "12"
},
{
"input": "wwuww",
"output": "4"
},
{
"input": "aaaaabcbaaaaa",
"output": "12"
},
{
"input": "aaabbbaaa",
"output": "8"
},
{
"input": "aabcbaa",
"output": "6"
},
{
"input": "abccdefccba",
"output": "11"
},
{
"input": "aabbcbbaa",
"output": "8"
},
{
"input": "aaaabbaaaa",
"output": "9"
},
{
"input": "aabcda",
"output": "6"
},
{
"input": "abbca",
"output": "5"
},
{
"input": "aaaaaabbaaa",
"output": "11"
},
{
"input": "sssssspssssss",
"output": "12"
},
{
"input": "sdnmsdcs",
"output": "8"
},
{
"input": "aaabbbccbbbaaa",
"output": "13"
},
{
"input": "cbdbdc",
"output": "6"
},
{
"input": "abb",
"output": "3"
},
{
"input": "abcdefaaaa",
"output": "10"
},
{
"input": "abbbaaa",
"output": "7"
},
{
"input": "v",
"output": "0"
},
{
"input": "abccbba",
"output": "7"
},
{
"input": "axyza",
"output": "5"
},
{
"input": "abcdefgaaaa",
"output": "11"
},
{
"input": "aaabcdaaa",
"output": "9"
},
{
"input": "aaaacaaaa",
"output": "8"
},
{
"input": "aaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaa",
"output": "42"
},
{
"input": "abbbaa",
"output": "6"
},
{
"input": "abcdee",
"output": "6"
},
{
"input": "oom",
"output": "3"
},
{
"input": "aabcaa",
"output": "6"
},
{
"input": "abba",
"output": "3"
},
{
"input": "aaca",
"output": "4"
},
{
"input": "aacbca",
"output": "6"
},
{
"input": "ababa",
"output": "4"
},
{
"input": "abcda",
"output": "5"
},
{
"input": "cccaaccc",
"output": "7"
},
{
"input": "aaabcda",
"output": "7"
},
{
"input": "aa",
"output": "0"
},
{
"input": "aabaaaa",
"output": "7"
},
{
"input": "abbaaaa",
"output": "7"
},
{
"input": "aaabcbaaa",
"output": "8"
},
{
"input": "aabba",
"output": "5"
},
{
"input": "xyxx",
"output": "4"
},
{
"input": "aaaaaaaaaaaabc",
"output": "14"
},
{
"input": "bbaaaabb",
"output": "7"
},
{
"input": "aaabaa",
"output": "6"
},
{
"input": "sssssabsssss",
"output": "12"
},
{
"input": "bbbaaaabbb",
"output": "9"
},
{
"input": "abbbbaaaa",
"output": "9"
},
{
"input": "wwufuww",
"output": "6"
},
{
"input": "oowoo",
"output": "4"
},
{
"input": "cccaccc",
"output": "6"
},
{
"input": "aaa",
"output": "0"
},
{
"input": "bbbcc",
"output": "5"
},
{
"input": "abcdef",
"output": "6"
},
{
"input": "abbba",
"output": "4"
},
{
"input": "aab",
"output": "3"
},
{
"input": "aaba",
"output": "4"
},
{
"input": "azbyaaa",
"output": "7"
},
{
"input": "oooooiooooo",
"output": "10"
},
{
"input": "aabbbbbaaaaaa",
"output": "13"
}
] | 1,527,923,037 | 2,147,483,647 | Python 3 | OK | TESTS | 133 | 93 | 7,065,600 | word = input()
if word == word[::-1]:
for i in range(len(word)):
slicedWord = word[i + 1:]
if slicedWord != slicedWord[::-1]:
print(len(word) - i - 1)
break
if len(slicedWord) == 0:
print(0)
break
else:
print(len(word)) | Title: Antipalindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$.
Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all.
Some time ago Ann read the word $s$. What is the word she changed it into?
Input Specification:
The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only.
Output Specification:
If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique.
Demo Input:
['mew\n', 'wuffuw\n', 'qqqqqqqq\n']
Demo Output:
['3\n', '5\n', '0\n']
Note:
"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$. | ```python
word = input()
if word == word[::-1]:
for i in range(len(word)):
slicedWord = word[i + 1:]
if slicedWord != slicedWord[::-1]:
print(len(word) - i - 1)
break
if len(slicedWord) == 0:
print(0)
break
else:
print(len(word))
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | One day student Vasya was sitting on a lecture and mentioned a string *s*1*s*2... *s**n*, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph *G* with the following properties:
- *G* has exactly *n* vertices, numbered from 1 to *n*. - For all pairs of vertices *i* and *j*, where *i*<=≠<=*j*, there is an edge connecting them if and only if characters *s**i* and *s**j* are either equal or neighbouring in the alphabet. That is, letters in pairs "a"-"b" and "b"-"c" are neighbouring, while letters "a"-"c" are not.
Vasya painted the resulting graph near the string and then erased the string. Next day Vasya's friend Petya came to a lecture and found some graph at his desk. He had heard of Vasya's adventure and now he wants to find out whether it could be the original graph *G*, painted by Vasya. In order to verify this, Petya needs to know whether there exists a string *s*, such that if Vasya used this *s* he would produce the given graph *G*. | The first line of the input contains two integers *n* and *m* — the number of vertices and edges in the graph found by Petya, respectively.
Each of the next *m* lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*) — the edges of the graph *G*. It is guaranteed, that there are no multiple edges, that is any pair of vertexes appear in this list no more than once. | In the first line print "Yes" (without the quotes), if the string *s* Petya is interested in really exists and "No" (without the quotes) otherwise.
If the string *s* exists, then print it on the second line of the output. The length of *s* must be exactly *n*, it must consist of only letters "a", "b" and "c" only, and the graph built using this string must coincide with *G*. If there are multiple possible answers, you may print any of them. | [
"2 1\n1 2\n",
"4 3\n1 2\n1 3\n1 4\n"
] | [
"Yes\naa\n",
"No\n"
] | In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions.
In the second sample the first vertex is connected to all three other vertices, but these three vertices are not connected with each other. That means that they must correspond to distinct letters that are not adjacent, but that is impossible as there are only two such letters: a and c. | 0 | [
{
"input": "2 1\n1 2",
"output": "Yes\naa"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "No"
},
{
"input": "4 4\n1 2\n1 3\n1 4\n3 4",
"output": "Yes\nbacc"
},
{
"input": "1 0",
"output": "Yes\na"
},
{
"input": "8 28\n3 2\n4 2\n7 4\n6 3\n3 7\n8 1\n3 4\n5 1\n6 5\n5 3\n7 1\n5 8\n5 4\n6 1\n6 4\n2 1\n4 1\n8 2\n7 2\n6 8\n8 4\n6 7\n3 1\n7 8\n3 8\n5 7\n5 2\n6 2",
"output": "Yes\naaaaaaaa"
},
{
"input": "8 28\n3 2\n4 2\n7 4\n6 3\n3 7\n8 1\n3 4\n5 1\n6 5\n5 3\n7 1\n5 8\n5 4\n6 1\n6 4\n2 1\n4 1\n8 2\n7 2\n6 8\n8 4\n6 7\n3 1\n7 8\n3 8\n5 7\n5 2\n6 2",
"output": "Yes\naaaaaaaa"
},
{
"input": "4 3\n4 3\n2 4\n2 3",
"output": "Yes\naccc"
},
{
"input": "4 2\n4 3\n1 2",
"output": "Yes\naacc"
},
{
"input": "5 3\n1 2\n1 3\n4 5",
"output": "No"
},
{
"input": "6 4\n1 2\n1 3\n4 5\n4 6",
"output": "No"
},
{
"input": "6 4\n1 2\n2 3\n4 5\n4 6",
"output": "No"
},
{
"input": "6 4\n3 2\n1 3\n6 5\n4 6",
"output": "No"
},
{
"input": "6 4\n1 2\n1 3\n4 6\n5 6",
"output": "No"
},
{
"input": "7 13\n1 2\n2 3\n1 3\n4 5\n5 6\n4 6\n2 5\n2 7\n3 7\n7 4\n7 6\n7 1\n7 5",
"output": "No"
},
{
"input": "8 18\n3 7\n2 5\n5 3\n3 8\n8 6\n6 3\n6 4\n4 8\n1 2\n6 1\n2 7\n2 4\n4 5\n4 3\n6 5\n1 4\n5 7\n3 1",
"output": "No"
},
{
"input": "20 55\n20 11\n14 5\n4 9\n17 5\n16 5\n20 16\n11 17\n2 14\n14 19\n9 15\n20 19\n5 18\n15 20\n1 16\n12 20\n4 7\n16 19\n17 19\n16 12\n19 9\n11 13\n18 17\n10 8\n20 1\n16 8\n1 13\n11 12\n13 18\n4 13\n14 10\n9 13\n8 9\n6 9\n2 13\n10 16\n19 1\n7 17\n20 4\n12 8\n3 2\n18 10\n6 13\n14 9\n7 9\n19 7\n8 15\n20 6\n16 13\n14 13\n19 8\n7 14\n6 2\n9 1\n7 1\n10 6",
"output": "No"
},
{
"input": "15 84\n11 9\n3 11\n13 10\n2 12\n5 9\n1 7\n14 4\n14 2\n14 1\n11 8\n1 8\n14 10\n4 15\n10 5\n5 12\n13 11\n6 14\n5 7\n12 11\n9 1\n10 15\n2 6\n7 15\n14 9\n9 7\n11 14\n8 15\n12 7\n13 6\n2 9\n9 6\n15 3\n12 15\n6 15\n4 6\n4 1\n9 12\n10 7\n6 1\n11 10\n2 3\n5 2\n13 2\n13 3\n12 6\n4 3\n5 8\n12 1\n9 15\n14 5\n12 14\n10 1\n9 4\n7 13\n3 6\n15 1\n13 9\n11 1\n10 4\n9 3\n8 12\n13 12\n6 7\n12 10\n4 12\n13 15\n2 10\n3 8\n1 5\n15 2\n4 11\n2 1\n10 8\n14 3\n14 8\n8 7\n13 1\n5 4\n11 2\n6 8\n5 15\n2 4\n9 8\n9 10",
"output": "No"
},
{
"input": "15 13\n13 15\n13 3\n14 3\n10 7\n2 5\n5 12\n12 11\n9 2\n13 7\n7 4\n12 10\n15 7\n6 13",
"output": "No"
},
{
"input": "6 6\n1 4\n3 4\n6 4\n2 6\n5 3\n3 2",
"output": "No"
},
{
"input": "4 6\n4 2\n3 1\n3 4\n3 2\n4 1\n2 1",
"output": "Yes\naaaa"
},
{
"input": "4 4\n3 2\n2 4\n1 2\n3 4",
"output": "Yes\nabcc"
},
{
"input": "4 3\n1 3\n1 4\n3 4",
"output": "Yes\nacaa"
},
{
"input": "4 4\n1 2\n4 1\n3 4\n3 1",
"output": "Yes\nbacc"
},
{
"input": "4 4\n4 2\n3 4\n3 1\n2 3",
"output": "Yes\nacbc"
},
{
"input": "4 5\n3 1\n2 1\n3 4\n2 4\n3 2",
"output": "Yes\nabbc"
},
{
"input": "4 4\n4 1\n3 1\n3 2\n3 4",
"output": "Yes\nacba"
},
{
"input": "4 5\n3 4\n2 1\n3 1\n4 1\n2 3",
"output": "Yes\nbabc"
},
{
"input": "4 4\n1 3\n3 4\n2 1\n3 2",
"output": "Yes\naabc"
},
{
"input": "4 3\n2 1\n1 4\n2 4",
"output": "Yes\naaca"
},
{
"input": "4 4\n2 4\n1 2\n1 3\n1 4",
"output": "Yes\nbaca"
},
{
"input": "4 2\n3 1\n2 4",
"output": "Yes\nacac"
},
{
"input": "4 4\n4 2\n2 1\n3 2\n1 4",
"output": "Yes\nabca"
},
{
"input": "4 5\n4 1\n2 4\n2 1\n2 3\n3 1",
"output": "Yes\nbbac"
},
{
"input": "4 4\n1 2\n3 1\n2 4\n2 3",
"output": "Yes\nabac"
},
{
"input": "4 2\n2 3\n1 4",
"output": "Yes\nacca"
},
{
"input": "4 4\n2 1\n1 4\n2 3\n3 1",
"output": "Yes\nbaac"
},
{
"input": "4 3\n3 2\n1 2\n1 3",
"output": "Yes\naaac"
},
{
"input": "4 4\n3 2\n2 4\n3 4\n4 1",
"output": "Yes\naccb"
},
{
"input": "4 5\n4 2\n3 2\n4 3\n4 1\n2 1",
"output": "Yes\nabcb"
},
{
"input": "4 4\n3 1\n2 4\n1 4\n3 4",
"output": "Yes\nacab"
},
{
"input": "4 5\n3 1\n4 3\n4 1\n2 1\n2 4",
"output": "Yes\nbacb"
},
{
"input": "4 4\n2 4\n3 4\n1 2\n4 1",
"output": "Yes\naacb"
},
{
"input": "4 5\n1 4\n4 3\n4 2\n3 2\n1 3",
"output": "Yes\nacbb"
},
{
"input": "2 0",
"output": "Yes\nac"
},
{
"input": "3 0",
"output": "No"
},
{
"input": "3 1\n1 2",
"output": "Yes\naac"
},
{
"input": "3 2\n1 2\n3 2",
"output": "Yes\nabc"
},
{
"input": "3 3\n1 2\n1 3\n2 3",
"output": "Yes\naaa"
},
{
"input": "3 1\n2 3",
"output": "Yes\nacc"
},
{
"input": "3 1\n1 3",
"output": "Yes\naca"
},
{
"input": "4 3\n1 2\n2 3\n3 4",
"output": "No"
},
{
"input": "5 9\n4 3\n4 2\n3 1\n5 1\n4 1\n2 1\n5 2\n3 2\n5 4",
"output": "Yes\nbbabc"
},
{
"input": "6 9\n1 4\n1 6\n3 6\n5 4\n2 6\n3 5\n4 6\n1 5\n5 6",
"output": "No"
},
{
"input": "8 21\n4 7\n7 8\n6 4\n8 5\n8 1\n3 4\n4 8\n4 5\n6 7\n6 8\n7 1\n4 2\n1 5\n6 5\n8 2\n3 6\n5 2\n7 5\n1 2\n7 2\n4 1",
"output": "No"
},
{
"input": "4 3\n1 4\n1 3\n2 4",
"output": "No"
},
{
"input": "4 4\n1 3\n1 4\n2 3\n2 4",
"output": "No"
},
{
"input": "4 3\n1 3\n2 4\n3 4",
"output": "No"
},
{
"input": "4 3\n1 3\n2 4\n1 4",
"output": "No"
},
{
"input": "5 6\n1 2\n2 4\n2 5\n3 4\n3 5\n4 5",
"output": "No"
},
{
"input": "6 10\n1 5\n1 4\n3 4\n3 6\n1 2\n3 5\n2 5\n2 6\n1 6\n4 6",
"output": "No"
},
{
"input": "4 3\n1 2\n3 4\n2 3",
"output": "No"
}
] | 1,465,384,655 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 77 | 5,120,000 | from collections import defaultdict,deque,Counter,OrderedDict
def main():
n,m = map(int,input().split())
adj = [[] for i in range(n+1)]
for i in range(m):
a,b = map(int,input().split())
adj[a].append(b)
adj[b].append(a)
ans = ["d"]*(n+1)
visited = [0] * (n + 1)
for i in range(1,n+1):
if len(adj[i]) == n-1:
visited[i] = 1
ans[i] = "b"
st = ans.index("d")
def dfs(st,ck):
if visited[st]: return
visited[st] = 1
ans[st] = ck
for i in adj[st]:
dfs(i,ck)
dfs(st,"a")
if "d" in ans:
st = ans.index("d")
dfs(st,"c")
if "d" in ans:
print("No")
else:
print("Yes")
print("".join(ans[1:]))
if __name__ == "__main__":
main() | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day student Vasya was sitting on a lecture and mentioned a string *s*1*s*2... *s**n*, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph *G* with the following properties:
- *G* has exactly *n* vertices, numbered from 1 to *n*. - For all pairs of vertices *i* and *j*, where *i*<=≠<=*j*, there is an edge connecting them if and only if characters *s**i* and *s**j* are either equal or neighbouring in the alphabet. That is, letters in pairs "a"-"b" and "b"-"c" are neighbouring, while letters "a"-"c" are not.
Vasya painted the resulting graph near the string and then erased the string. Next day Vasya's friend Petya came to a lecture and found some graph at his desk. He had heard of Vasya's adventure and now he wants to find out whether it could be the original graph *G*, painted by Vasya. In order to verify this, Petya needs to know whether there exists a string *s*, such that if Vasya used this *s* he would produce the given graph *G*.
Input Specification:
The first line of the input contains two integers *n* and *m* — the number of vertices and edges in the graph found by Petya, respectively.
Each of the next *m* lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*) — the edges of the graph *G*. It is guaranteed, that there are no multiple edges, that is any pair of vertexes appear in this list no more than once.
Output Specification:
In the first line print "Yes" (without the quotes), if the string *s* Petya is interested in really exists and "No" (without the quotes) otherwise.
If the string *s* exists, then print it on the second line of the output. The length of *s* must be exactly *n*, it must consist of only letters "a", "b" and "c" only, and the graph built using this string must coincide with *G*. If there are multiple possible answers, you may print any of them.
Demo Input:
['2 1\n1 2\n', '4 3\n1 2\n1 3\n1 4\n']
Demo Output:
['Yes\naa\n', 'No\n']
Note:
In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions.
In the second sample the first vertex is connected to all three other vertices, but these three vertices are not connected with each other. That means that they must correspond to distinct letters that are not adjacent, but that is impossible as there are only two such letters: a and c. | ```python
from collections import defaultdict,deque,Counter,OrderedDict
def main():
n,m = map(int,input().split())
adj = [[] for i in range(n+1)]
for i in range(m):
a,b = map(int,input().split())
adj[a].append(b)
adj[b].append(a)
ans = ["d"]*(n+1)
visited = [0] * (n + 1)
for i in range(1,n+1):
if len(adj[i]) == n-1:
visited[i] = 1
ans[i] = "b"
st = ans.index("d")
def dfs(st,ck):
if visited[st]: return
visited[st] = 1
ans[st] = ck
for i in adj[st]:
dfs(i,ck)
dfs(st,"a")
if "d" in ans:
st = ans.index("d")
dfs(st,"c")
if "d" in ans:
print("No")
else:
print("Yes")
print("".join(ans[1:]))
if __name__ == "__main__":
main()
``` | 0 |
|
766 | B | Mahmoud and a Triangle | PROGRAMMING | 1,000 | [
"constructive algorithms",
"geometry",
"greedy",
"math",
"number theory",
"sortings"
] | null | null | Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle.
Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area. | The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has. | In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise. | [
"5\n1 5 3 2 4\n",
"3\n4 1 2\n"
] | [
"YES\n",
"NO\n"
] | For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle. | 1,000 | [
{
"input": "5\n1 5 3 2 4",
"output": "YES"
},
{
"input": "3\n4 1 2",
"output": "NO"
},
{
"input": "30\n197 75 517 39724 7906061 1153471 3 15166 168284 3019844 272293 316 16 24548 42 118 5792 5 9373 1866366 4886214 24 2206 712886 104005 1363 836 64273 440585 3576",
"output": "NO"
},
{
"input": "30\n229017064 335281886 247217656 670601882 743442492 615491486 544941439 911270108 474843964 803323771 177115397 62179276 390270885 754889875 881720571 902691435 154083299 328505383 761264351 182674686 94104683 357622370 573909964 320060691 33548810 247029007 812823597 946798893 813659359 710111761",
"output": "YES"
},
{
"input": "40\n740553458 532562042 138583675 75471987 487348843 476240280 972115023 103690894 546736371 915774563 35356828 819948191 138721993 24257926 761587264 767176616 608310208 78275645 386063134 227581756 672567198 177797611 87579917 941781518 274774331 843623616 981221615 630282032 118843963 749160513 354134861 132333165 405839062 522698334 29698277 541005920 856214146 167344951 398332403 68622974",
"output": "YES"
},
{
"input": "40\n155 1470176 7384 765965701 1075 4 561554 6227772 93 16304522 1744 662 3 292572860 19335 908613 42685804 347058 20 132560 3848974 69067081 58 2819 111752888 408 81925 30 11951 4564 251 26381275 473392832 50628 180819969 2378797 10076746 9 214492 31291",
"output": "NO"
},
{
"input": "3\n1 1000000000 1000000000",
"output": "YES"
},
{
"input": "4\n1 1000000000 1000000000 1000000000",
"output": "YES"
},
{
"input": "3\n1 1000000000 1",
"output": "NO"
},
{
"input": "5\n1 2 3 5 2",
"output": "YES"
},
{
"input": "41\n19 161 4090221 118757367 2 45361275 1562319 596751 140871 97 1844 310910829 10708344 6618115 698 1 87059 33 2527892 12703 73396090 17326460 3 368811 20550 813975131 10 53804 28034805 7847 2992 33254 1139 227930 965568 261 4846 503064297 192153458 57 431",
"output": "NO"
},
{
"input": "42\n4317083 530966905 202811311 104 389267 35 1203 18287479 125344279 21690 859122498 65 859122508 56790 1951 148683 457 1 22 2668100 8283 2 77467028 13405 11302280 47877251 328155592 35095 29589769 240574 4 10 1019123 6985189 629846 5118 169 1648973 91891 741 282 3159",
"output": "YES"
},
{
"input": "43\n729551585 11379 5931704 330557 1653 15529406 729551578 278663905 1 729551584 2683 40656510 29802 147 1400284 2 126260 865419 51 17 172223763 86 1 534861 450887671 32 234 25127103 9597697 48226 7034 389 204294 2265706 65783617 4343 3665990 626 78034 106440137 5 18421 1023",
"output": "YES"
},
{
"input": "44\n719528276 2 235 444692918 24781885 169857576 18164 47558 15316043 9465834 64879816 2234575 1631 853530 8 1001 621 719528259 84 6933 31 1 3615623 719528266 40097928 274835337 1381044 11225 2642 5850203 6 527506 18 104977753 76959 29393 49 4283 141 201482 380 1 124523 326015",
"output": "YES"
},
{
"input": "45\n28237 82 62327732 506757 691225170 5 970 4118 264024506 313192 367 14713577 73933 691225154 6660 599 691225145 3473403 51 427200630 1326718 2146678 100848386 1569 27 163176119 193562 10784 45687 819951 38520653 225 119620 1 3 691225169 691225164 17445 23807072 1 9093493 5620082 2542 139 14",
"output": "YES"
},
{
"input": "44\n165580141 21 34 55 1 89 144 17711 2 377 610 987 2584 13 5 4181 6765 10946 1597 8 28657 3 233 75025 121393 196418 317811 9227465 832040 1346269 2178309 3524578 5702887 1 14930352 102334155 24157817 39088169 63245986 701408733 267914296 433494437 514229 46368",
"output": "NO"
},
{
"input": "3\n1 1000000000 999999999",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1",
"output": "YES"
},
{
"input": "10\n1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000",
"output": "NO"
},
{
"input": "5\n2 3 4 10 20",
"output": "YES"
},
{
"input": "6\n18 23 40 80 160 161",
"output": "YES"
},
{
"input": "4\n5 6 7 888",
"output": "YES"
},
{
"input": "9\n1 1 2 2 4 5 10 10 20",
"output": "YES"
},
{
"input": "7\n3 150 900 4 500 1500 5",
"output": "YES"
},
{
"input": "3\n2 2 3",
"output": "YES"
},
{
"input": "7\n1 2 100 200 250 1000000 2000000",
"output": "YES"
},
{
"input": "8\n2 3 5 5 5 6 6 13",
"output": "YES"
},
{
"input": "3\n2 3 4",
"output": "YES"
},
{
"input": "6\n1 1 1 4 5 100",
"output": "YES"
},
{
"input": "13\n1 2 3 5 8 13 22 34 55 89 144 233 377",
"output": "YES"
},
{
"input": "4\n2 3 4 8",
"output": "YES"
},
{
"input": "3\n5 6 7",
"output": "YES"
},
{
"input": "5\n1 4 5 6 1000000",
"output": "YES"
},
{
"input": "4\n5 6 7 20",
"output": "YES"
},
{
"input": "6\n1 1 1 1 1 65",
"output": "YES"
},
{
"input": "4\n3 4 5 100",
"output": "YES"
},
{
"input": "3\n2 4 5",
"output": "YES"
},
{
"input": "7\n1 1 1 1 1 10 1000",
"output": "YES"
},
{
"input": "4\n1 1 2 3",
"output": "NO"
},
{
"input": "11\n1 2 5 6 7 8 9 17 18 19 100",
"output": "YES"
},
{
"input": "4\n5 16 20 200",
"output": "YES"
},
{
"input": "5\n17 6 3 3 1",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "YES"
},
{
"input": "6\n1 1 1 2 3 5",
"output": "YES"
},
{
"input": "4\n2 4 6 6",
"output": "YES"
},
{
"input": "9\n1 2 4 4 4 4 7 8 20",
"output": "YES"
},
{
"input": "9\n1 1 2 5 5 5 10 10 20",
"output": "YES"
},
{
"input": "7\n3 150 600 4 1700 6000 5",
"output": "YES"
},
{
"input": "5\n5761 20966 27841 28800 29399",
"output": "YES"
},
{
"input": "9\n1 2 3 6 7 10 11 12 24",
"output": "YES"
},
{
"input": "4\n1 2 1 1",
"output": "YES"
},
{
"input": "5\n1 1 2 3 4",
"output": "YES"
}
] | 1,686,216,107 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 20 | 77 | 12,800,000 | """
B. Mahmoud and a Triangle: constructive algorithms, geometry, greedy, math, number theory, sortings
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output
Mahmoud has n line segments, the i-th of them has length ai.
Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle.
Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge.
Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle.
Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length.
A non-degenerate triangle is a triangle with positive area.
Input
The first line contains single integer n (3 ≤ n ≤ 10^5) — the number of line segments Mahmoud has.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 10^9) — the lengths of line segments Mahmoud has.
Output
In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.
"""
def mahmoud_and_a_triangle():
n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
# print(sum(a[-3:-1]))
# print(a.index(n - 1))
print('YES' if sum(a[-3:-1]) > max(a) else 'NO')
# print()
# for i in a[-3:-1]:
# print(i)
if __name__ == '__main__':
mahmoud_and_a_triangle() | Title: Mahmoud and a Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud has *n* line segments, the *i*-th of them has length *a**i*. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle.
Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area.
Input Specification:
The first line contains single integer *n* (3<=≤<=*n*<=≤<=105) — the number of line segments Mahmoud has.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the lengths of line segments Mahmoud has.
Output Specification:
In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.
Demo Input:
['5\n1 5 3 2 4\n', '3\n4 1 2\n']
Demo Output:
['YES\n', 'NO\n']
Note:
For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle. | ```python
"""
B. Mahmoud and a Triangle: constructive algorithms, geometry, greedy, math, number theory, sortings
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output
Mahmoud has n line segments, the i-th of them has length ai.
Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle.
Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge.
Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle.
Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length.
A non-degenerate triangle is a triangle with positive area.
Input
The first line contains single integer n (3 ≤ n ≤ 10^5) — the number of line segments Mahmoud has.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 10^9) — the lengths of line segments Mahmoud has.
Output
In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.
"""
def mahmoud_and_a_triangle():
n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
# print(sum(a[-3:-1]))
# print(a.index(n - 1))
print('YES' if sum(a[-3:-1]) > max(a) else 'NO')
# print()
# for i in a[-3:-1]:
# print(i)
if __name__ == '__main__':
mahmoud_and_a_triangle()
``` | 0 |
|
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string. | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
},
{
"input": "5\naaaaa",
"output": "aaaaa"
},
{
"input": "3\naabaaaaabb",
"output": "-1"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "2\nbabac",
"output": "-1"
},
{
"input": "3\nbbbccc",
"output": "bcbcbc"
},
{
"input": "2\naa",
"output": "aa"
},
{
"input": "250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece",
"output": "cececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece"
},
{
"input": "15\nabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaa",
"output": "aaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbc"
},
{
"input": "1\naaa",
"output": "aaa"
},
{
"input": "1\naabaab",
"output": "aaaabb"
},
{
"input": "2\naabbbbccccccdddddddd",
"output": "abbcccddddabbcccdddd"
},
{
"input": "3\naaaaaaaaacccdddddd",
"output": "aaacddaaacddaaacdd"
},
{
"input": "3\naaaaaaaaacccbbbbbb",
"output": "aaabbcaaabbcaaabbc"
},
{
"input": "2\naazzzz",
"output": "azzazz"
},
{
"input": "2\naaaa",
"output": "aaaa"
},
{
"input": "2\naaaazz",
"output": "aazaaz"
},
{
"input": "2\naaaabb",
"output": "aabaab"
},
{
"input": "2\naabbbb",
"output": "abbabb"
},
{
"input": "2\naaaazzzz",
"output": "aazzaazz"
},
{
"input": "2\naaazz",
"output": "-1"
},
{
"input": "2\nbbbbaa",
"output": "abbabb"
},
{
"input": "2\naaaaaabbbb",
"output": "aaabbaaabb"
},
{
"input": "2\naaaaaazz",
"output": "aaazaaaz"
},
{
"input": "2\naaaabbbb",
"output": "aabbaabb"
},
{
"input": "2\naabaab",
"output": "aabaab"
},
{
"input": "1\naaaaa",
"output": "aaaaa"
},
{
"input": "2\nbbaaaa",
"output": "aabaab"
},
{
"input": "2\nacaccc",
"output": "accacc"
}
] | 1,627,109,829 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 186 | 20,172,800 | n = int(input())
s=input()
ofc=sorted(s)
pack=ofc[::n]*n
if(ofc==sorted(pack)):
print(''.join(pack))
else:
print('-1')
print(pack) | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string *s*, consisting of lowercase English letters and a positive integer *k*. Your task is to reorder the letters in the string *s* in such a way that the resulting string is a *k*-string.
Input Specification:
The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*.
Output Specification:
Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes).
Demo Input:
['2\naazz\n', '3\nabcabcabz\n']
Demo Output:
['azaz\n', '-1\n']
Note:
none | ```python
n = int(input())
s=input()
ofc=sorted(s)
pack=ofc[::n]*n
if(ofc==sorted(pack)):
print(''.join(pack))
else:
print('-1')
print(pack)
``` | 0 |
|
818 | E | Card Game Again | PROGRAMMING | 1,900 | [
"binary search",
"data structures",
"number theory",
"two pointers"
] | null | null | Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of *n* cards and a magic number *k*. The order of the cards in the deck is fixed. Each card has a number written on it; number *a**i* is written on the *i*-th card in the deck.
After receiving the deck and the magic number, Vova removes *x* (possibly *x*<==<=0) cards from the top of the deck, *y* (possibly *y*<==<=0) cards from the bottom of the deck, and the rest of the deck is his new deck (Vova has to leave at least one card in the deck after removing cards). So Vova's new deck actually contains cards *x*<=+<=1, *x*<=+<=2, ... *n*<=-<=*y*<=-<=1, *n*<=-<=*y* from the original deck.
Vova's new deck is considered valid iff the product of all numbers written on the cards in his new deck is divisible by *k*. So Vova received a deck (possibly not a valid one) and a number *k*, and now he wonders, how many ways are there to choose *x* and *y* so the deck he will get after removing *x* cards from the top and *y* cards from the bottom is valid? | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=109).
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) — the numbers written on the cards. | Print the number of ways to choose *x* and *y* so the resulting deck is valid. | [
"3 4\n6 2 8\n",
"3 6\n9 1 14\n"
] | [
"4\n",
"1\n"
] | In the first example the possible values of *x* and *y* are:
1. *x* = 0, *y* = 0; 1. *x* = 1, *y* = 0; 1. *x* = 2, *y* = 0; 1. *x* = 0, *y* = 1. | 0 | [
{
"input": "3 4\n6 2 8",
"output": "4"
},
{
"input": "3 6\n9 1 14",
"output": "1"
},
{
"input": "5 1\n1 3 1 3 1",
"output": "15"
},
{
"input": "5 1\n5 5 5 5 5",
"output": "15"
},
{
"input": "5 1\n5 4 4 4 4",
"output": "15"
},
{
"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": "5050"
},
{
"input": "100 1\n3 3 2 1 1 2 1 2 3 4 1 5 2 4 5 1 1 3 2 3 4 2 1 3 4 4 5 5 1 5 2 5 3 3 1 1 1 3 2 2 3 4 4 4 4 3 1 3 5 3 3 3 3 2 3 2 2 3 3 1 2 4 3 2 2 5 3 1 5 2 2 5 1 2 1 1 5 1 5 2 4 5 3 4 2 5 4 2 2 5 5 5 3 3 5 3 4 3 3 1",
"output": "5050"
},
{
"input": "100 5\n4 4 3 2 4 4 1 2 2 1 5 3 2 5 5 3 2 3 4 5 2 2 3 4 2 4 3 1 2 3 5 5 1 3 3 5 2 3 3 4 1 3 1 5 4 4 2 1 5 1 4 4 1 5 1 1 5 5 5 4 1 3 1 2 3 2 4 5 5 1 3 4 3 3 1 2 2 4 1 5 1 1 2 4 4 4 5 5 5 3 4 3 3 3 3 2 1 1 5 5",
"output": "4713"
},
{
"input": "100 6\n4 4 1 1 1 1 3 3 5 5 4 2 2 4 3 4 4 5 5 4 5 1 3 1 5 4 5 1 2 5 5 2 2 4 2 4 4 2 5 5 3 3 1 3 3 5 2 3 1 4 1 4 4 1 5 5 1 2 3 2 3 3 5 3 4 2 3 4 3 1 5 3 5 5 3 5 4 4 3 1 1 2 1 2 1 3 2 4 3 2 1 4 3 1 1 5 1 5 4 3",
"output": "4580"
},
{
"input": "100 72\n8 8 7 9 6 1 4 5 3 7 5 10 5 4 1 3 4 1 3 1 6 6 4 5 4 5 6 1 10 7 9 1 6 10 6 6 9 3 3 4 5 9 4 9 8 1 5 9 3 7 1 8 5 2 1 1 7 7 7 6 6 4 2 9 10 2 8 3 1 1 4 8 5 9 7 10 9 4 2 3 7 7 6 7 8 5 1 3 8 5 1 8 9 10 3 7 1 8 10 5",
"output": "4549"
},
{
"input": "100 72\n3 2 1 3 3 3 4 3 5 5 2 5 1 2 2 2 1 4 1 5 1 4 5 4 3 1 4 3 4 4 1 4 4 3 4 1 4 4 5 2 2 3 3 5 4 5 4 2 4 3 1 1 1 4 5 5 3 1 5 3 4 4 5 3 5 1 4 3 2 2 1 4 2 1 3 2 4 2 1 4 4 1 3 4 4 4 1 5 5 2 5 2 3 1 5 1 1 1 2 3",
"output": "4123"
},
{
"input": "2 999634589\n31607 31627",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 2\n1",
"output": "0"
},
{
"input": "1 3\n1",
"output": "0"
},
{
"input": "1 4\n1",
"output": "0"
},
{
"input": "1 5\n3",
"output": "0"
},
{
"input": "1 6\n4",
"output": "0"
},
{
"input": "1 7\n2",
"output": "0"
},
{
"input": "1 8\n3",
"output": "0"
},
{
"input": "1 9\n5",
"output": "0"
},
{
"input": "1 10\n3",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "3"
},
{
"input": "2 2\n2 2",
"output": "3"
},
{
"input": "2 3\n1 2",
"output": "0"
},
{
"input": "2 4\n1 2",
"output": "0"
},
{
"input": "2 5\n1 1",
"output": "0"
},
{
"input": "2 6\n2 1",
"output": "0"
},
{
"input": "2 7\n1 4",
"output": "0"
},
{
"input": "2 8\n5 3",
"output": "0"
},
{
"input": "2 9\n2 2",
"output": "0"
},
{
"input": "2 10\n6 1",
"output": "0"
},
{
"input": "3 1\n1 1 1",
"output": "6"
},
{
"input": "3 2\n2 2 1",
"output": "5"
},
{
"input": "3 3\n2 1 2",
"output": "0"
},
{
"input": "3 4\n2 2 2",
"output": "3"
},
{
"input": "3 5\n1 1 2",
"output": "0"
},
{
"input": "3 6\n4 3 2",
"output": "3"
},
{
"input": "3 7\n3 4 1",
"output": "0"
},
{
"input": "3 8\n5 1 4",
"output": "0"
},
{
"input": "3 9\n3 2 1",
"output": "0"
},
{
"input": "3 10\n6 5 5",
"output": "2"
},
{
"input": "4 1\n1 1 1 1",
"output": "10"
},
{
"input": "4 2\n2 2 1 2",
"output": "9"
},
{
"input": "4 3\n2 1 1 1",
"output": "0"
},
{
"input": "4 4\n2 2 1 1",
"output": "3"
},
{
"input": "4 5\n2 3 2 1",
"output": "0"
},
{
"input": "4 6\n1 1 3 3",
"output": "0"
},
{
"input": "4 7\n1 1 2 2",
"output": "0"
},
{
"input": "4 8\n5 4 5 5",
"output": "0"
},
{
"input": "4 9\n1 1 4 2",
"output": "0"
},
{
"input": "4 10\n2 6 2 1",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "15"
},
{
"input": "5 2\n2 2 1 2 1",
"output": "13"
},
{
"input": "5 3\n2 1 1 2 1",
"output": "0"
},
{
"input": "5 4\n2 2 1 3 1",
"output": "4"
},
{
"input": "5 5\n2 3 1 1 3",
"output": "0"
},
{
"input": "5 6\n3 4 3 4 3",
"output": "10"
},
{
"input": "5 7\n3 1 3 2 4",
"output": "0"
},
{
"input": "5 8\n2 2 3 3 1",
"output": "0"
},
{
"input": "5 9\n3 1 3 3 4",
"output": "7"
},
{
"input": "5 10\n3 6 6 1 5",
"output": "3"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "21"
},
{
"input": "6 2\n1 2 2 1 1 1",
"output": "14"
},
{
"input": "6 3\n2 2 2 2 1 2",
"output": "0"
},
{
"input": "6 4\n1 3 3 3 3 2",
"output": "0"
},
{
"input": "6 5\n2 3 3 2 1 2",
"output": "0"
},
{
"input": "6 6\n1 2 4 1 4 4",
"output": "0"
},
{
"input": "6 7\n2 2 4 3 2 1",
"output": "0"
},
{
"input": "6 8\n3 2 3 5 5 3",
"output": "0"
},
{
"input": "6 9\n1 4 1 2 1 1",
"output": "0"
},
{
"input": "6 10\n1 2 5 6 6 6",
"output": "11"
},
{
"input": "7 1\n1 1 1 1 1 1 1",
"output": "28"
},
{
"input": "7 2\n1 1 2 2 2 2 1",
"output": "24"
},
{
"input": "7 3\n2 2 1 1 2 2 2",
"output": "0"
},
{
"input": "7 4\n3 2 1 2 1 1 1",
"output": "8"
},
{
"input": "7 5\n2 3 3 3 2 3 2",
"output": "0"
},
{
"input": "7 6\n3 4 4 1 4 3 2",
"output": "15"
},
{
"input": "7 7\n4 2 4 4 1 4 4",
"output": "0"
},
{
"input": "7 8\n4 4 2 4 2 5 3",
"output": "18"
},
{
"input": "7 9\n2 1 3 4 4 5 4",
"output": "0"
},
{
"input": "7 10\n6 3 3 5 3 6 1",
"output": "10"
},
{
"input": "8 1\n1 1 1 1 1 1 1 1",
"output": "36"
},
{
"input": "8 2\n1 1 1 1 1 1 1 2",
"output": "8"
},
{
"input": "8 3\n1 1 2 2 1 1 2 2",
"output": "0"
},
{
"input": "8 4\n2 3 2 3 3 3 2 3",
"output": "10"
},
{
"input": "8 5\n1 3 1 2 2 2 1 3",
"output": "0"
},
{
"input": "8 6\n4 2 4 2 1 2 1 4",
"output": "0"
},
{
"input": "8 7\n2 2 1 4 4 4 2 2",
"output": "0"
},
{
"input": "8 8\n5 2 1 2 4 2 2 4",
"output": "21"
},
{
"input": "8 9\n4 4 2 2 5 5 4 1",
"output": "0"
},
{
"input": "8 10\n2 1 4 4 3 4 4 6",
"output": "0"
},
{
"input": "9 1\n1 1 1 1 1 1 1 1 1",
"output": "45"
},
{
"input": "9 2\n1 1 1 2 1 1 2 2 2",
"output": "36"
},
{
"input": "9 3\n1 1 1 2 2 1 1 2 1",
"output": "0"
},
{
"input": "9 4\n1 1 2 1 2 1 1 1 1",
"output": "15"
},
{
"input": "9 5\n3 2 3 2 3 1 1 3 2",
"output": "0"
},
{
"input": "9 6\n2 1 1 3 2 4 1 2 2",
"output": "21"
},
{
"input": "9 7\n4 3 2 1 2 3 3 4 4",
"output": "0"
},
{
"input": "9 8\n5 5 2 1 3 1 3 1 3",
"output": "0"
},
{
"input": "9 9\n2 4 1 4 4 3 3 4 1",
"output": "18"
},
{
"input": "9 10\n4 3 2 5 2 2 2 2 6",
"output": "23"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "55"
},
{
"input": "10 2\n2 2 2 2 2 2 2 1 2 1",
"output": "53"
},
{
"input": "10 3\n2 2 1 1 2 2 2 2 1 2",
"output": "0"
},
{
"input": "10 4\n1 1 2 3 3 1 2 2 2 3",
"output": "26"
},
{
"input": "10 5\n3 3 2 2 3 1 1 1 3 1",
"output": "0"
},
{
"input": "10 6\n4 4 4 3 2 1 1 1 2 4",
"output": "27"
},
{
"input": "10 7\n4 2 2 2 3 3 2 4 4 3",
"output": "0"
},
{
"input": "10 8\n5 4 1 4 3 2 1 2 3 3",
"output": "24"
},
{
"input": "10 9\n1 2 3 4 5 2 3 5 5 4",
"output": "12"
},
{
"input": "10 10\n5 3 2 5 1 2 5 1 5 1",
"output": "35"
},
{
"input": "1 1000000000\n1",
"output": "0"
},
{
"input": "1 1000000000\n1000000000",
"output": "1"
},
{
"input": "1 100000000\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
}
] | 1,522,777,809 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 77 | 7,065,600 | count=0
def is_valid(l,k):
pro=1
for i in l:
pro=pro*i
if(pro%k==0):
return 1
else:
return 0
def e_card(l,k):
global count
if(is_valid(l,k)):
count+=1
if(len(l)==1):
return
else:
m=l[len(l)-1]
l.pop()
e_card(l,k)
l.append(m)
m=l[0]
l.pop(0)
e_card(l,k)
l.insert(0,m)
n,k=[int(x) for x in input().strip().split()]
e_card([int(x) for x in input().strip().split()],k)
print(count) | Title: Card Game Again
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of *n* cards and a magic number *k*. The order of the cards in the deck is fixed. Each card has a number written on it; number *a**i* is written on the *i*-th card in the deck.
After receiving the deck and the magic number, Vova removes *x* (possibly *x*<==<=0) cards from the top of the deck, *y* (possibly *y*<==<=0) cards from the bottom of the deck, and the rest of the deck is his new deck (Vova has to leave at least one card in the deck after removing cards). So Vova's new deck actually contains cards *x*<=+<=1, *x*<=+<=2, ... *n*<=-<=*y*<=-<=1, *n*<=-<=*y* from the original deck.
Vova's new deck is considered valid iff the product of all numbers written on the cards in his new deck is divisible by *k*. So Vova received a deck (possibly not a valid one) and a number *k*, and now he wonders, how many ways are there to choose *x* and *y* so the deck he will get after removing *x* cards from the top and *y* cards from the bottom is valid?
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=109).
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) — the numbers written on the cards.
Output Specification:
Print the number of ways to choose *x* and *y* so the resulting deck is valid.
Demo Input:
['3 4\n6 2 8\n', '3 6\n9 1 14\n']
Demo Output:
['4\n', '1\n']
Note:
In the first example the possible values of *x* and *y* are:
1. *x* = 0, *y* = 0; 1. *x* = 1, *y* = 0; 1. *x* = 2, *y* = 0; 1. *x* = 0, *y* = 1. | ```python
count=0
def is_valid(l,k):
pro=1
for i in l:
pro=pro*i
if(pro%k==0):
return 1
else:
return 0
def e_card(l,k):
global count
if(is_valid(l,k)):
count+=1
if(len(l)==1):
return
else:
m=l[len(l)-1]
l.pop()
e_card(l,k)
l.append(m)
m=l[0]
l.pop(0)
e_card(l,k)
l.insert(0,m)
n,k=[int(x) for x in input().strip().split()]
e_card([int(x) for x in input().strip().split()],k)
print(count)
``` | 0 |
|
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,640,790,610 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n=int(input())
a=list(map(int,input().split()))
i=0
while i<n and a[i]>a[i-1]:
i=i+1
while i<n and a[i]==a[i-1]:
i=i+1
while i<n and a[i]<a[i-1]:
i=i+1
if i==n:
print("YES")
else:
print("NO")
| 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()))
i=0
while i<n and a[i]>a[i-1]:
i=i+1
while i<n and a[i]==a[i-1]:
i=i+1
while i<n and a[i]<a[i-1]:
i=i+1
if i==n:
print("YES")
else:
print("NO")
``` | 0 |
|
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set. | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"output": "2"
},
{
"input": "{a}",
"output": "1"
},
{
"input": "{b, a, b, a, b, c, c, b, c, b}",
"output": "3"
},
{
"input": "{e, g, c, e}",
"output": "3"
},
{
"input": "{a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a}",
"output": "1"
},
{
"input": "{a, a, b}",
"output": "2"
},
{
"input": "{a, b, b, b, a, b, a, a, a, a, a, a, b, a, b, a, a, a, a, a, b, a, b, a}",
"output": "2"
},
{
"input": "{j, u, a, c, f, w, e, w, x, t, h, p, v, n, i, l, x, n, i, b, u, c, a, a}",
"output": "16"
},
{
"input": "{x, i, w, c, p, e, h, z, k, i}",
"output": "9"
},
{
"input": "{t, k, o, x, r, d, q, j, k, e, z, w, y, r, z, s, s, e, s, b, k, i}",
"output": "15"
},
{
"input": "{y}",
"output": "1"
},
{
"input": "{x}",
"output": "1"
},
{
"input": "{b, z, a, z}",
"output": "3"
},
{
"input": "{z}",
"output": "1"
},
{
"input": "{a, z}",
"output": "2"
},
{
"input": "{a, b, z}",
"output": "3"
},
{
"input": "{s, q, z, r, t, a, b, h, j, i, o, z, r, q}",
"output": "11"
}
] | 1,699,752,063 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | s = input()
if len(s) == 2:
print(0)
else:
print(len(set(s[1:-1].split(', '))))
| Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
Input Specification:
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Output Specification:
Print a single number — the number of distinct letters in Anton's set.
Demo Input:
['{a, b, c}\n', '{b, a, b, a}\n', '{}\n']
Demo Output:
['3\n', '2\n', '0\n']
Note:
none | ```python
s = input()
if len(s) == 2:
print(0)
else:
print(len(set(s[1:-1].split(', '))))
``` | 3 |
|
807 | A | Is it rated? | PROGRAMMING | 900 | [
"implementation",
"sortings"
] | null | null | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.
It's known that if at least one participant's rating has changed, then the round was rated for sure.
It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed.
In this problem, you should not make any other assumptions about the rating system.
Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings. | If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". | [
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] | [
"rated\n",
"unrated\n",
"maybe\n"
] | In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure.
In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not. | 500 | [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
"input": "2\n1 1\n1 1",
"output": "maybe"
},
{
"input": "2\n4126 4126\n4126 4126",
"output": "maybe"
},
{
"input": "10\n446 446\n1331 1331\n3594 3594\n1346 1902\n91 91\n3590 3590\n2437 2437\n4007 3871\n2797 699\n1423 1423",
"output": "rated"
},
{
"input": "10\n4078 4078\n2876 2876\n1061 1061\n3721 3721\n143 143\n2992 2992\n3279 3279\n3389 3389\n1702 1702\n1110 1110",
"output": "unrated"
},
{
"input": "10\n4078 4078\n3721 3721\n3389 3389\n3279 3279\n2992 2992\n2876 2876\n1702 1702\n1110 1110\n1061 1061\n143 143",
"output": "maybe"
},
{
"input": "2\n3936 3936\n2967 2967",
"output": "maybe"
},
{
"input": "2\n1 1\n2 2",
"output": "unrated"
},
{
"input": "2\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n2 1\n1 2",
"output": "rated"
},
{
"input": "2\n2967 2967\n3936 3936",
"output": "unrated"
},
{
"input": "3\n1200 1200\n1200 1200\n1300 1300",
"output": "unrated"
},
{
"input": "3\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "3\n1 1\n1 1\n2 2",
"output": "unrated"
},
{
"input": "2\n3 2\n3 2",
"output": "rated"
},
{
"input": "3\n5 5\n4 4\n3 4",
"output": "rated"
},
{
"input": "3\n200 200\n200 200\n300 300",
"output": "unrated"
},
{
"input": "3\n1 1\n2 2\n3 3",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2245 2245\n1699 1699",
"output": "maybe"
},
{
"input": "2\n10 10\n8 8",
"output": "maybe"
},
{
"input": "3\n1500 1500\n1500 1500\n1600 1600",
"output": "unrated"
},
{
"input": "3\n1500 1500\n1500 1500\n1700 1700",
"output": "unrated"
},
{
"input": "4\n100 100\n100 100\n70 70\n80 80",
"output": "unrated"
},
{
"input": "2\n1 2\n2 1",
"output": "rated"
},
{
"input": "3\n5 5\n4 3\n3 3",
"output": "rated"
},
{
"input": "3\n1600 1650\n1500 1550\n1400 1450",
"output": "rated"
},
{
"input": "4\n2000 2000\n1500 1500\n1500 1500\n1700 1700",
"output": "unrated"
},
{
"input": "4\n1500 1500\n1400 1400\n1400 1400\n1700 1700",
"output": "unrated"
},
{
"input": "2\n1600 1600\n1400 1400",
"output": "maybe"
},
{
"input": "2\n3 1\n9 8",
"output": "rated"
},
{
"input": "2\n2 1\n1 1",
"output": "rated"
},
{
"input": "4\n4123 4123\n4123 4123\n2670 2670\n3670 3670",
"output": "unrated"
},
{
"input": "2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "2\n10 11\n5 4",
"output": "rated"
},
{
"input": "2\n15 14\n13 12",
"output": "rated"
},
{
"input": "2\n2 1\n2 2",
"output": "rated"
},
{
"input": "3\n2670 2670\n3670 3670\n4106 4106",
"output": "unrated"
},
{
"input": "3\n4 5\n3 3\n2 2",
"output": "rated"
},
{
"input": "2\n10 9\n10 10",
"output": "rated"
},
{
"input": "3\n1011 1011\n1011 999\n2200 2100",
"output": "rated"
},
{
"input": "2\n3 3\n5 5",
"output": "unrated"
},
{
"input": "2\n1500 1500\n3000 2000",
"output": "rated"
},
{
"input": "2\n5 6\n5 5",
"output": "rated"
},
{
"input": "3\n2000 2000\n1500 1501\n500 500",
"output": "rated"
},
{
"input": "2\n2 3\n2 2",
"output": "rated"
},
{
"input": "2\n3 3\n2 2",
"output": "maybe"
},
{
"input": "2\n1 2\n1 1",
"output": "rated"
},
{
"input": "4\n3123 3123\n2777 2777\n2246 2246\n1699 1699",
"output": "maybe"
},
{
"input": "2\n15 14\n14 13",
"output": "rated"
},
{
"input": "4\n3000 3000\n2900 2900\n3000 3000\n2900 2900",
"output": "unrated"
},
{
"input": "6\n30 3060\n24 2194\n26 2903\n24 2624\n37 2991\n24 2884",
"output": "rated"
},
{
"input": "2\n100 99\n100 100",
"output": "rated"
},
{
"input": "4\n2 2\n1 1\n1 1\n2 2",
"output": "unrated"
},
{
"input": "3\n100 101\n100 100\n100 100",
"output": "rated"
},
{
"input": "4\n1000 1001\n900 900\n950 950\n890 890",
"output": "rated"
},
{
"input": "2\n2 3\n1 1",
"output": "rated"
},
{
"input": "2\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n3 2\n2 2",
"output": "rated"
},
{
"input": "2\n3 2\n3 3",
"output": "rated"
},
{
"input": "2\n1 1\n2 2",
"output": "unrated"
},
{
"input": "3\n3 2\n3 3\n3 3",
"output": "rated"
},
{
"input": "4\n1500 1501\n1300 1300\n1200 1200\n1400 1400",
"output": "rated"
},
{
"input": "3\n1000 1000\n500 500\n400 300",
"output": "rated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n3000 3000",
"output": "unrated"
},
{
"input": "2\n1 1\n2 3",
"output": "rated"
},
{
"input": "2\n6 2\n6 2",
"output": "rated"
},
{
"input": "5\n3123 3123\n1699 1699\n2777 2777\n2246 2246\n2246 2246",
"output": "unrated"
},
{
"input": "2\n1500 1500\n1600 1600",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2241 2241\n1699 1699",
"output": "maybe"
},
{
"input": "2\n20 30\n10 5",
"output": "rated"
},
{
"input": "3\n1 1\n2 2\n1 1",
"output": "unrated"
},
{
"input": "2\n1 2\n3 3",
"output": "rated"
},
{
"input": "5\n5 5\n4 4\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n2 2\n2 1",
"output": "rated"
},
{
"input": "2\n100 100\n90 89",
"output": "rated"
},
{
"input": "2\n1000 900\n2000 2000",
"output": "rated"
},
{
"input": "2\n50 10\n10 50",
"output": "rated"
},
{
"input": "2\n200 200\n100 100",
"output": "maybe"
},
{
"input": "3\n2 2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "3\n1000 1000\n300 300\n100 100",
"output": "maybe"
},
{
"input": "4\n2 2\n2 2\n3 3\n4 4",
"output": "unrated"
},
{
"input": "2\n5 3\n6 3",
"output": "rated"
},
{
"input": "2\n1200 1100\n1200 1000",
"output": "rated"
},
{
"input": "2\n5 5\n4 4",
"output": "maybe"
},
{
"input": "2\n5 5\n3 3",
"output": "maybe"
},
{
"input": "5\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n1100 1100",
"output": "unrated"
},
{
"input": "5\n10 10\n9 9\n8 8\n7 7\n6 6",
"output": "maybe"
},
{
"input": "3\n1000 1000\n300 300\n10 10",
"output": "maybe"
},
{
"input": "5\n6 6\n5 5\n4 4\n3 3\n2 2",
"output": "maybe"
},
{
"input": "2\n3 3\n1 1",
"output": "maybe"
},
{
"input": "4\n2 2\n2 2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "2\n1000 1000\n700 700",
"output": "maybe"
},
{
"input": "2\n4 3\n5 3",
"output": "rated"
},
{
"input": "2\n1000 1000\n1100 1100",
"output": "unrated"
},
{
"input": "4\n5 5\n4 4\n3 3\n2 2",
"output": "maybe"
},
{
"input": "3\n1 1\n2 3\n2 2",
"output": "rated"
},
{
"input": "2\n1 2\n1 3",
"output": "rated"
},
{
"input": "2\n3 3\n1 2",
"output": "rated"
},
{
"input": "4\n1501 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "rated"
},
{
"input": "5\n1 1\n2 2\n3 3\n4 4\n5 5",
"output": "unrated"
},
{
"input": "2\n10 10\n1 2",
"output": "rated"
},
{
"input": "6\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n1900 1900",
"output": "unrated"
},
{
"input": "6\n3123 3123\n2777 2777\n3000 3000\n2246 2246\n2246 2246\n1699 1699",
"output": "unrated"
},
{
"input": "2\n100 100\n110 110",
"output": "unrated"
},
{
"input": "3\n3 3\n3 3\n4 4",
"output": "unrated"
},
{
"input": "3\n3 3\n3 2\n4 4",
"output": "rated"
},
{
"input": "3\n5 2\n4 4\n3 3",
"output": "rated"
},
{
"input": "4\n4 4\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n1 1\n3 2",
"output": "rated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n2699 2699",
"output": "unrated"
},
{
"input": "3\n3 3\n3 3\n3 4",
"output": "rated"
},
{
"input": "3\n1 2\n2 2\n3 3",
"output": "rated"
},
{
"input": "3\n1 2\n1 2\n1 2",
"output": "rated"
},
{
"input": "2\n2 1\n2 1",
"output": "rated"
},
{
"input": "2\n1 2\n3 4",
"output": "rated"
},
{
"input": "2\n3 2\n2 3",
"output": "rated"
},
{
"input": "3\n1500 1500\n1600 1600\n1600 1600",
"output": "unrated"
},
{
"input": "3\n1 1\n3 3\n4 4",
"output": "unrated"
},
{
"input": "3\n1 1\n2 2\n2 2",
"output": "unrated"
},
{
"input": "2\n10 12\n8 8",
"output": "rated"
},
{
"input": "5\n1200 1200\n1500 1500\n1500 1500\n1500 1500\n1500 1500",
"output": "unrated"
},
{
"input": "2\n1 2\n2 2",
"output": "rated"
},
{
"input": "3\n1500 1400\n1200 1200\n1100 1100",
"output": "rated"
},
{
"input": "2\n10 12\n10 10",
"output": "rated"
},
{
"input": "3\n1500 1500\n1400 1400\n1300 1300",
"output": "maybe"
},
{
"input": "3\n3 3\n4 4\n5 5",
"output": "unrated"
},
{
"input": "3\n2 6\n3 5\n4 4",
"output": "rated"
},
{
"input": "2\n5 6\n4 6",
"output": "rated"
},
{
"input": "4\n10 10\n10 10\n7 7\n8 8",
"output": "unrated"
},
{
"input": "2\n4 4\n3 3",
"output": "maybe"
}
] | 1,656,762,481 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | def main():
number_of_participant=int(input())
flag=0
participant=[]
for i in range(number_of_participant):
ranking=input()
ranking=ranking.split()
if ranking[0]!=ranking[1]:
flag=1
participant.append(int(ranking[0]))
if flag==1:
print("rated")
else:
if sorted(participant)==participant:
print("maybe")
else:
print("unrated")
if __name__=="__main__":
main() | Title: Is it rated?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.
It's known that if at least one participant's rating has changed, then the round was rated for sure.
It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed.
In this problem, you should not make any other assumptions about the rating system.
Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.
Output Specification:
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
Demo Input:
['6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n', '4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n', '5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n']
Demo Output:
['rated\n', 'unrated\n', 'maybe\n']
Note:
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure.
In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not. | ```python
def main():
number_of_participant=int(input())
flag=0
participant=[]
for i in range(number_of_participant):
ranking=input()
ranking=ranking.split()
if ranking[0]!=ranking[1]:
flag=1
participant.append(int(ranking[0]))
if flag==1:
print("rated")
else:
if sorted(participant)==participant:
print("maybe")
else:
print("unrated")
if __name__=="__main__":
main()
``` | 0 |
|
127 | A | Wasted Time | PROGRAMMING | 900 | [
"geometry"
] | null | null | Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.
Mr. Scrooge's signature can be represented as a polyline *A*1*A*2... *A**n*. Scrooge signs like that: first it places a pen at the point *A*1, then draws a segment from point *A*1 to point *A*2, then he draws a segment from point *A*2 to point *A*3 and so on to point *A**n*, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant — 50 millimeters per second.
Scrooge signed exactly *k* papers throughout his life and all those signatures look the same.
Find the total time Scrooge wasted signing the papers. | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* — integers *x**i* and *y**i*, separated by a space.
All points *A**i* are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters. | Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6. | [
"2 1\n0 0\n10 0\n",
"5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n",
"6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n"
] | [
"0.200000000",
"6.032163204",
"3.000000000"
] | none | 500 | [
{
"input": "2 1\n0 0\n10 0",
"output": "0.200000000"
},
{
"input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0",
"output": "6.032163204"
},
{
"input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0",
"output": "3.000000000"
},
{
"input": "10 95\n-20 -5\n2 -8\n14 13\n10 3\n17 11\n13 -12\n-6 11\n14 -15\n-13 14\n19 8",
"output": "429.309294877"
},
{
"input": "30 1000\n4 -13\n14 13\n-14 -16\n-9 18\n17 11\n2 -8\n2 15\n8 -1\n-9 13\n8 -12\n-2 20\n11 -12\n19 8\n9 -15\n-20 -5\n-18 20\n-13 14\n-12 -17\n-4 3\n13 -12\n11 -10\n18 7\n-6 11\n10 13\n10 3\n6 -14\n-1 10\n14 -15\n2 11\n-8 10",
"output": "13629.282573522"
},
{
"input": "2 1\n-20 -10\n-10 -6",
"output": "0.215406592"
},
{
"input": "2 13\n13 -10\n-3 -2",
"output": "4.651021393"
},
{
"input": "2 21\n13 8\n14 10",
"output": "0.939148551"
},
{
"input": "2 75\n-3 12\n1 12",
"output": "6.000000000"
},
{
"input": "2 466\n10 16\n-6 -3",
"output": "231.503997374"
},
{
"input": "2 999\n6 16\n-17 -14",
"output": "755.286284531"
},
{
"input": "2 1000\n-17 -14\n-14 -8",
"output": "134.164078650"
},
{
"input": "3 384\n-4 -19\n-17 -2\n3 4",
"output": "324.722285390"
},
{
"input": "5 566\n-11 8\n2 -7\n7 0\n-7 -9\n-7 5",
"output": "668.956254495"
},
{
"input": "7 495\n-10 -13\n-9 -5\n4 9\n8 13\n-4 2\n2 10\n-18 15",
"output": "789.212495576"
},
{
"input": "10 958\n7 13\n20 19\n12 -7\n10 -10\n-13 -15\n-10 -7\n20 -5\n-11 19\n-7 3\n-4 18",
"output": "3415.618464093"
},
{
"input": "13 445\n-15 16\n-8 -14\n8 7\n4 15\n8 -13\n15 -11\n-12 -4\n2 -13\n-5 0\n-20 -14\n-8 -7\n-10 -18\n18 -5",
"output": "2113.552527680"
},
{
"input": "18 388\n11 -8\n13 10\n18 -17\n-15 3\n-13 -15\n20 -7\n1 -10\n-13 -12\n-12 -15\n-17 -8\n1 -2\n3 -20\n-8 -9\n15 -13\n-19 -6\n17 3\n-17 2\n6 6",
"output": "2999.497312668"
},
{
"input": "25 258\n-5 -3\n-18 -14\n12 3\n6 11\n4 2\n-19 -3\n19 -7\n-15 19\n-19 -12\n-11 -10\n-5 17\n10 15\n-4 1\n-3 -20\n6 16\n18 -19\n11 -19\n-17 10\n-17 17\n-2 -17\n-3 -9\n18 13\n14 8\n-2 -5\n-11 4",
"output": "2797.756635934"
},
{
"input": "29 848\n11 -10\n-19 1\n18 18\n19 -19\n0 -5\n16 10\n-20 -14\n7 15\n6 8\n-15 -16\n9 3\n16 -20\n-12 12\n18 -1\n-11 14\n18 10\n11 -20\n-20 -16\n-1 11\n13 10\n-6 13\n-7 -10\n-11 -10\n-10 3\n15 -13\n-4 11\n-13 -11\n-11 -17\n11 -5",
"output": "12766.080247922"
},
{
"input": "36 3\n-11 20\n-11 13\n-17 9\n15 9\n-6 9\n-1 11\n12 -11\n16 -10\n-20 7\n-18 6\n-15 -2\n20 -20\n16 4\n-20 -8\n-12 -15\n-13 -6\n-9 -4\n0 -10\n8 -1\n1 4\n5 8\n8 -15\n16 -12\n19 1\n0 -4\n13 -4\n17 -13\n-7 11\n14 9\n-14 -9\n5 -8\n11 -8\n-17 -5\n1 -3\n-16 -17\n2 -3",
"output": "36.467924851"
},
{
"input": "48 447\n14 9\n9 -17\n-17 11\n-14 14\n19 -8\n-14 -17\n-7 10\n-6 -11\n-9 -19\n19 10\n-4 2\n-5 16\n20 9\n-10 20\n-7 -17\n14 -16\n-2 -10\n-18 -17\n14 12\n-6 -19\n5 -18\n-3 2\n-3 10\n-5 5\n13 -12\n10 -18\n10 -12\n-2 4\n7 -15\n-5 -5\n11 14\n11 10\n-6 -9\n13 -4\n13 9\n6 12\n-13 17\n-9 -12\n14 -19\n10 12\n-15 8\n-1 -11\n19 8\n11 20\n-9 -3\n16 1\n-14 19\n8 -4",
"output": "9495.010556306"
},
{
"input": "50 284\n-17 -13\n7 12\n-13 0\n13 1\n14 6\n14 -9\n-5 -1\n0 -10\n12 -3\n-14 6\n-8 10\n-16 17\n0 -1\n4 -9\n2 6\n1 8\n-8 -14\n3 9\n1 -15\n-4 -19\n-7 -20\n18 10\n3 -11\n10 16\n2 -6\n-9 19\n-3 -1\n20 9\n-12 -5\n-10 -2\n16 -7\n-16 -18\n-2 17\n2 8\n7 -15\n4 1\n6 -17\n19 9\n-10 -20\n5 2\n10 -2\n3 7\n20 0\n8 -14\n-16 -1\n-20 7\n20 -19\n17 18\n-11 -18\n-16 14",
"output": "6087.366930474"
},
{
"input": "57 373\n18 3\n-4 -1\n18 5\n-7 -15\n-6 -10\n-19 1\n20 15\n15 4\n-1 -2\n13 -14\n0 12\n10 3\n-16 -17\n-14 -9\n-11 -10\n17 19\n-2 6\n-12 -15\n10 20\n16 7\n9 -1\n4 13\n8 -2\n-1 -16\n-3 8\n14 11\n-12 3\n-5 -6\n3 4\n5 7\n-9 9\n11 4\n-19 10\n-7 4\n-20 -12\n10 16\n13 11\n13 -11\n7 -1\n17 18\n-19 7\n14 13\n5 -1\n-7 6\n-1 -6\n6 20\n-16 2\n4 17\n16 -11\n-4 -20\n19 -18\n17 16\n-14 -8\n3 2\n-6 -16\n10 -10\n-13 -11",
"output": "8929.162822862"
},
{
"input": "60 662\n15 17\n-2 -19\n-4 -17\n10 0\n15 10\n-8 -14\n14 9\n-15 20\n6 5\n-9 0\n-13 20\n13 -2\n10 9\n7 5\n4 18\n-10 1\n6 -15\n15 -16\n6 13\n4 -6\n2 5\n18 19\n8 3\n-7 14\n-12 -20\n14 19\n-15 0\n-2 -12\n9 18\n14 4\n2 -20\n3 0\n20 9\n-5 11\n-11 1\n2 -19\n-14 -4\n18 6\n16 16\n15 3\n-1 -5\n9 20\n12 -8\n-1 10\n-4 -9\n3 6\n3 -12\n14 -10\n-8 10\n-18 6\n14 -2\n-14 -12\n-10 -7\n10 -6\n14 1\n6 14\n15 19\n4 14\n3 -14\n-9 -13",
"output": "16314.207721932"
},
{
"input": "61 764\n-9 15\n11 -8\n-6 -7\n-13 -19\n16 -16\n-5 -1\n20 -19\n-14 -1\n-11 4\n7 -2\n-3 2\n-14 -17\n15 18\n20 15\n-13 -2\n15 8\n3 13\n19 -10\n2 -6\n15 -3\n-12 11\n4 -16\n-14 20\n0 2\n11 -7\n-6 -11\n16 7\n8 -3\n16 -10\n-3 9\n9 5\n4 -1\n-17 9\n14 -4\n8 6\n-19 12\n10 -17\n-5 7\n7 -3\n5 3\n6 -14\n9 9\n-16 -19\n11 -16\n-17 15\n8 5\n16 -19\n-7 10\n14 -15\n15 19\n-20 -16\n6 -2\n-4 6\n7 -15\n1 -8\n20 -17\n3 7\n10 12\n10 -11\n-19 10\n0 -11",
"output": "22153.369189802"
}
] | 1,635,060,742 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 122 | 17,715,200 | import math
n, k = map(int, input().split())
posx, posy, res = 0, 0, 0
for u in range(n):
x, y = map(int, input().split())
res += math.sqrt(abs(posx - x) ** 2 + abs(posy - y) ** 2)
posx, posy = x, y
print(res * k) | Title: Wasted Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.
Mr. Scrooge's signature can be represented as a polyline *A*1*A*2... *A**n*. Scrooge signs like that: first it places a pen at the point *A*1, then draws a segment from point *A*1 to point *A*2, then he draws a segment from point *A*2 to point *A*3 and so on to point *A**n*, where he stops signing and takes the pen off the paper. At that the resulting line can intersect with itself and partially repeat itself but Scrooge pays no attention to it and never changes his signing style. As Scrooge makes the signature, he never takes the pen off the paper and his writing speed is constant — 50 millimeters per second.
Scrooge signed exactly *k* papers throughout his life and all those signatures look the same.
Find the total time Scrooge wasted signing the papers.
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* — integers *x**i* and *y**i*, separated by a space.
All points *A**i* are different. The absolute value of all coordinates does not exceed 20. The coordinates are measured in millimeters.
Output Specification:
Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6.
Demo Input:
['2 1\n0 0\n10 0\n', '5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n', '6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n']
Demo Output:
['0.200000000', '6.032163204', '3.000000000']
Note:
none | ```python
import math
n, k = map(int, input().split())
posx, posy, res = 0, 0, 0
for u in range(n):
x, y = map(int, input().split())
res += math.sqrt(abs(posx - x) ** 2 + abs(posy - y) ** 2)
posx, posy = x, y
print(res * k)
``` | 0 |
|
32 | A | Reconnaissance | PROGRAMMING | 800 | [
"brute force"
] | A. Reconnaissance | 2 | 256 | According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1,<=2) and (2,<=1) should be regarded as different. | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*. | [
"5 10\n10 20 50 60 65\n",
"5 1\n55 30 29 31 55\n"
] | [
"6\n",
"6\n"
] | none | 500 | [
{
"input": "5 10\n10 20 50 60 65",
"output": "6"
},
{
"input": "5 1\n55 30 29 31 55",
"output": "6"
},
{
"input": "6 10\n4 6 4 1 9 3",
"output": "30"
},
{
"input": "7 100\n19 1694 261 162 1 234 513",
"output": "8"
},
{
"input": "8 42\n37 53 74 187 568 22 5 65",
"output": "20"
},
{
"input": "10 4\n11 6 76 49 28 20 57 152 5 32",
"output": "4"
},
{
"input": "100 100\n51 93 101 960 2 477 213 129 663 925 254 78 1486 274 160 481 132 156 412 372 5 57 152 298 1771 7 359 468 254 406 202 929 221 366 552 97 555 29 822 118 539 140 992 854 7 163 134 103 940 30 409 1003 398 43 555 79 107 40 23 103 643 171 310 382 770 337 18 189 570 177 29 54 855 171 205 291 299 935 620 180 114 358 88 292 118 400 218 537 369 60 683 192 13 537 59 824 264 191 3 300",
"output": "2404"
}
] | 1,642,936,484 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | s=[]
o=0
n,d=input("").split()
n=int(n)
d=int(d)
r=input("")
e= r.split()
for x in e:
x=int(x)
s.append(x)
for z in range(0,len(s)):
for g in range(0,len(s)):
if z != g :
if abs (s[z] - s[g]) <= d :
print(s[z],s[g])
o+=1
if n== len(s):
print(o) | Title: Reconnaissance
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.
Ways (1,<=2) and (2,<=1) should be regarded as different.
Input Specification:
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
Output Specification:
Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*.
Demo Input:
['5 10\n10 20 50 60 65\n', '5 1\n55 30 29 31 55\n']
Demo Output:
['6\n', '6\n']
Note:
none | ```python
s=[]
o=0
n,d=input("").split()
n=int(n)
d=int(d)
r=input("")
e= r.split()
for x in e:
x=int(x)
s.append(x)
for z in range(0,len(s)):
for g in range(0,len(s)):
if z != g :
if abs (s[z] - s[g]) <= d :
print(s[z],s[g])
o+=1
if n== len(s):
print(o)
``` | 0 |
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,651,685,616 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 46 | 0 | # -*- coding: utf-8 -*-
"""831.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1hYxPSks58iBj6lqO-ZFgsg_7bcRbm3l3
"""
#https://codeforces.com/contest/831/problem/A Unimodal Array
a=int(input())
b=list(map(int,input().split()))
i=1
while i<a and b[i-1]<b[i]:
i+=1
while i<a and b[i-1]==b[i]:
i+=1
while i<a and b[i-1]>b[i]:
i+=1
if i==a:
print("Yes")
else:
print("No") | 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
# -*- coding: utf-8 -*-
"""831.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1hYxPSks58iBj6lqO-ZFgsg_7bcRbm3l3
"""
#https://codeforces.com/contest/831/problem/A Unimodal Array
a=int(input())
b=list(map(int,input().split()))
i=1
while i<a and b[i-1]<b[i]:
i+=1
while i<a and b[i-1]==b[i]:
i+=1
while i<a and b[i-1]>b[i]:
i+=1
if i==a:
print("Yes")
else:
print("No")
``` | 3 |
|
262 | A | Roma and Lucky Numbers | PROGRAMMING | 800 | [
"implementation"
] | null | null | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem. | The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces. | In a single line print a single integer — the answer to the problem. | [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n"
] | [
"3\n",
"2\n"
] | In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | 500 | [
{
"input": "3 4\n1 2 4",
"output": "3"
},
{
"input": "3 2\n447 44 77",
"output": "2"
},
{
"input": "2 2\n507978501 180480073",
"output": "2"
},
{
"input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089",
"output": "9"
},
{
"input": "6 100\n170427799 37215529 675016434 168544291 683447134 950090227",
"output": "6"
},
{
"input": "4 2\n194041605 706221269 69909135 257655784",
"output": "3"
},
{
"input": "4 2\n9581849 67346651 530497 272158241",
"output": "4"
},
{
"input": "3 47\n378261451 163985731 230342101",
"output": "3"
},
{
"input": "2 3\n247776868 480572137",
"output": "1"
},
{
"input": "7 77\n366496749 549646417 278840199 119255907 33557677 379268590 150378796",
"output": "7"
},
{
"input": "40 31\n32230963 709031779 144328646 513494529 36547831 416998222 84161665 318773941 170724397 553666286 368402971 48581613 31452501 368026285 47903381 939151438 204145360 189920160 288159400 133145006 314295423 450219949 160203213 358403181 478734385 29331901 31051111 110710191 567314089 139695685 111511396 87708701 317333277 103301481 110400517 634446253 481551313 39202255 105948 738066085",
"output": "40"
},
{
"input": "1 8\n55521105",
"output": "1"
},
{
"input": "49 3\n34644511 150953622 136135827 144208961 359490601 86708232 719413689 188605873 64330753 488776302 104482891 63360106 437791390 46521319 70778345 339141601 136198441 292941209 299339510 582531183 555958105 437904637 74219097 439816011 236010407 122674666 438442529 186501223 63932449 407678041 596993853 92223251 849265278 480265849 30983497 330283357 186901672 20271344 794252593 123774176 27851201 52717531 479907210 196833889 149331196 82147847 255966471 278600081 899317843",
"output": "44"
},
{
"input": "26 2\n330381357 185218042 850474297 483015466 296129476 1205865 538807493 103205601 160403321 694220263 416255901 7245756 507755361 88187633 91426751 1917161 58276681 59540376 576539745 595950717 390256887 105690055 607818885 28976353 488947089 50643601",
"output": "22"
},
{
"input": "38 1\n194481717 126247087 815196361 106258801 381703249 283859137 15290101 40086151 213688513 577996947 513899717 371428417 107799271 11136651 5615081 323386401 381128815 34217126 17709913 520702093 201694245 570931849 169037023 417019726 282437316 7417126 271667553 11375851 185087449 410130883 383045677 5764771 905017051 328584026 215330671 299553233 15838255 234532105",
"output": "20"
},
{
"input": "44 9\n683216389 250581469 130029957 467020047 188395565 206237982 63257361 68314981 732878407 563579660 199133851 53045209 665723851 16273169 10806790 556633156 350593410 474645249 478790761 708234243 71841230 18090541 19836685 146373571 17947452 534010506 46933264 377035021 311636557 75193963 54321761 12759959 71120181 548816939 23608621 31876417 107672995 72575155 369667956 20574379 210596751 532163173 75726739 853719629",
"output": "44"
},
{
"input": "8 6\n204157376 10514197 65483881 347219841 263304577 296402721 11739011 229776191",
"output": "8"
},
{
"input": "38 29\n333702889 680931737 61137217 203030505 68728281 11414209 642645708 590904616 3042901 607198177 189041074 700764043 813035201 198341461 126403544 401436841 420826465 45046581 20249976 46978855 46397957 706610773 24701041 57954481 51603266 593109701 385569073 178982291 582152863 287317968 1474090 34825141 432421977 130257781 151516903 540852403 548392 117246529",
"output": "38"
},
{
"input": "19 3\n562569697 549131571 50676718 84501863 74567295 702372009 365895280 451459937 40378543 167666701 158635641 53639293 442332661 825055617 100109161 326616021 862332843 533271196 4791547",
"output": "18"
},
{
"input": "1 1\n44",
"output": "0"
},
{
"input": "1 1\n4",
"output": "1"
},
{
"input": "10 3\n444 447 774 777 7777 4447 4 7 7 4",
"output": "8"
}
] | 1,589,023,440 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 186 | 6,656,000 | [n, k] = [int(x) for x in input().split()]
L = [x for x in input().split()]
c = 0
for i in L:
if i.count('4') + i.count('7') <= k: c += 1
print(c)
| Title: Roma and Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem.
Input Specification:
The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces.
Output Specification:
In a single line print a single integer — the answer to the problem.
Demo Input:
['3 4\n1 2 4\n', '3 2\n447 44 77\n']
Demo Output:
['3\n', '2\n']
Note:
In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | ```python
[n, k] = [int(x) for x in input().split()]
L = [x for x in input().split()]
c = 0
for i in L:
if i.count('4') + i.count('7') <= k: c += 1
print(c)
``` | 3 |
|
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated. | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time. | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 -1 2 2 1 6 5 -1 5",
"output": "5"
},
{
"input": "98\n-1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -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": "3\n-1 5 4",
"output": "1"
},
{
"input": "146\n4 -1 -1 -1 -1 -1 -1 -1 -1 -1 4 -1 3 -1 3 -1 -1 1 4 -1 2 -1 -1 3 -1 -1 -1 4 1 -1 -1 -1 4 -1 -1 -1 -1 -1 -1 3 2 -1 3 2 4 5 2 4 1 5 -1 -1 2 -1 -1 1 -1 5 3 -1 1 2 2 3 5 3 -1 -1 3 -1 -1 3 5 5 -1 -1 5 -1 4 4 1 -1 -1 -1 2 1 -1 -1 -1 2 5 3 -1 -1 -1 3 -1 5 4 -1 1 -1 -1 3 -1 -1 3 1 1 2 -1 -1 -1 1 3 1 -1 2 -1 -1 5 5 -1 -1 3 4 5 1 -1 2 -1 -1 -1 3 -1 5 3 2 -1 2 -1 -1 5 -1 3 -1",
"output": "5"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n1 -1",
"output": "0"
},
{
"input": "2\n-1 1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n-1 -1",
"output": "2"
},
{
"input": "4\n10 -1 -1 -1",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "4\n-1 -1 1 1",
"output": "2"
}
] | 1,694,688,779 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 63 | 78 | 13,209,600 | n = int(input())
li = list(map(int, input().split()))
c = 0
k = 0
for i in range(n):
if li[i] == -1 and c < 1:
k += 1
else:
c += li[i]
print(k)
"""
4
abacaba
acaba
abacaba
acab
""" | Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
Input Specification:
The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
Output Specification:
Print a single integer, the number of crimes which will go untreated.
Demo Input:
['3\n-1 -1 1\n', '8\n1 -1 1 -1 -1 1 1 1\n', '11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n']
Demo Output:
['2\n', '1\n', '8\n']
Note:
Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this crime will go untreated. 1. One more person is hired. 1. One more person is hired. 1. One more person is hired.
The answer is one, as one crime (on step 5) will go untreated. | ```python
n = int(input())
li = list(map(int, input().split()))
c = 0
k = 0
for i in range(n):
if li[i] == -1 and c < 1:
k += 1
else:
c += li[i]
print(k)
"""
4
abacaba
acaba
abacaba
acab
"""
``` | 3 |
|
801 | A | Vicious Keyboard | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string. | The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. | Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. | [
"VK\n",
"VV\n",
"V\n",
"VKKKKKKKKKVVVVVVVVVK\n",
"KVKV\n"
] | [
"1\n",
"1\n",
"0\n",
"3\n",
"1\n"
] | For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences. | 500 | [
{
"input": "VK",
"output": "1"
},
{
"input": "VV",
"output": "1"
},
{
"input": "V",
"output": "0"
},
{
"input": "VKKKKKKKKKVVVVVVVVVK",
"output": "3"
},
{
"input": "KVKV",
"output": "1"
},
{
"input": "VKKVVVKVKVK",
"output": "5"
},
{
"input": "VKVVKVKVVKVKKKKVVVVVVVVKVKVVVVVVKKVKKVKVVKVKKVVVVKV",
"output": "14"
},
{
"input": "VVKKVKKVVKKVKKVKVVKKVKKVVKKVKVVKKVKKVKVVKKVVKKVKVVKKVKVVKKVVKVVKKVKKVKKVKKVKKVKVVKKVKKVKKVKKVKKVVKVK",
"output": "32"
},
{
"input": "KVVKKVKVKVKVKVKKVKVKVVKVKVVKVVKVKKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVVKVKVVKKVKVKK",
"output": "32"
},
{
"input": "KVVVVVKKVKVVKVVVKVVVKKKVKKKVVKVKKKVKKKKVKVVVVVKKKVVVVKKVVVVKKKVKVVVVVVVKKVKVKKKVVKVVVKVVKK",
"output": "21"
},
{
"input": "VVVVVKKVKVKVKVVKVVKKVVKVKKKKKKKVKKKVVVVVVKKVVVKVKVVKVKKVVKVVVKKKKKVVVVVKVVVVKVVVKKVKKVKKKVKKVKKVVKKV",
"output": "25"
},
{
"input": "KKVVKVVKVVKKVVKKVKVVKKV",
"output": "7"
},
{
"input": "KKVVKKVVVKKVKKVKKVVVKVVVKKVKKVVVKKVVVKVVVKVVVKKVVVKKVVVKVVVKKVVVKVVKKVVVKKVVVKKVVKVVVKKVVKKVKKVVVKKV",
"output": "24"
},
{
"input": "KVKVKVKVKVKVKVKVKVKVVKVKVKVKVKVKVKVVKVKVKKVKVKVKVKVVKVKVKVKVKVKVKVKVKKVKVKVV",
"output": "35"
},
{
"input": "VKVVVKKKVKVVKVKVKVKVKVV",
"output": "9"
},
{
"input": "KKKKVKKVKVKVKKKVVVVKK",
"output": "6"
},
{
"input": "KVKVKKVVVVVVKKKVKKKKVVVVKVKKVKVVK",
"output": "9"
},
{
"input": "KKVKKVKKKVKKKVKKKVKVVVKKVVVVKKKVKKVVKVKKVKVKVKVVVKKKVKKKKKVVKVVKVVVKKVVKVVKKKKKVK",
"output": "22"
},
{
"input": "VVVKVKVKVVVVVKVVVKKVVVKVVVVVKKVVKVVVKVVVKVKKKVVKVVVVVKVVVVKKVVKVKKVVKKKVKVVKVKKKKVVKVVVKKKVKVKKKKKK",
"output": "25"
},
{
"input": "VKVVKVVKKKVVKVKKKVVKKKVVKVVKVVKKVKKKVKVKKKVVKVKKKVVKVVKKKVVKKKVKKKVVKKVVKKKVKVKKKVKKKVKKKVKVKKKVVKVK",
"output": "29"
},
{
"input": "KKVKVVVKKVV",
"output": "3"
},
{
"input": "VKVKVKVKVKVKVKVKVKVKVVKVKVKVKVKVK",
"output": "16"
},
{
"input": "VVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVV",
"output": "13"
},
{
"input": "VVKKVKVKKKVVVKVVVKVKKVKKKVVVKVVKVKKVKKVKVKVVKKVVKKVKVVKKKVVKKVVVKVKVVVKVKVVKVKKVKKV",
"output": "26"
},
{
"input": "VVKVKKVVKKVVKKVVKKVVKKVKKVVKVKKVVKKVVKKVVKKVVKKVVKVVKKVVKVVKKVVKVVKKVVKKVKKVVKVVKKVVKVVKKVV",
"output": "26"
},
{
"input": "K",
"output": "0"
},
{
"input": "VKVK",
"output": "2"
},
{
"input": "VKVV",
"output": "2"
},
{
"input": "KV",
"output": "0"
},
{
"input": "KK",
"output": "1"
},
{
"input": "KKVK",
"output": "2"
},
{
"input": "KKKK",
"output": "1"
},
{
"input": "KKV",
"output": "1"
},
{
"input": "KKVKVK",
"output": "3"
},
{
"input": "VKKVK",
"output": "2"
},
{
"input": "VKKK",
"output": "2"
},
{
"input": "KKK",
"output": "1"
},
{
"input": "KVV",
"output": "1"
},
{
"input": "KKVKV",
"output": "2"
},
{
"input": "VVK",
"output": "1"
},
{
"input": "VVVKVKVKVKVKVKVK",
"output": "8"
},
{
"input": "KVVVK",
"output": "2"
},
{
"input": "VVVKK",
"output": "2"
},
{
"input": "KKVV",
"output": "1"
},
{
"input": "KKKKKKK",
"output": "1"
},
{
"input": "VKKKVK",
"output": "3"
},
{
"input": "KKVVV",
"output": "1"
},
{
"input": "VVVVVV",
"output": "1"
},
{
"input": "KKKV",
"output": "1"
},
{
"input": "VVKVV",
"output": "2"
},
{
"input": "VKVKKK",
"output": "3"
},
{
"input": "VKKV",
"output": "1"
},
{
"input": "VKKVV",
"output": "2"
},
{
"input": "VVKKVV",
"output": "2"
},
{
"input": "KKVVKKV",
"output": "2"
},
{
"input": "KKKKK",
"output": "1"
},
{
"input": "VKVVKKVKKVVKVKKVKKKVKKVKVKK",
"output": "10"
},
{
"input": "VKVKVV",
"output": "3"
},
{
"input": "VKVVKVV",
"output": "3"
},
{
"input": "VVV",
"output": "1"
},
{
"input": "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV",
"output": "1"
},
{
"input": "VVKKKKKKVKK",
"output": "3"
},
{
"input": "KVKVKVV",
"output": "3"
}
] | 1,492,357,420 | 520 | Python 3 | OK | TESTS | 63 | 77 | 5,529,600 | l=input()
s=[]
for i in l:
if(i=='V'):
s.append(1)
else:
s.append(0)
ls=len(s)
i=0
maxc = 0
c = 0
while i+1<ls:
if(s[i]==1 and s[i+1]==0):
c+=1
i+=1
maxc = max(maxc,c)
j=0
while j<ls:
if(s[j]==1):
s[j]=0
else:
s[j]=1
i=0
c=0
while i+1<ls:
if(s[i]==1 and s[i+1]==0):
c+=1
i+=1
maxc=max(c,maxc)
if(s[j]==1):
s[j]=0
else:
s[j]=1
j+=1
print(maxc) | Title: Vicious Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string.
Input Specification:
The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100.
Output Specification:
Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character.
Demo Input:
['VK\n', 'VV\n', 'V\n', 'VKKKKKKKKKVVVVVVVVVK\n', 'KVKV\n']
Demo Output:
['1\n', '1\n', '0\n', '3\n', '1\n']
Note:
For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences. | ```python
l=input()
s=[]
for i in l:
if(i=='V'):
s.append(1)
else:
s.append(0)
ls=len(s)
i=0
maxc = 0
c = 0
while i+1<ls:
if(s[i]==1 and s[i+1]==0):
c+=1
i+=1
maxc = max(maxc,c)
j=0
while j<ls:
if(s[j]==1):
s[j]=0
else:
s[j]=1
i=0
c=0
while i+1<ls:
if(s[i]==1 and s[i+1]==0):
c+=1
i+=1
maxc=max(c,maxc)
if(s[j]==1):
s[j]=0
else:
s[j]=1
j+=1
print(maxc)
``` | 3 |
|
2 | B | The least round way | PROGRAMMING | 2,000 | [
"dp",
"math"
] | B. The least round way | 2 | 64 | There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros. | The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | [
"3\n1 2 3\n4 5 6\n7 8 9\n"
] | [
"0\nDDRR\n"
] | none | 0 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "0\nDDRR"
},
{
"input": "2\n7 6\n3 8",
"output": "0\nDR"
},
{
"input": "3\n4 10 5\n10 9 4\n6 5 3",
"output": "1\nDRRD"
},
{
"input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5",
"output": "0\nDDDRRR"
},
{
"input": "5\n8 3 2 1 4\n3 7 2 4 8\n9 2 8 9 10\n2 3 6 10 1\n8 2 2 8 4",
"output": "0\nDDDDRRRR"
},
{
"input": "6\n5 5 4 10 5 5\n7 10 8 7 6 6\n7 1 7 9 7 8\n5 5 3 3 10 9\n5 8 10 6 3 8\n3 10 5 4 3 4",
"output": "1\nDDRRDRDDRR"
},
{
"input": "7\n2 9 8 2 7 4 8\n9 5 4 4 8 5 3\n5 7 2 10 8 1 8\n2 7 10 7 5 7 7\n9 2 7 6 4 8 4\n7 2 4 7 4 1 8\n9 5 3 10 1 6 2",
"output": "0\nRRDRRDRDDDDR"
},
{
"input": "8\n1 1 10 1 8 4 8 7\n9 3 3 2 2 6 2 4\n7 4 3 5 10 3 5 1\n8 4 4 10 4 5 9 4\n5 5 5 2 6 7 1 8\n4 10 1 3 2 4 8 3\n8 1 10 2 8 2 2 4\n2 10 6 8 10 2 8 4",
"output": "0\nDRRRRRRRDDDDDD"
},
{
"input": "9\n8 3 3 3 10 3 10 5 6\n2 1 6 1 8 1 9 1 6\n6 1 5 4 2 2 10 4 9\n1 9 1 3 10 6 10 5 5\n1 10 5 4 7 2 5 9 10\n6 6 1 3 1 9 4 9 9\n5 3 7 6 4 6 2 10 2\n9 3 3 10 5 6 7 6 4\n4 9 6 7 4 3 7 6 5",
"output": "1\nDDDDDRDDDRRRRRRR"
},
{
"input": "10\n10 8 6 5 9 8 2 5 3 2\n3 1 8 6 8 10 5 5 7 8\n5 9 7 7 4 9 7 2 5 2\n5 9 9 5 4 2 6 6 8 1\n10 6 9 9 10 5 6 3 5 9\n6 7 10 3 1 4 3 6 7 6\n10 10 4 7 4 4 8 6 7 4\n10 5 8 2 2 7 4 4 1 4\n8 4 6 10 10 6 1 3 3 1\n9 9 7 2 9 5 1 8 6 3",
"output": "1\nDRDDDRRDDDRRDRDRRR"
}
] | 1,621,926,779 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | ls=[]
n=int(input())
for _ in range(n):
a=input().split()
a=[int(x) for x in a]
ls.append(a)
dp=[[0 for x in range(n)] for y in range(n)]
way=[['' for x in range(n)] for y in range(n)]
dp[0][0]=1
for i in range(1,n):
dp[0][i]=dp[0][i-1]+ls[0][i]
way[0][i]=way[0][i-1]+'R'
for i in range(1,n):
dp[i][0]=dp[i-1][0]+ls[i][0]
way[i][0]=way[i-1][0]+'D'
for i in range(1,n):
for j in range(1,n):
if dp[i-1][j]<dp[i][j-1]:
dp[i][j]=dp[i-1][j]+ls[i][j]
way[i][j]=way[i-1][j]+'D'
else:
dp[i][j]=dp[i][j-1]+ls[i][j]
way[i][j]=way[i][j-1]+'R'
print(way[n-1][n-1])
| Title: The least round way
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros.
Input Specification:
The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109).
Output Specification:
In the first line print the least number of trailing zeros. In the second line print the correspondent way itself.
Demo Input:
['3\n1 2 3\n4 5 6\n7 8 9\n']
Demo Output:
['0\nDDRR\n']
Note:
none | ```python
ls=[]
n=int(input())
for _ in range(n):
a=input().split()
a=[int(x) for x in a]
ls.append(a)
dp=[[0 for x in range(n)] for y in range(n)]
way=[['' for x in range(n)] for y in range(n)]
dp[0][0]=1
for i in range(1,n):
dp[0][i]=dp[0][i-1]+ls[0][i]
way[0][i]=way[0][i-1]+'R'
for i in range(1,n):
dp[i][0]=dp[i-1][0]+ls[i][0]
way[i][0]=way[i-1][0]+'D'
for i in range(1,n):
for j in range(1,n):
if dp[i-1][j]<dp[i][j-1]:
dp[i][j]=dp[i-1][j]+ls[i][j]
way[i][j]=way[i-1][j]+'D'
else:
dp[i][j]=dp[i][j-1]+ls[i][j]
way[i][j]=way[i][j-1]+'R'
print(way[n-1][n-1])
``` | 0 |
384 | A | Coder | PROGRAMMING | 800 | [
"implementation"
] | null | null | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1).
Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard.
On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'.
If there are multiple correct answers, you can print any. | [
"2\n"
] | [
"2\nC.\n.C\n"
] | none | 500 | [
{
"input": "2",
"output": "2\nC.\n.C"
},
{
"input": "3",
"output": "5\nC.C\n.C.\nC.C"
},
{
"input": "4",
"output": "8\nC.C.\n.C.C\nC.C.\n.C.C"
},
{
"input": "10",
"output": "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C"
},
{
"input": "15",
"output": "113\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C"
},
{
"input": "100",
"output": "5000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "101",
"output": "5101\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "500",
"output": "125000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.\n...."
},
{
"input": "501",
"output": "125501\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C\n..."
},
{
"input": "755",
"output": "285013\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "888",
"output": "394272\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "998",
"output": "498002\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "999",
"output": "499001\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "1000",
"output": "500000\nC.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C.C..."
},
{
"input": "1",
"output": "1\nC"
}
] | 1,541,642,164 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 109 | 0 | n = int(input())
field = [list("." * n) for i in range(n)]
for i in range(0,n,2):
for j in range(0,n,2):
field[i][j] = "C"
for i in range(1,n,2):
for j in range(1,n,2):
field[i][j] = "C"
for i in range(n):
print("".join(field[i]))
| Title: Coder
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1).
Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Output Specification:
On the first line print an integer, the maximum number of Coders that can be placed on the chessboard.
On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'.
If there are multiple correct answers, you can print any.
Demo Input:
['2\n']
Demo Output:
['2\nC.\n.C\n']
Note:
none | ```python
n = int(input())
field = [list("." * n) for i in range(n)]
for i in range(0,n,2):
for j in range(0,n,2):
field[i][j] = "C"
for i in range(1,n,2):
for j in range(1,n,2):
field[i][j] = "C"
for i in range(n):
print("".join(field[i]))
``` | 0 |
|
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus. | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1. ivan 1. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan 1. roman 1. alex | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"output": "ypg"
},
{
"input": "3\nexhll\nexhll\narruapexj",
"output": "arruapexj\nexhll"
},
{
"input": "3\nfv\nle\nle",
"output": "le\nfv"
},
{
"input": "8\nm\nm\nm\nm\nm\nm\nm\nm",
"output": "m"
},
{
"input": "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr",
"output": "r\nu\nb\nk\nw\ni"
},
{
"input": "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok",
"output": "tjmok\nwx\nby\nnzs\ncmk\nfau\ne"
},
{
"input": "6\nklrj\nwe\nklrj\nwe\nwe\nwe",
"output": "we\nklrj"
},
{
"input": "8\nzncybqmh\naeebef\nzncybqmh\nn\naeebef\nzncybqmh\nzncybqmh\nzncybqmh",
"output": "zncybqmh\naeebef\nn"
},
{
"input": "30\nkqqcbs\nvap\nkymomn\nj\nkqqcbs\nfuzlzoum\nkymomn\ndbh\nfuzlzoum\nkymomn\nvap\nvlgzs\ndbh\nvlgzs\nbvy\ndbh\nkymomn\nkymomn\neoqql\nkymomn\nkymomn\nkqqcbs\nvlgzs\nkqqcbs\nkqqcbs\nfuzlzoum\nvlgzs\nrylgdoo\nvlgzs\nrylgdoo",
"output": "rylgdoo\nvlgzs\nfuzlzoum\nkqqcbs\nkymomn\neoqql\ndbh\nbvy\nvap\nj"
},
{
"input": "40\nji\nv\nv\nns\nji\nn\nji\nv\nfvy\nvje\nns\nvje\nv\nhas\nv\nusm\nhas\nfvy\nvje\nkdb\nn\nv\nji\nji\nn\nhas\nv\nji\nkdb\nr\nvje\nns\nv\nusm\nn\nvje\nhas\nns\nhas\nn",
"output": "n\nhas\nns\nvje\nusm\nv\nr\nkdb\nji\nfvy"
},
{
"input": "50\njcg\nvle\njopb\nepdb\nnkef\nfv\nxj\nufe\nfuy\noqta\ngbc\nyuz\nec\nyji\nkuux\ncwm\ntq\nnno\nhp\nzry\nxxpp\ntjvo\ngyz\nkwo\nvwqz\nyaqc\njnj\nwoav\nqcv\ndcu\ngc\nhovn\nop\nevy\ndc\ntrpu\nyb\nuzfa\npca\noq\nnhxy\nsiqu\nde\nhphy\nc\nwovu\nf\nbvv\ndsik\nlwyg",
"output": "lwyg\ndsik\nbvv\nf\nwovu\nc\nhphy\nde\nsiqu\nnhxy\noq\npca\nuzfa\nyb\ntrpu\ndc\nevy\nop\nhovn\ngc\ndcu\nqcv\nwoav\njnj\nyaqc\nvwqz\nkwo\ngyz\ntjvo\nxxpp\nzry\nhp\nnno\ntq\ncwm\nkuux\nyji\nec\nyuz\ngbc\noqta\nfuy\nufe\nxj\nfv\nnkef\nepdb\njopb\nvle\njcg"
},
{
"input": "100\nvhh\nvhh\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh",
"output": "vhh\nfa"
},
{
"input": "2\naa\nbb",
"output": "bb\naa"
},
{
"input": "2\naa\na",
"output": "a\naa"
},
{
"input": "3\naa\naa\naa",
"output": "aa"
},
{
"input": "5\naa\na\naa\na\naa",
"output": "aa\na"
},
{
"input": "7\naaaa\naaaa\naaa\na\naa\naaaaaaa\naaa",
"output": "aaa\naaaaaaa\naa\na\naaaa"
},
{
"input": "5\na\naa\naaa\naaaa\na",
"output": "a\naaaa\naaa\naa"
},
{
"input": "12\naaaaa\naaaaaa\naaaa\naaaaaa\naa\naaaa\naaaa\naaaaaa\na\naaa\naaaaaaaa\naa",
"output": "aa\naaaaaaaa\naaa\na\naaaaaa\naaaa\naaaaa"
},
{
"input": "3\na\naa\naaa",
"output": "aaa\naa\na"
},
{
"input": "9\nzzz\nzzzzz\nzzz\nzzzz\nzz\nzzzz\nzzzzz\nzzzz\nzzzzzzz",
"output": "zzzzzzz\nzzzz\nzzzzz\nzz\nzzz"
}
] | 1,690,058,110 | 2,147,483,647 | Python 3 | OK | TESTS | 95 | 514 | 28,569,600 | n = int(input())
v = []
for i in range(n):
name = input()
v.append(name)
# v contains all names in the initial order
# now we have to process the list in reverse order
s = set() # should use set() for set
for i in range(n-1, -1, -1): # start from the last index, dec by 1, stop at -1
name = v[i]
if name not in s:
print(name)
s.add(name)
| Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output Specification:
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Demo Input:
['4\nalex\nivan\nroman\nivan\n', '8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n']
Demo Output:
['ivan\nroman\nalex\n', 'alina\nmaria\nekaterina\ndarya\n']
Note:
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1. ivan 1. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan 1. roman 1. alex | ```python
n = int(input())
v = []
for i in range(n):
name = input()
v.append(name)
# v contains all names in the initial order
# now we have to process the list in reverse order
s = set() # should use set() for set
for i in range(n-1, -1, -1): # start from the last index, dec by 1, stop at -1
name = v[i]
if name not in s:
print(name)
s.add(name)
``` | 3 |
|
104 | A | Blackjack | PROGRAMMING | 800 | [
"implementation"
] | A. Blackjack | 2 | 256 | One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.
In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses.
The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*. | The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points. | Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. | [
"12\n",
"20\n",
"10\n"
] | [
"4",
"15",
"0"
] | In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there is no card, that would add a zero to the current ten points. | 500 | [
{
"input": "12",
"output": "4"
},
{
"input": "20",
"output": "15"
},
{
"input": "10",
"output": "0"
},
{
"input": "11",
"output": "4"
},
{
"input": "15",
"output": "4"
},
{
"input": "18",
"output": "4"
},
{
"input": "25",
"output": "0"
},
{
"input": "22",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "6",
"output": "0"
},
{
"input": "7",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "9",
"output": "0"
},
{
"input": "13",
"output": "4"
},
{
"input": "14",
"output": "4"
},
{
"input": "16",
"output": "4"
},
{
"input": "17",
"output": "4"
},
{
"input": "19",
"output": "4"
},
{
"input": "21",
"output": "4"
},
{
"input": "23",
"output": "0"
},
{
"input": "24",
"output": "0"
}
] | 1,645,416,180 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 122 | 4,710,400 | from collections import defaultdict as dd
hp = dd(lambda:4)
hp[0] = 4
hp[10] = 15
hp[11] = 8
n = int(input())
x = n - 10
if x > 11:
print(0)
else:
print(hp[x]) | Title: Blackjack
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.
In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses.
The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*.
Input Specification:
The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points.
Output Specification:
Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.
Demo Input:
['12\n', '20\n', '10\n']
Demo Output:
['4', '15', '0']
Note:
In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there is no card, that would add a zero to the current ten points. | ```python
from collections import defaultdict as dd
hp = dd(lambda:4)
hp[0] = 4
hp[10] = 15
hp[11] = 8
n = int(input())
x = n - 10
if x > 11:
print(0)
else:
print(hp[x])
``` | 0 |
914 | F | Substrings in a String | PROGRAMMING | 3,000 | [
"bitmasks",
"brute force",
"data structures",
"string suffix structures",
"strings"
] | null | null | Given a string *s*, process *q* queries, each having one of the following forms:
- 1<=*i*<=*c* — Change the *i*-th character in the string to *c*. - 2<=*l*<=*r*<=*y* — Consider the substring of *s* starting at position *l* and ending at position *r*. Output the number of times *y* occurs as a substring in it. | The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=105) of lowercase English letters.
The second line contains an integer *q* (1<=≤<=*q*<=≤<=105) — the number of queries to process.
The next *q* lines describe the queries and may have one of the following forms:
- 1<=*i*<=*c* (1<=≤<=*i*<=≤<=|*s*|) - 2<=*l*<=*r*<=*y* (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|)
*c* is a lowercase English letter and *y* is a non-empty string consisting of only lowercase English letters.
The sum of |*y*| over all queries of second type is at most 105.
It is guaranteed that there is at least one query of second type.
All strings are 1-indexed.
|*s*| is the length of the string *s*. | For each query of type 2, output the required answer in a separate line. | [
"ababababa\n3\n2 1 7 aba\n1 5 c\n2 1 7 aba\n",
"abcdcbc\n5\n2 1 7 bc\n1 4 b\n2 4 7 bc\n1 2 a\n2 1 4 aa\n"
] | [
"3\n1\n",
"2\n2\n1\n"
] | Consider the first sample case. Initially, the string aba occurs 3 times in the range [1, 7]. Note that two occurrences may overlap.
After the update, the string becomes ababcbaba and now aba occurs only once in the range [1, 7]. | 3,000 | [] | 1,649,838,288 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | # -*- coding: utf-8 -*-
#I at first check what type of query is given. after that replace method is to replace the character at given index.
# on the otherhand, to findout the number of substring in the range, i wrote the substring method
#the return value of substring method was saved into a list and later printed.
#Time complexity = O(n^4) . reason : the substring method has a time complexity of O(n^3). It is inside of a loop (input loop) of O(n). Thus O(N^4)
def replace(x,a,p):
x[a-1]=p
return x
def substring(x,m,n,k):
count=0
i=m-1
k=list(k)
while (i+len(k)-1<n):
while((x[i]!=k[0]) and (i+len(k)-1<n) ):
i=i+1
if((x[i]==k[0]) and (i+len(k)-1<n)):
flag=True
for m in range(len(k)):
if x[i]==k[m]:
i+=1
else:
flag=False
i+=1
break
if flag is True:
count+=1
while n>m:
if(x[n-1] != k[len(k)-1]):
n-=1
else:
break
return count
str=input()
numberOfQuery=int(input())
str=list(str)
for i in range(numberOfQuery):
query=input()
query=query.split(" ")
if(len(query) == 3):
str=replace(str,int(query[1]),query[2])
elif(len(query) == 4):
print(substring(str,int(query[1]),int(query[2]),query[3]))
| Title: Substrings in a String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given a string *s*, process *q* queries, each having one of the following forms:
- 1<=*i*<=*c* — Change the *i*-th character in the string to *c*. - 2<=*l*<=*r*<=*y* — Consider the substring of *s* starting at position *l* and ending at position *r*. Output the number of times *y* occurs as a substring in it.
Input Specification:
The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=105) of lowercase English letters.
The second line contains an integer *q* (1<=≤<=*q*<=≤<=105) — the number of queries to process.
The next *q* lines describe the queries and may have one of the following forms:
- 1<=*i*<=*c* (1<=≤<=*i*<=≤<=|*s*|) - 2<=*l*<=*r*<=*y* (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|)
*c* is a lowercase English letter and *y* is a non-empty string consisting of only lowercase English letters.
The sum of |*y*| over all queries of second type is at most 105.
It is guaranteed that there is at least one query of second type.
All strings are 1-indexed.
|*s*| is the length of the string *s*.
Output Specification:
For each query of type 2, output the required answer in a separate line.
Demo Input:
['ababababa\n3\n2 1 7 aba\n1 5 c\n2 1 7 aba\n', 'abcdcbc\n5\n2 1 7 bc\n1 4 b\n2 4 7 bc\n1 2 a\n2 1 4 aa\n']
Demo Output:
['3\n1\n', '2\n2\n1\n']
Note:
Consider the first sample case. Initially, the string aba occurs 3 times in the range [1, 7]. Note that two occurrences may overlap.
After the update, the string becomes ababcbaba and now aba occurs only once in the range [1, 7]. | ```python
# -*- coding: utf-8 -*-
#I at first check what type of query is given. after that replace method is to replace the character at given index.
# on the otherhand, to findout the number of substring in the range, i wrote the substring method
#the return value of substring method was saved into a list and later printed.
#Time complexity = O(n^4) . reason : the substring method has a time complexity of O(n^3). It is inside of a loop (input loop) of O(n). Thus O(N^4)
def replace(x,a,p):
x[a-1]=p
return x
def substring(x,m,n,k):
count=0
i=m-1
k=list(k)
while (i+len(k)-1<n):
while((x[i]!=k[0]) and (i+len(k)-1<n) ):
i=i+1
if((x[i]==k[0]) and (i+len(k)-1<n)):
flag=True
for m in range(len(k)):
if x[i]==k[m]:
i+=1
else:
flag=False
i+=1
break
if flag is True:
count+=1
while n>m:
if(x[n-1] != k[len(k)-1]):
n-=1
else:
break
return count
str=input()
numberOfQuery=int(input())
str=list(str)
for i in range(numberOfQuery):
query=input()
query=query.split(" ")
if(len(query) == 3):
str=replace(str,int(query[1]),query[2])
elif(len(query) == 4):
print(substring(str,int(query[1]),int(query[2]),query[3]))
``` | 0 |
|
912 | B | New Year's Eve | PROGRAMMING | 1,300 | [
"bitmasks",
"constructive algorithms",
"number theory"
] | null | null | Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness.
The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones — but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum!
A xor-sum of a sequence of integers *a*1,<=*a*2,<=...,<=*a**m* is defined as the bitwise XOR of all its elements: , here denotes the bitwise XOR operation; more about bitwise XOR can be found [here.](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)
Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than *k* candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain. | The sole string contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018). | Output one number — the largest possible xor-sum. | [
"4 3\n",
"6 6\n"
] | [
"7\n",
"7\n"
] | In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.
In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7. | 1,000 | [
{
"input": "4 3",
"output": "7"
},
{
"input": "6 6",
"output": "7"
},
{
"input": "2 2",
"output": "3"
},
{
"input": "1022 10",
"output": "1023"
},
{
"input": "415853337373441 52",
"output": "562949953421311"
},
{
"input": "75 12",
"output": "127"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1152921504606846975"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000000000000 2",
"output": "1152921504606846975"
},
{
"input": "49194939 22",
"output": "67108863"
},
{
"input": "228104606 17",
"output": "268435455"
},
{
"input": "817034381 7",
"output": "1073741823"
},
{
"input": "700976748 4",
"output": "1073741823"
},
{
"input": "879886415 9",
"output": "1073741823"
},
{
"input": "18007336 10353515",
"output": "33554431"
},
{
"input": "196917003 154783328",
"output": "268435455"
},
{
"input": "785846777 496205300",
"output": "1073741823"
},
{
"input": "964756444 503568330",
"output": "1073741823"
},
{
"input": "848698811 317703059",
"output": "1073741823"
},
{
"input": "676400020444788 1",
"output": "676400020444788"
},
{
"input": "502643198528213 1",
"output": "502643198528213"
},
{
"input": "815936580997298686 684083143940282566",
"output": "1152921504606846975"
},
{
"input": "816762824175382110 752185261508428780",
"output": "1152921504606846975"
},
{
"input": "327942415253132295 222598158321260499",
"output": "576460752303423487"
},
{
"input": "328768654136248423 284493129147496637",
"output": "576460752303423487"
},
{
"input": "329594893019364551 25055600080496801",
"output": "576460752303423487"
},
{
"input": "921874985256864012 297786684518764536",
"output": "1152921504606846975"
},
{
"input": "922701224139980141 573634416190460758",
"output": "1152921504606846975"
},
{
"input": "433880815217730325 45629641110945892",
"output": "576460752303423487"
},
{
"input": "434707058395813749 215729375494216481",
"output": "576460752303423487"
},
{
"input": "435533301573897173 34078453236225189",
"output": "576460752303423487"
},
{
"input": "436359544751980597 199220719961060641",
"output": "576460752303423487"
},
{
"input": "437185783635096725 370972992240105630",
"output": "576460752303423487"
},
{
"input": "438012026813180149 111323110116193830",
"output": "576460752303423487"
},
{
"input": "438838269991263573 295468957052046146",
"output": "576460752303423487"
},
{
"input": "439664513169346997 46560240538186155",
"output": "576460752303423487"
},
{
"input": "440490752052463125 216165966013438147",
"output": "576460752303423487"
},
{
"input": "441316995230546549 401964286420555423",
"output": "576460752303423487"
},
{
"input": "952496582013329437 673506882352402278",
"output": "1152921504606846975"
},
{
"input": "1000000000000000000 1",
"output": "1000000000000000000"
},
{
"input": "2147483647 1",
"output": "2147483647"
},
{
"input": "2147483647 2",
"output": "2147483647"
},
{
"input": "2147483647 31",
"output": "2147483647"
},
{
"input": "8 2",
"output": "15"
},
{
"input": "3 3",
"output": "3"
},
{
"input": "4 1",
"output": "4"
},
{
"input": "10 2",
"output": "15"
},
{
"input": "288230376151711743 2",
"output": "288230376151711743"
},
{
"input": "5 2",
"output": "7"
},
{
"input": "576460752303423487 2",
"output": "576460752303423487"
},
{
"input": "36028797018963967 123",
"output": "36028797018963967"
},
{
"input": "1125899906842623 2",
"output": "1125899906842623"
},
{
"input": "576460752303423489 5",
"output": "1152921504606846975"
},
{
"input": "288230376151711743 3",
"output": "288230376151711743"
},
{
"input": "36028797018963967 345",
"output": "36028797018963967"
},
{
"input": "18014398509481984 30",
"output": "36028797018963967"
},
{
"input": "8 8",
"output": "15"
},
{
"input": "8 1",
"output": "8"
}
] | 1,541,702,844 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 109 | 0 | [n, k] = [int(i) for i in input().split()]
remaining = k
number = 2**65
res = 0
while remaining > 0 and number > 0:
if number <= n:
res += number
remaining -= 1
number = number // 2
print(res)
| Title: New Year's Eve
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness.
The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones — but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum!
A xor-sum of a sequence of integers *a*1,<=*a*2,<=...,<=*a**m* is defined as the bitwise XOR of all its elements: , here denotes the bitwise XOR operation; more about bitwise XOR can be found [here.](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)
Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than *k* candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain.
Input Specification:
The sole string contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018).
Output Specification:
Output one number — the largest possible xor-sum.
Demo Input:
['4 3\n', '6 6\n']
Demo Output:
['7\n', '7\n']
Note:
In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.
In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7. | ```python
[n, k] = [int(i) for i in input().split()]
remaining = k
number = 2**65
res = 0
while remaining > 0 and number > 0:
if number <= n:
res += number
remaining -= 1
number = number // 2
print(res)
``` | 0 |
|
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
- 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9
Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given *a*, *b* and *c* print the maximum value that you can get. | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{
"input": "3\n1\n5",
"output": "20"
},
{
"input": "6\n7\n1",
"output": "48"
},
{
"input": "1\n8\n3",
"output": "27"
},
{
"input": "9\n7\n2",
"output": "126"
},
{
"input": "1\n1\n10",
"output": "20"
},
{
"input": "9\n1\n1",
"output": "18"
},
{
"input": "10\n5\n6",
"output": "300"
},
{
"input": "8\n9\n7",
"output": "504"
},
{
"input": "4\n2\n10",
"output": "80"
},
{
"input": "2\n8\n3",
"output": "48"
},
{
"input": "3\n5\n7",
"output": "105"
},
{
"input": "1\n10\n1",
"output": "12"
},
{
"input": "2\n2\n2",
"output": "8"
},
{
"input": "5\n6\n1",
"output": "35"
},
{
"input": "10\n1\n1",
"output": "20"
},
{
"input": "1\n6\n1",
"output": "8"
},
{
"input": "1\n9\n1",
"output": "11"
},
{
"input": "2\n1\n2",
"output": "6"
},
{
"input": "2\n6\n1",
"output": "14"
},
{
"input": "9\n2\n1",
"output": "27"
},
{
"input": "1\n9\n2",
"output": "20"
},
{
"input": "1\n3\n1",
"output": "5"
},
{
"input": "2\n1\n1",
"output": "4"
}
] | 1,696,848,808 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | a,b,c=map(int,input().split())
if a==1 or b==1 or c==1:
if a>=b and a>=c:
print((b+c)*a)
if b>a and b>c:
print((a+c)*b)
if c>a and c>b:
print((a+b)*c)
else:
print(a*b*c) | Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
- 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9
Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given *a*, *b* and *c* print the maximum value that you can get.
Input Specification:
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Output Specification:
Print the maximum value of the expression that you can obtain.
Demo Input:
['1\n2\n3\n', '2\n10\n3\n']
Demo Output:
['9\n', '60\n']
Note:
none | ```python
a,b,c=map(int,input().split())
if a==1 or b==1 or c==1:
if a>=b and a>=c:
print((b+c)*a)
if b>a and b>c:
print((a+c)*b)
if c>a and c>b:
print((a+b)*c)
else:
print(a*b*c)
``` | -1 |
|
14 | B | Young Photographer | PROGRAMMING | 1,000 | [
"implementation"
] | B. Young Photographer | 2 | 64 | Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals *n*. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position *a*1 to position *b*1, the second — from *a*2 to *b*2
What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack. | The first line of the input file contains integers *n* and *x*0 (1<=≤<=*n*<=≤<=100; 0<=≤<=*x*0<=≤<=1000). The following *n* lines contain pairs of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000; *a**i*<=≠<=*b**i*). | Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. | [
"3 3\n0 7\n14 2\n4 6\n"
] | [
"1\n"
] | none | 0 | [
{
"input": "3 3\n0 7\n14 2\n4 6",
"output": "1"
},
{
"input": "1 1\n0 10",
"output": "0"
},
{
"input": "2 2\n1 2\n3 2",
"output": "0"
},
{
"input": "3 2\n1 2\n2 3\n3 4",
"output": "-1"
},
{
"input": "2 4\n10 4\n1 5",
"output": "0"
},
{
"input": "1 10\n1 9",
"output": "1"
},
{
"input": "1 10\n123 12",
"output": "2"
},
{
"input": "1 17\n10 17",
"output": "0"
},
{
"input": "1 22\n22 33",
"output": "0"
},
{
"input": "1 3\n1 2",
"output": "1"
},
{
"input": "2 5\n0 3\n2 1",
"output": "3"
},
{
"input": "3 3\n7 3\n6 4\n3 7",
"output": "1"
},
{
"input": "4 9\n8 6\n11 5\n5 11\n8 3",
"output": "1"
},
{
"input": "2 4\n1 4\n4 0",
"output": "0"
},
{
"input": "3 7\n5 8\n7 5\n4 7",
"output": "0"
},
{
"input": "4 7\n8 2\n5 7\n8 2\n5 8",
"output": "0"
},
{
"input": "2 3\n4 1\n4 1",
"output": "0"
},
{
"input": "3 8\n7 2\n3 7\n5 2",
"output": "3"
},
{
"input": "4 0\n9 1\n8 1\n8 4\n4 5",
"output": "4"
},
{
"input": "4 7\n2 5\n3 6\n3 5\n7 4",
"output": "2"
},
{
"input": "10 16\n4 18\n6 19\n22 1\n23 0\n1 22\n9 22\n4 19\n0 14\n6 14\n0 16",
"output": "2"
},
{
"input": "20 1\n35 8\n40 6\n49 5\n48 18\n46 16\n45 16\n44 10\n16 44\n8 46\n2 45\n38 3\n42 1\n13 35\n35 18\n12 33\n32 11\n31 3\n50 20\n47 6\n38 2",
"output": "19"
},
{
"input": "30 43\n17 72\n75 26\n23 69\n83 30\n15 82\n4 67\n83 27\n33 62\n26 83\n70 26\n69 25\n16 67\n77 26\n66 33\n7 88\n70 9\n10 79\n76 9\n30 77\n77 28\n21 68\n81 14\n13 72\n88 15\n60 29\n87 28\n16 58\n6 58\n71 9\n83 18",
"output": "0"
},
{
"input": "40 69\n29 109\n28 87\n52 106\n101 34\n32 92\n91 60\n90 47\n62 102\n33 72\n27 87\n45 78\n103 37\n94 33\n56 98\n38 79\n31 83\n105 53\n47 89\n50 83\n93 62\n96 49\n47 75\n89 47\n89 61\n93 54\n46 100\n110 41\n103 28\n101 57\n100 62\n71 37\n65 80\n86 28\n73 42\n96 44\n33 111\n98 39\n87 55\n108 65\n31 101",
"output": "0"
},
{
"input": "50 77\n95 55\n113 33\n101 17\n109 56\n117 7\n77 12\n14 84\n57 101\n96 28\n108 22\n105 12\n17 114\n51 115\n18 112\n104 25\n50 115\n14 111\n55 113\n124 20\n101 37\n18 121\n41 90\n77 41\n117 16\n8 83\n92 45\n48 86\n16 84\n13 98\n40 107\n14 94\n23 111\n36 121\n50 100\n35 90\n103 37\n96 51\n109 15\n13 117\n117 42\n112 45\n88 36\n51 121\n127 49\n112 15\n9 95\n122 46\n126 40\n57 93\n56 88",
"output": "0"
},
{
"input": "5 12\n2 7\n7 5\n3 10\n11 3\n2 11",
"output": "5"
},
{
"input": "15 15\n12 37\n40 4\n38 8\n5 36\n11 31\n21 33\n9 37\n4 38\n8 33\n5 39\n7 39\n38 16\n16 41\n38 9\n5 32",
"output": "6"
},
{
"input": "25 40\n66 26\n56 19\n64 38\n64 23\n25 49\n51 26\n67 20\n65 35\n33 66\n28 63\n27 57\n40 56\n59 26\n35 56\n39 67\n30 63\n69 22\n21 63\n67 22\n20 66\n26 65\n64 26\n44 57\n57 41\n35 50",
"output": "4"
},
{
"input": "50 77\n24 119\n43 119\n102 22\n117 30\n127 54\n93 19\n120 9\n118 27\n98 16\n17 105\n22 127\n109 52\n115 40\n11 121\n12 120\n113 30\n13 108\n33 124\n31 116\n112 39\n37 108\n127 28\n127 39\n120 29\n19 114\n103 18\n106 16\n24 121\n93 10\n36 112\n104 40\n39 100\n36 97\n83 9\n14 114\n126 12\n85 47\n25 84\n105 29\n35 113\n102 19\n8 110\n111 28\n94 12\n11 115\n40 124\n39 85\n47 93\n94 31\n17 121",
"output": "0"
},
{
"input": "1 21\n973 373",
"output": "352"
},
{
"input": "2 212\n831 551\n810 753",
"output": "541"
},
{
"input": "3 404\n690 728\n820 260\n186 402",
"output": "-1"
},
{
"input": "4 906\n548 906\n830 457\n228 638\n464 167",
"output": "-1"
},
{
"input": "5 97\n97 393\n840 965\n269 183\n596 49\n975 62",
"output": "-1"
},
{
"input": "3 183\n416 335\n773 648\n434 198",
"output": "-1"
},
{
"input": "3 868\n251 927\n862 464\n157 756",
"output": "112"
},
{
"input": "3 242\n397 208\n951 279\n570 622",
"output": "-1"
},
{
"input": "3 618\n543 800\n38 94\n293 179",
"output": "-1"
},
{
"input": "3 993\n378 81\n127 911\n16 737",
"output": "615"
},
{
"input": "5 12\n11 1\n9 6\n1 11\n3 8\n874 842",
"output": "-1"
},
{
"input": "15 16\n11 40\n5 32\n5 31\n36 10\n34 9\n43 6\n28 6\n34 8\n43 15\n9 28\n14 34\n34 6\n7 31\n31 14\n68 478",
"output": "-1"
},
{
"input": "25 57\n47 31\n64 21\n43 56\n47 19\n70 27\n28 61\n41 61\n39 45\n46 21\n55 35\n70 22\n22 69\n30 67\n55 42\n37 58\n50 28\n57 42\n35 48\n68 40\n38 50\n62 20\n31 52\n38 70\n64 35\n666 393",
"output": "-1"
},
{
"input": "50 118\n83 55\n101 33\n89 17\n97 56\n105 7\n65 12\n14 72\n57 89\n84 28\n96 22\n93 12\n17 102\n51 103\n18 100\n92 25\n50 103\n14 99\n55 101\n112 20\n89 37\n18 109\n41 78\n65 41\n105 16\n8 71\n80 45\n48 74\n16 72\n13 86\n40 95\n14 82\n23 99\n36 109\n50 88\n35 78\n91 37\n84 51\n97 15\n13 105\n105 42\n100 45\n76 36\n51 109\n115 49\n100 15\n9 83\n110 46\n114 40\n57 81\n528 348",
"output": "-1"
},
{
"input": "1 21\n0 1000",
"output": "0"
}
] | 1,683,039,409 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 310 | 3,584,000 | import sys
from fractions import Fraction
input = sys.stdin.readline
n, x = map(int, input().split())
p = 0
for _ in range(n):
a, b = sorted(map(int, input().split()))
k = range(a, b+1)
if x not in k:
p += abs(x-a)
print(p) | Title: Young Photographer
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals *n*. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position *a*1 to position *b*1, the second — from *a*2 to *b*2
What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.
Input Specification:
The first line of the input file contains integers *n* and *x*0 (1<=≤<=*n*<=≤<=100; 0<=≤<=*x*0<=≤<=1000). The following *n* lines contain pairs of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000; *a**i*<=≠<=*b**i*).
Output Specification:
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
Demo Input:
['3 3\n0 7\n14 2\n4 6\n']
Demo Output:
['1\n']
Note:
none | ```python
import sys
from fractions import Fraction
input = sys.stdin.readline
n, x = map(int, input().split())
p = 0
for _ in range(n):
a, b = sorted(map(int, input().split()))
k = range(a, b+1)
if x not in k:
p += abs(x-a)
print(p)
``` | 0 |
385 | A | Bear and Raspberry | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for *c* kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day *d* (1<=≤<=*d*<=<<=*n*), lent a barrel of honey and immediately (on day *d*) sell it according to a daily exchange rate. The next day (*d*<=+<=1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day *d*<=+<=1) give his friend the borrowed barrel of honey as well as *c* kilograms of raspberry for renting the barrel.
The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan. | The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100), the price of a honey barrel on day *i*. | Print a single integer — the answer to the problem. | [
"5 1\n5 10 7 3 20\n",
"6 2\n100 1 10 40 10 40\n",
"3 0\n1 2 3\n"
] | [
"3\n",
"97\n",
"0\n"
] | In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97. | 500 | [
{
"input": "5 1\n5 10 7 3 20",
"output": "3"
},
{
"input": "6 2\n100 1 10 40 10 40",
"output": "97"
},
{
"input": "3 0\n1 2 3",
"output": "0"
},
{
"input": "2 0\n2 1",
"output": "1"
},
{
"input": "10 5\n10 1 11 2 12 3 13 4 14 5",
"output": "4"
},
{
"input": "100 4\n2 57 70 8 44 10 88 67 50 44 93 79 72 50 69 19 21 9 71 47 95 13 46 10 68 72 54 40 15 83 57 92 58 25 4 22 84 9 8 55 87 0 16 46 86 58 5 21 32 28 10 46 11 29 13 33 37 34 78 33 33 21 46 70 77 51 45 97 6 21 68 61 87 54 8 91 37 12 76 61 57 9 100 45 44 88 5 71 98 98 26 45 37 87 34 50 33 60 64 77",
"output": "87"
},
{
"input": "100 5\n15 91 86 53 18 52 26 89 8 4 5 100 11 64 88 91 35 57 67 72 71 71 69 73 97 23 11 1 59 86 37 82 6 67 71 11 7 31 11 68 21 43 89 54 27 10 3 33 8 57 79 26 90 81 6 28 24 7 33 50 24 13 27 85 4 93 14 62 37 67 33 40 7 48 41 4 14 9 95 10 64 62 7 93 23 6 28 27 97 64 26 83 70 0 97 74 11 82 70 93",
"output": "84"
},
{
"input": "6 100\n10 9 8 7 6 5",
"output": "0"
},
{
"input": "100 9\n66 71 37 41 23 38 77 11 74 13 51 26 93 56 81 17 12 70 85 37 54 100 14 99 12 83 44 16 99 65 13 48 92 32 69 33 100 57 58 88 25 45 44 85 5 41 82 15 37 18 21 45 3 68 33 9 52 64 8 73 32 41 87 99 26 26 47 24 79 93 9 44 11 34 85 26 14 61 49 38 25 65 49 81 29 82 28 23 2 64 38 13 77 68 67 23 58 57 83 46",
"output": "78"
},
{
"input": "100 100\n9 72 46 37 26 94 80 1 43 85 26 53 58 18 24 19 67 2 100 52 61 81 48 15 73 41 97 93 45 1 73 54 75 51 28 79 0 14 41 42 24 50 70 18 96 100 67 1 68 48 44 39 63 77 78 18 10 51 32 53 26 60 1 13 66 39 55 27 23 71 75 0 27 88 73 31 16 95 87 84 86 71 37 40 66 70 65 83 19 4 81 99 26 51 67 63 80 54 23 44",
"output": "0"
},
{
"input": "43 65\n32 58 59 75 85 18 57 100 69 0 36 38 79 95 82 47 7 55 28 88 27 88 63 71 80 86 67 53 69 37 99 54 81 19 55 12 2 17 84 77 25 26 62",
"output": "4"
},
{
"input": "12 64\n14 87 40 24 32 36 4 41 38 77 68 71",
"output": "0"
},
{
"input": "75 94\n80 92 25 48 78 17 69 52 79 73 12 15 59 55 25 61 96 27 98 43 30 43 36 94 67 54 86 99 100 61 65 8 65 19 18 21 75 31 2 98 55 87 14 1 17 97 94 11 57 29 34 71 76 67 45 0 78 29 86 82 29 23 77 100 48 43 65 62 88 34 7 28 13 1 1",
"output": "0"
},
{
"input": "59 27\n76 61 24 66 48 18 69 84 21 8 64 90 19 71 36 90 9 36 30 37 99 37 100 56 9 79 55 37 54 63 11 11 49 71 91 70 14 100 10 44 52 23 21 19 96 13 93 66 52 79 76 5 62 6 90 35 94 7 27",
"output": "63"
},
{
"input": "86 54\n41 84 16 5 20 79 73 13 23 24 42 73 70 80 69 71 33 44 62 29 86 88 40 64 61 55 58 19 16 23 84 100 38 91 89 98 47 50 55 87 12 94 2 12 0 1 4 26 50 96 68 34 94 80 8 22 60 3 72 84 65 89 44 52 50 9 24 34 81 28 56 17 38 85 78 90 62 60 1 40 91 2 7 41 84 22",
"output": "38"
},
{
"input": "37 2\n65 36 92 92 92 76 63 56 15 95 75 26 15 4 73 50 41 92 26 20 19 100 63 55 25 75 61 96 35 0 14 6 96 3 28 41 83",
"output": "91"
},
{
"input": "19 4\n85 2 56 70 33 75 89 60 100 81 42 28 18 92 29 96 49 23 14",
"output": "79"
},
{
"input": "89 1\n50 53 97 41 68 27 53 66 93 19 11 78 46 49 38 69 96 9 43 16 1 63 95 64 96 6 34 34 45 40 19 4 53 8 11 18 95 25 50 16 64 33 97 49 23 81 63 10 30 73 76 55 7 70 9 98 6 36 75 78 3 92 85 75 40 75 55 71 9 91 15 17 47 55 44 35 55 88 53 87 61 22 100 56 14 87 36 84 24",
"output": "91"
},
{
"input": "67 0\n40 48 15 46 90 7 65 52 24 15 42 81 2 6 71 94 32 18 97 67 83 98 48 51 10 47 8 68 36 46 65 75 90 30 62 9 5 35 80 60 69 58 62 68 58 73 80 9 22 46 56 64 44 11 93 73 62 54 15 20 17 69 16 33 85 62 49",
"output": "83"
},
{
"input": "96 0\n38 97 82 43 80 40 1 99 50 94 81 63 92 13 57 24 4 10 25 32 79 56 96 19 25 14 69 56 66 22 23 78 87 76 37 30 75 77 61 64 35 64 62 32 44 62 6 84 91 44 99 5 71 19 17 12 35 52 1 14 35 18 8 36 54 42 4 67 80 11 88 44 34 35 12 38 66 42 4 90 45 10 1 44 37 96 23 28 100 90 75 17 27 67 51 70",
"output": "94"
},
{
"input": "14 14\n87 63 62 31 59 47 40 89 92 43 80 30 99 42",
"output": "43"
},
{
"input": "12 0\n100 1 100 2 100 3 100 4 100 5 100 0",
"output": "100"
},
{
"input": "3 1\n1 2 3",
"output": "0"
},
{
"input": "3 2\n3 3 3",
"output": "0"
},
{
"input": "3 3\n3 2 1",
"output": "0"
},
{
"input": "3 100\n1 2 3",
"output": "0"
},
{
"input": "2 100\n0 0",
"output": "0"
},
{
"input": "2 90\n10 5",
"output": "0"
},
{
"input": "2 5\n5 4",
"output": "0"
},
{
"input": "3 1\n19 20 1",
"output": "18"
},
{
"input": "5 1\n5 10 7 4 20",
"output": "2"
},
{
"input": "5 1\n1 2 3 4 5",
"output": "0"
}
] | 1,398,866,754 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 77 | 0 |
s = input().rstrip().split(' ')
n, c = int (s[0]), int(s[1])
x = input().rstrip().split(' ')
max = int (x[0]) - int (x[1]) - c
for i in range (1, n - 1):
if int (x[i]) - int (x[i + 1]) - c > max:
max = int (x[i]) - int (x[i+1]) - c
if max < 0:
max = 0
print (max)
| Title: Bear and Raspberry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for *c* kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day *d* (1<=≤<=*d*<=<<=*n*), lent a barrel of honey and immediately (on day *d*) sell it according to a daily exchange rate. The next day (*d*<=+<=1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day *d*<=+<=1) give his friend the borrowed barrel of honey as well as *c* kilograms of raspberry for renting the barrel.
The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan.
Input Specification:
The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100), the price of a honey barrel on day *i*.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['5 1\n5 10 7 3 20\n', '6 2\n100 1 10 40 10 40\n', '3 0\n1 2 3\n']
Demo Output:
['3\n', '97\n', '0\n']
Note:
In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97. | ```python
s = input().rstrip().split(' ')
n, c = int (s[0]), int(s[1])
x = input().rstrip().split(' ')
max = int (x[0]) - int (x[1]) - c
for i in range (1, n - 1):
if int (x[i]) - int (x[i + 1]) - c > max:
max = int (x[i]) - int (x[i+1]) - c
if max < 0:
max = 0
print (max)
``` | 3 |
|
977 | A | Wrong Subtraction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit).
You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions.
It is guaranteed that the result will be positive integer number. | The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly. | Print one integer number — the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number. | [
"512 4\n",
"1000000000 9\n"
] | [
"50\n",
"1\n"
] | The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | 0 | [
{
"input": "512 4",
"output": "50"
},
{
"input": "1000000000 9",
"output": "1"
},
{
"input": "131203 11",
"output": "12"
},
{
"input": "999999999 50",
"output": "9999"
},
{
"input": "999999999 49",
"output": "99990"
},
{
"input": "131203 9",
"output": "130"
},
{
"input": "900000000 16",
"output": "1"
},
{
"input": "909090909 50",
"output": "3"
},
{
"input": "1001 2",
"output": "100"
},
{
"input": "5 2",
"output": "3"
},
{
"input": "2 1",
"output": "1"
}
] | 1,694,080,862 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 46 | 0 | a=str(input(""))
b=0
f=-1
c=''
d=''
while a[f]!=" ":
d=a[f]+d
f=f-1
while a[b]!=" " :
c=c+a[b]
b=b+1
e=int(c)
g=int(d)
for i in range(0,g):
if e%10==0:
e=e/10
else:
e=e-1
print(int(e)) | Title: Wrong Subtraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit).
You are given an integer number $n$. Tanya will subtract one from it $k$ times. Your task is to print the result after all $k$ subtractions.
It is guaranteed that the result will be positive integer number.
Input Specification:
The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly.
Output Specification:
Print one integer number — the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number.
Demo Input:
['512 4\n', '1000000000 9\n']
Demo Output:
['50\n', '1\n']
Note:
The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | ```python
a=str(input(""))
b=0
f=-1
c=''
d=''
while a[f]!=" ":
d=a[f]+d
f=f-1
while a[b]!=" " :
c=c+a[b]
b=b+1
e=int(c)
g=int(d)
for i in range(0,g):
if e%10==0:
e=e/10
else:
e=e-1
print(int(e))
``` | 3 |
|
276 | B | Little Girl and Game | PROGRAMMING | 1,300 | [
"games",
"greedy"
] | null | null | The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't.
Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second. | The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters. | In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes. | [
"aba\n",
"abca\n"
] | [
"First\n",
"Second\n"
] | none | 1,000 | [
{
"input": "aba",
"output": "First"
},
{
"input": "abca",
"output": "Second"
},
{
"input": "aabb",
"output": "First"
},
{
"input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo",
"output": "Second"
},
{
"input": "gevqgtaorjixsxnbcoybr",
"output": "First"
},
{
"input": "xvhtcbtouuddhylxhplgjxwlo",
"output": "First"
},
{
"input": "knaxhkbokmtfvnjvlsbrfoefpjpkqwlumeqqbeohodnwevhllkylposdpjuoizyunuxivzrjofiyxxiliuwhkjqpkqxukxroivfhikxjdtwcqngqswptdwrywxszxrqojjphzwzxqftnfhkapeejdgckfyrxtpuipfljsjwgpjfatmxpylpnerllshuvkbomlpghjrxcgxvktgeyuhrcwgvdmppqnkdmjtxukzlzqhfbgrishuhkyggkpstvqabpxoqjuovwjwcmazmvpfpnljdgpokpatjnvwacotkvxheorzbsrazldsquijzkmtmqahakjrjvzkquvayxpqrmqqcknilpqpjapagezonfpz",
"output": "Second"
},
{
"input": "desktciwoidfuswycratvovutcgjrcyzmilsmadzaegseetexygedzxdmorxzxgiqhcuppshcsjcozkopebegfmxzxxagzwoymlghgjexcgfojychyt",
"output": "First"
},
{
"input": "gfhuidxgxpxduqrfnqrnefgtyxgmrtehmddjkddwdiayyilaknxhlxszeslnsjpcrwnoqubmbpcehiftteirkfvbtfyibiikdaxmondnawtvqccctdxrjcfxqwqhvvrqmhqflbzskrayvruqvqijrmikucwzodxvufwxpxxjxlifdjzxrttjzatafkbzsjupsiefmipdufqltedjlytphzppoevxawjdhbxgennevbvdgpoeihasycctyddenzypoprchkoioouhcexjqwjflxvkgpgjatstlmledxasecfhwvabzwviywsiaryqrxyeceefblherqjevdzkfxslqiytwzz",
"output": "First"
},
{
"input": "fezzkpyctjvvqtncmmjsitrxaliyhirspnjjngvzdoudrkkvvdiwcwtcxobpobzukegtcrwsgxxzlcphdxkbxdximqbycaicfdeqlvzboptfimkzvjzdsvahorqqhcirpkhtwjkplitpacpkpbhnxtoxuoqsxcxnhtrmzvexmpvlethbkvmlzftimjnidrzvcunbpysvukzgwghjmwrvstsunaocnoqohcsggtrwxiworkliqejajewbrtdwgnyynpupbrrvtfqtlaaq",
"output": "Second"
},
{
"input": "tsvxmeixijyavdalmrvscwohzubhhgsocdvnjmjtctojbxxpezzbgfltixwgzmkfwdnlhidhrdgyajggmrvmwaoydodjmzqvgabyszfqcuhwdncyfqvmackvijgpjyiauxljvvwgiofdxccwmybdfcfcrqppbvbagmnvvvhngxauwbpourviyfokwjweypzzrrzjcmddnpoaqgqfgglssjnlshrerfffmrwhapzknxveiqixflykjbnpivogtdpyjakwrdoklsbvbkjhdojfnuwbpcfdycwxecysbyjfvoykxsxgg",
"output": "First"
},
{
"input": "upgqmhfmfnodsyosgqswugfvpdxhtkxvhlsxrjiqlojchoddxkpsamwmuvopdbncymcgrkurwlxerexgswricuqxhvqvgekeofkgqabypamozmyjyfvpifsaotnyzqydcenphcsmplekinwkmwzpjnlapfdbhxjdcnarlgkfgxzfbpgsuxqfyhnxjhtojrlnprnxprfbkkcyriqztjeeepkzgzcaiutvbqqofyhddfebozhvtvrigtidxqmydjxegxipakzjcnenjkdroyjmxugj",
"output": "Second"
},
{
"input": "aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbccccccccccccccccccccddddddddddeeeeeeeeeeffffgggghhhhiiiijjjjqqqqwwwweeeerrrrttttyyyyuuuuiiiiooooppppaaaassssddddffffgggghhhhjjjjkkkkllllzzzzxxxxccccvvvvbbbbnnnnmmmm",
"output": "First"
},
{
"input": "vnvtvnxjrtffdhrfvczzoyeokjabxcilmmsrhwuakghvuabcmfpmblyroodmhfivmhqoiqhapoglwaluewhqkunzitmvijaictjdncivccedfpaezcnpwemlohbhjjlqsonuclaumgbzjamsrhuzqdqtitygggsnruuccdtxkgbdd",
"output": "First"
},
{
"input": "vqdtkbvlbdyndheoiiwqhnvcmmhnhsmwwrvesnpdfxvprqbwzbodoihrywagphlsrcbtnvppjsquuuzkjazaenienjiyctyajsqdfsdiedzugkymgzllvpxfetkwfabbiotjcknzdwsvmbbuqrxrulvgljagvxdmfsqtcczhifhoghqgffkbviphbabwiaqburerfkbqfjbptkwlahysrrfwjbqfnrgnsnsukqqcxxwqtuhvdzqmpfwrbqzdwxcaifuyhvojgurmchh",
"output": "First"
},
{
"input": "hxueikegwnrctlciwguepdsgupguykrntbszeqzzbpdlouwnmqgzcxejidstxyxhdlnttnibxstduwiflouzfswfikdudkazoefawm",
"output": "Second"
},
{
"input": "ershkhsywqftixappwqzoojtnamvqjbyfauvuubwpctspioqusnnivwsiyszfhlrskbswaiaczurygcioonjcndntwvrlaejyrghfnecltqytfmkvjxuujifgtujrqsisdawpwgttxynewiqhdhronamabysvpxankxeybcjqttbqnciwuqiehzyfjoedaradqnfthuuwrezwrkjiytpgwfwbslawbiezdbdltenjlaygwaxddplgseiaojndqjcopvolqbvnacuvfvirzbrnlnyjixngeevcggmirzatenjihpgnyfjhgsjgzepohbyhmzbatfwuorwutavlqsogrvcjpqziuifrhurq",
"output": "First"
},
{
"input": "qilwpsuxogazrfgfznngwklnioueuccyjfatjoizcctgsweitzofwkyjustizbopzwtaqxbtovkdrxeplukrcuozhpymldstbbfynkgsmafigetvzkxloxqtphvtwkgfjkiczttcsxkjpsoutdpzxytrsqgjtbdljjrbmkudrkodfvcwkcuggbsthxdyogeeyfuyhmnwgyuatfkvchavpzadfacckdurlbqjkthqbnirzzbpusxcenkpgtizayjmsahvobobudfeaewcqmrlxxnocqzmkessnguxkiccrxyvnxxlqnqfwuzmupk",
"output": "First"
},
{
"input": "opfokvwzpllctflkphutcrkferbjyyrasqqkrcvoymyrxwaudgsugcqveccymdplxmtlzfoptmrapfeizpnnhbzlkuyznwacnswibxhqunazbhdvrlidghisuqunstbuevjzimvlfvopgqxrvahhngnaumgywscfrfwfpnfxwhfrelbunmedvkssykwjyartxjiplerntzkpiiaalijiwhyuhxlvhxpkgfypvrpqqsacuwocdampnnhvibsbolyduvscsjfayxpldyvqzjbqojjxdvxtctwtifcdfcaoonzbgegyllngwvjivtxeezoabhsihcuvgvdsgjtzbzwovjshvwrljkxavowovzrfpdufpogdtujkerdorpboufrxhyswirjehgsxthlvjufvahdpeajidqipwaxokbeycrievgcfkyuyavaq",
"output": "Second"
},
{
"input": "a",
"output": "First"
},
{
"input": "ab",
"output": "Second"
},
{
"input": "abacaba",
"output": "First"
},
{
"input": "abazaba",
"output": "First"
},
{
"input": "zz",
"output": "First"
},
{
"input": "aassddxyz",
"output": "First"
},
{
"input": "abcdefghijklmnopqrstuvwxyz",
"output": "Second"
},
{
"input": "aabc",
"output": "Second"
},
{
"input": "abcabc",
"output": "First"
},
{
"input": "aaabbbccdd",
"output": "Second"
},
{
"input": "aabbcccc",
"output": "First"
}
] | 1,696,898,167 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 51 | 154 | 0 | import sys
input = sys.stdin.readline
from collections import Counter , defaultdict
def instr():
return input()[:-1]
import math
############################
w = instr()
c = Counter(w)
f = sum(x%2 != 0 for x in c.values())
if f == 0 :
print("First")
else :
print("First" if f%2 != 0 else "Second") | Title: Little Girl and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules:
- The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the player before his turn can reorder the letters in string *s* so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't.
Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.
Input Specification:
The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters.
Output Specification:
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
Demo Input:
['aba\n', 'abca\n']
Demo Output:
['First\n', 'Second\n']
Note:
none | ```python
import sys
input = sys.stdin.readline
from collections import Counter , defaultdict
def instr():
return input()[:-1]
import math
############################
w = instr()
c = Counter(w)
f = sum(x%2 != 0 for x in c.values())
if f == 0 :
print("First")
else :
print("First" if f%2 != 0 else "Second")
``` | 3 |
|
998 | B | Cutting | PROGRAMMING | 1,200 | [
"dp",
"greedy",
"sortings"
] | null | null | There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulting segment will have the same number of odd and even integers.
Cuts separate a sequence to continuous (contiguous) segments. You may think about each cut as a break between two adjacent elements in a sequence. So after cutting each element belongs to exactly one segment. Say, $[4, 1, 2, 3, 4, 5, 4, 4, 5, 5]$ $\to$ two cuts $\to$ $[4, 1 | 2, 3, 4, 5 | 4, 4, 5, 5]$. On each segment the number of even elements should be equal to the number of odd elements.
The cost of the cut between $x$ and $y$ numbers is $|x - y|$ bitcoins. Find the maximum possible number of cuts that can be made while spending no more than $B$ bitcoins. | First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have.
Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal number of even and odd numbers | Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins. | [
"6 4\n1 2 5 10 15 20\n",
"4 10\n1 3 2 4\n",
"6 100\n1 2 3 4 5 6\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins.
In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.
In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$. The total price of the cuts is $1 + 1 = 2$ bitcoins. | 1,000 | [
{
"input": "6 4\n1 2 5 10 15 20",
"output": "1"
},
{
"input": "4 10\n1 3 2 4",
"output": "0"
},
{
"input": "6 100\n1 2 3 4 5 6",
"output": "2"
},
{
"input": "2 100\n13 78",
"output": "0"
},
{
"input": "10 1\n56 56 98 2 11 64 97 41 95 53",
"output": "0"
},
{
"input": "10 100\n94 65 24 47 29 98 20 65 6 17",
"output": "2"
},
{
"input": "100 1\n35 6 19 84 49 64 36 91 50 65 21 86 20 89 10 52 50 24 98 74 11 48 58 98 51 85 1 29 44 83 9 97 68 41 83 57 1 57 46 42 87 2 32 50 3 57 17 77 22 100 36 27 3 34 55 8 90 61 34 20 15 39 43 46 60 60 14 23 4 22 75 51 98 23 69 22 99 57 63 30 79 7 16 8 34 84 13 47 93 40 48 25 93 1 80 6 82 93 6 21",
"output": "0"
},
{
"input": "100 10\n3 20 3 29 90 69 2 30 70 28 71 99 22 99 34 70 87 48 3 92 71 61 26 90 14 38 51 81 16 33 49 71 14 52 50 95 65 16 80 57 87 47 29 14 40 31 74 15 87 76 71 61 30 91 44 10 87 48 84 12 77 51 25 68 49 38 79 8 7 9 39 19 48 40 15 53 29 4 60 86 76 84 6 37 45 71 46 38 80 68 94 71 64 72 41 51 71 60 79 7",
"output": "2"
},
{
"input": "100 100\n60 83 82 16 17 7 89 6 83 100 85 41 72 44 23 28 64 84 3 23 33 52 93 30 81 38 67 25 26 97 94 78 41 74 74 17 53 51 54 17 20 81 95 76 42 16 16 56 74 69 30 9 82 91 32 13 47 45 97 40 56 57 27 28 84 98 91 5 61 20 3 43 42 26 83 40 34 100 5 63 62 61 72 5 32 58 93 79 7 18 50 43 17 24 77 73 87 74 98 2",
"output": "11"
},
{
"input": "100 100\n70 54 10 72 81 84 56 15 27 19 43 100 49 44 52 33 63 40 95 17 58 2 51 39 22 18 82 1 16 99 32 29 24 94 9 98 5 37 47 14 42 73 41 31 79 64 12 6 53 26 68 67 89 13 90 4 21 93 46 74 75 88 66 57 23 7 25 48 92 62 30 8 50 61 38 87 71 34 97 28 80 11 60 91 3 35 86 96 36 20 59 65 83 45 76 77 78 69 85 55",
"output": "3"
},
{
"input": "100 100\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": "49"
},
{
"input": "10 10\n94 32 87 13 4 22 85 81 18 95",
"output": "1"
},
{
"input": "10 50\n40 40 9 3 64 96 67 19 21 30",
"output": "1"
},
{
"input": "100 50\n13 31 29 86 46 10 2 87 94 2 28 31 29 15 64 3 94 71 37 76 9 91 89 38 12 46 53 33 58 11 98 4 37 72 30 52 6 86 40 98 28 6 34 80 61 47 45 69 100 47 91 64 87 41 67 58 88 75 13 81 36 58 66 29 10 27 54 83 44 15 11 33 49 36 61 18 89 26 87 1 99 19 57 21 55 84 20 74 14 43 15 51 2 76 22 92 43 14 72 77",
"output": "3"
},
{
"input": "100 1\n78 52 95 76 96 49 53 59 77 100 64 11 9 48 15 17 44 46 21 54 39 68 43 4 32 28 73 6 16 62 72 84 65 86 98 75 33 45 25 3 91 82 2 92 63 88 7 50 97 93 14 22 20 42 60 55 80 85 29 34 56 71 83 38 26 47 90 70 51 41 40 31 37 12 35 99 67 94 1 87 57 8 61 19 23 79 36 18 66 74 5 27 81 69 24 58 13 10 89 30",
"output": "0"
},
{
"input": "100 10\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43",
"output": "0"
},
{
"input": "100 50\n2 4 82 12 47 63 52 91 87 45 53 1 17 25 64 50 9 13 22 54 21 30 43 24 38 33 68 11 41 78 99 23 28 18 58 67 79 10 71 56 49 61 26 29 59 20 90 74 5 75 89 8 39 95 72 42 66 98 44 32 88 35 92 3 97 55 65 51 77 27 81 76 84 69 73 85 19 46 62 100 60 37 7 36 57 6 14 83 40 48 16 70 96 15 31 93 80 86 94 34",
"output": "1"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "1"
},
{
"input": "100 10\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": "10"
},
{
"input": "100 50\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": "49"
},
{
"input": "100 30\n2 1 2 2 2 2 1 1 1 2 1 1 2 2 1 2 1 2 2 2 2 1 2 1 2 1 1 2 1 1 2 2 2 1 1 2 1 2 2 2 1 1 1 1 1 2 1 1 1 1 1 2 2 2 2 1 2 1 1 1 2 2 2 2 1 2 2 1 1 1 1 2 2 2 1 2 2 1 2 1 1 2 2 2 1 2 2 1 2 1 1 2 1 1 1 1 2 1 1 2",
"output": "11"
},
{
"input": "100 80\n1 1 1 2 2 1 1 2 1 1 1 1 2 2 2 1 2 2 2 2 1 1 2 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 2 2 2 2 1 2 2 1 2 1 1 1 1 2 2 1 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 1 1 2 1 1 1 2 1 1 2 1 2 1 2 2 1 1 2 1 1 1 1 2 2 2 1 2 2 1 2",
"output": "12"
},
{
"input": "100 30\n100 99 100 99 99 100 100 99 100 99 99 100 100 100 99 99 99 100 99 99 99 99 100 99 99 100 100 99 100 99 99 99 100 99 100 100 99 100 100 100 100 100 99 99 100 99 99 100 99 100 99 99 100 100 99 100 99 99 100 99 100 100 100 100 99 99 99 100 99 100 99 100 100 100 99 100 100 100 99 100 99 99 100 100 100 100 99 99 99 100 99 100 100 99 99 99 100 100 99 99",
"output": "14"
},
{
"input": "100 80\n99 100 100 100 99 99 99 99 100 99 99 99 99 99 99 99 99 100 100 99 99 99 99 99 100 99 100 99 100 100 100 100 100 99 100 100 99 99 100 100 100 100 100 99 100 99 100 99 99 99 100 99 99 99 99 99 99 99 99 100 99 100 100 99 99 99 99 100 100 100 99 100 100 100 100 100 99 100 100 100 100 100 100 100 100 99 99 99 99 100 99 100 100 100 100 100 99 100 99 100",
"output": "4"
},
{
"input": "100 30\n100 100 39 39 39 100 100 39 39 100 39 39 100 39 100 39 100 100 100 100 100 39 100 100 100 39 39 39 100 39 100 100 39 39 100 39 39 39 100 100 39 100 39 100 39 39 100 100 39 100 39 100 39 39 39 100 39 100 39 39 39 100 39 39 100 100 39 39 39 100 100 39 39 39 100 100 100 100 39 100 100 100 39 39 100 39 100 100 39 100 39 100 39 39 100 39 39 100 100 100",
"output": "5"
},
{
"input": "100 80\n39 100 39 100 100 100 100 39 39 100 100 39 39 100 39 39 39 39 100 39 39 39 39 100 100 100 100 39 100 39 39 100 100 39 39 100 39 100 39 100 100 39 39 100 39 39 39 100 39 100 39 100 100 100 100 100 100 100 39 100 39 100 100 100 39 39 39 39 39 100 100 100 39 100 100 100 100 39 100 100 39 39 100 39 39 39 100 39 100 39 39 100 100 39 100 39 39 39 100 39",
"output": "6"
},
{
"input": "4 1\n1 2 3 4",
"output": "1"
},
{
"input": "4 1\n1 2 1 2",
"output": "1"
},
{
"input": "4 4\n1 2 6 7",
"output": "1"
},
{
"input": "4 8\n1 2 10 11",
"output": "1"
},
{
"input": "6 2\n1 2 3 4 5 6",
"output": "2"
},
{
"input": "6 1\n1 2 1 2 1 2",
"output": "1"
},
{
"input": "6 4\n1 2 4 5 7 8",
"output": "2"
},
{
"input": "6 3\n1 2 5 10 15 20",
"output": "1"
}
] | 1,651,734,162 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n, money= int(input()) #���������� ����� � ��������������������
#money = int(input())
print(n, money) | Title: Cutting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulting segment will have the same number of odd and even integers.
Cuts separate a sequence to continuous (contiguous) segments. You may think about each cut as a break between two adjacent elements in a sequence. So after cutting each element belongs to exactly one segment. Say, $[4, 1, 2, 3, 4, 5, 4, 4, 5, 5]$ $\to$ two cuts $\to$ $[4, 1 | 2, 3, 4, 5 | 4, 4, 5, 5]$. On each segment the number of even elements should be equal to the number of odd elements.
The cost of the cut between $x$ and $y$ numbers is $|x - y|$ bitcoins. Find the maximum possible number of cuts that can be made while spending no more than $B$ bitcoins.
Input Specification:
First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have.
Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal number of even and odd numbers
Output Specification:
Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins.
Demo Input:
['6 4\n1 2 5 10 15 20\n', '4 10\n1 3 2 4\n', '6 100\n1 2 3 4 5 6\n']
Demo Output:
['1\n', '0\n', '2\n']
Note:
In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins.
In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.
In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$. The total price of the cuts is $1 + 1 = 2$ bitcoins. | ```python
n, money= int(input()) #���������� ����� � ��������������������
#money = int(input())
print(n, money)
``` | -1 |
|
624 | B | Making a String | PROGRAMMING | 1,100 | [
"greedy",
"sortings"
] | null | null | You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:
- the *i*-th letter occurs in the string no more than *a**i* times; - the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once. | The first line of the input contains a single integer *n* (2<=<=≤<=<=*n*<=<=≤<=<=26) — the number of letters in the alphabet.
The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — *i*-th of these integers gives the limitation on the number of occurrences of the *i*-th character in the string. | Print a single integer — the maximum length of the string that meets all the requirements. | [
"3\n2 5 5\n",
"3\n1 1 2\n"
] | [
"11\n",
"3\n"
] | For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc". | 1,000 | [
{
"input": "3\n2 5 5",
"output": "11"
},
{
"input": "3\n1 1 2",
"output": "3"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "3\n1 1000000000 2",
"output": "1000000003"
},
{
"input": "26\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "25999999675"
},
{
"input": "2\n559476582 796461544",
"output": "1355938126"
},
{
"input": "2\n257775227 621811272",
"output": "879586499"
},
{
"input": "10\n876938317 219479349 703839299 977218449 116819315 752405530 393874852 286326991 592978634 155758306",
"output": "5075639042"
},
{
"input": "26\n72 49 87 47 94 96 36 91 43 11 19 83 36 38 10 93 95 81 4 96 60 38 97 37 36 41",
"output": "1478"
},
{
"input": "26\n243 364 768 766 633 535 502 424 502 283 592 877 137 891 837 990 681 898 831 487 595 604 747 856 805 688",
"output": "16535"
},
{
"input": "26\n775 517 406 364 548 951 680 984 466 141 960 513 660 849 152 250 176 601 199 370 971 554 141 224 724 543",
"output": "13718"
},
{
"input": "26\n475 344 706 807 925 813 974 166 578 226 624 591 419 894 574 909 544 597 170 990 893 785 399 172 792 748",
"output": "16115"
},
{
"input": "26\n130 396 985 226 487 671 188 706 106 649 38 525 210 133 298 418 953 431 577 69 12 982 264 373 283 266",
"output": "10376"
},
{
"input": "26\n605 641 814 935 936 547 524 702 133 674 173 102 318 620 248 523 77 718 318 635 322 362 306 86 8 442",
"output": "11768"
},
{
"input": "26\n220 675 725 888 725 654 546 806 379 182 604 667 734 394 889 731 572 193 850 651 844 734 163 671 820 887",
"output": "16202"
},
{
"input": "26\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",
"output": "25675"
},
{
"input": "26\n1001 1001 1000 1000 1001 1000 1001 1001 1001 1000 1000 1001 1001 1000 1000 1000 1000 1001 1000 1001 1001 1000 1001 1001 1001 1000",
"output": "25701"
},
{
"input": "26\n1000 1001 1000 1001 1000 1001 1001 1000 1001 1002 1002 1000 1001 1000 1000 1000 1001 1002 1001 1000 1000 1001 1000 1002 1001 1002",
"output": "25727"
},
{
"input": "26\n1003 1002 1002 1003 1000 1000 1000 1003 1000 1001 1003 1003 1000 1002 1002 1002 1001 1003 1000 1001 1000 1001 1001 1000 1003 1003",
"output": "25753"
},
{
"input": "26\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": "1"
},
{
"input": "26\n8717 9417 1409 7205 3625 6247 8626 9486 464 4271 1698 8449 4551 1528 7456 9198 4886 2889 7534 506 7867 9410 1635 4955 2580 2580",
"output": "137188"
},
{
"input": "26\n197464663 125058028 622449215 11119637 587496049 703992162 219591040 965159268 229879004 278894000 841629744 616893922 218779915 362575332 844188865 342411376 369680019 43823059 921419789 999588082 943769007 35365522 301907919 758302419 427454397 807507709",
"output": "12776400142"
},
{
"input": "26\n907247856 970380443 957324066 929910532 947150618 944189007 998282297 988343406 981298600 943026596 953932265 972691398 950024048 923033790 996423650 972134755 946404759 918183059 902987271 965507679 906967700 982106487 933997242 972594441 977736332 928874832",
"output": "24770753129"
},
{
"input": "26\n999999061 999999688 999999587 999999429 999999110 999999563 999999120 999999111 999999794 999999890 999999004 999999448 999999770 999999543 999999460 999999034 999999361 999999305 999999201 999999778 999999432 999999844 999999133 999999342 999999600 999999319",
"output": "25999984927"
},
{
"input": "3\n587951561 282383259 612352726",
"output": "1482687546"
},
{
"input": "4\n111637338 992238139 787658714 974622806",
"output": "2866156997"
},
{
"input": "5\n694257603 528073418 726928894 596328666 652863391",
"output": "3198451972"
},
{
"input": "6\n217943380 532900593 902234882 513005821 369342573 495810412",
"output": "3031237661"
},
{
"input": "7\n446656860 478792281 77541870 429682977 85821755 826122363 563802405",
"output": "2908420511"
},
{
"input": "8\n29278125 778590752 252847858 51388836 802299938 215370803 901540149 242074772",
"output": "3273391233"
},
{
"input": "9\n552962902 724482439 133182550 673093696 518779120 604618242 534250189 847695567 403066553",
"output": "4992131258"
},
{
"input": "10\n600386086 862479376 284190454 781950823 672077209 5753052 145701234 680334621 497013634 35429365",
"output": "4565315854"
},
{
"input": "11\n183007351 103343359 164525146 698627979 388556391 926007595 483438978 580927711 659384363 201890880 920750904",
"output": "5310460657"
},
{
"input": "12\n706692128 108170535 339831134 320333838 810063277 20284739 821176722 481520801 467848308 604388203 881959821 874133307",
"output": "6436402813"
},
{
"input": "13\n525349200 54062222 810108418 237010994 821513756 409532178 158915465 87142595 630219037 770849718 843168738 617993222 504443485",
"output": "6470309028"
},
{
"input": "14\n812998169 353860693 690443110 153688149 537992938 798779618 791624505 282706982 733654279 468319337 568341847 597888944 649703235 667623671",
"output": "8107625477"
},
{
"input": "15\n336683946 299752380 865749098 775393009 959499824 893055762 365399057 419335880 896025008 575845364 529550764 341748859 30999793 464432689 19445239",
"output": "7772916672"
},
{
"input": "16\n860368723 540615364 41056086 692070164 970950302 282304201 998108096 24957674 999460249 37279175 490759681 26673285 412295352 671298115 627182888 90740349",
"output": "7766119704"
},
{
"input": "17\n148018692 545442539 980325266 313776023 687429485 376580345 40875544 925549764 161831978 144805202 451968598 475560904 262583806 468107133 60900936 281546097 912565045",
"output": "7237867357"
},
{
"input": "18\n966674765 786305522 860659958 935480883 108937371 60800080 673584584 826142855 560238516 606238013 413177515 455456626 643879364 969943855 963609881 177380550 544192822 864797474",
"output": "11417500634"
},
{
"input": "19\n490360541 496161402 330938242 852158038 120387849 686083328 247359135 431764649 427637949 8736336 843378328 435352349 494167818 766752874 161292122 368186298 470791896 813444279 170758124",
"output": "8615711557"
},
{
"input": "20\n654616375 542649443 729213190 188364665 238384327 726353863 974350390 526804424 601329631 886592063 734805196 275562411 861801362 374466292 119830901 403120565 670982545 63210795 130397643 601611646",
"output": "10304447727"
},
{
"input": "21\n942265343 252505322 904519178 810069524 954862509 115602302 548124942 132426218 999736168 584061682 696014113 960485837 712089816 581331718 317512142 593926314 302610323 716885305 477125514 813997503 535631456",
"output": "12951783229"
},
{
"input": "22\n465951120 788339601 784853870 726746679 376370396 504849742 180834982 33019308 867135601 455551901 657223030 940381560 93386374 378140736 161286599 548696254 934237100 75589518 764917898 731412064 205669368 630662937",
"output": "11305256638"
},
{
"input": "23\n989635897 498195481 255132154 643423835 387820874 894097181 223601429 228583694 265543138 153021520 618431947 684241474 943673829 174949754 358967839 444530707 801900686 965299835 347682577 648826625 406714384 129525158 958578251",
"output": "12022378269"
},
{
"input": "24\n277285866 739058464 135466846 265129694 104300056 519381429 856310469 834204489 132942572 260547547 343605057 664137197 619941683 676786476 497713592 635336455 138557168 618975345 635474960 861212482 76752297 923357675 517046816 274123722",
"output": "11607648357"
},
{
"input": "25\n95942939 979921447 310772834 181806850 525806942 613657573 194049213 734797579 531349109 721980358 304813974 113025815 470230137 473595494 695394833 590106396 770183946 567622150 218239639 778627043 41761505 127248600 134450869 860350034 901937574",
"output": "11937672853"
},
{
"input": "26\n619627716 984748623 486078822 98484005 537257421 2906012 62795060 635390669 103777246 829506385 971050595 92921538 851525695 680460920 893076074 780912144 401811723 221297659 269996214 991012900 242806521 626109821 987889730 682613155 209557740 806895799",
"output": "14070510187"
},
{
"input": "26\n10 1 20 2 23 3 14 6 7 13 26 21 11 8 16 25 12 15 19 9 17 22 24 18 5 4",
"output": "351"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "11"
},
{
"input": "5\n2 2 2 2 2",
"output": "3"
},
{
"input": "10\n10 10 10 10 10 10 10 10 1 1",
"output": "53"
},
{
"input": "10\n100 100 10 10 10 10 10 1 1 1",
"output": "240"
},
{
"input": "6\n5 3 3 3 3 1",
"output": "11"
},
{
"input": "4\n4 3 2 1",
"output": "10"
},
{
"input": "5\n1 1 1 1 1",
"output": "1"
}
] | 1,454,610,507 | 5,007 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 46 | 0 | n = int(input())
s = input().split()
s = [int(i) for i in s]
answer = 0
used = []
for i in range(n):
if s[i] not in used:
answer += s[i]
used.append(s[i])
print(answer)
| Title: Making a String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:
- the *i*-th letter occurs in the string no more than *a**i* times; - the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once.
Input Specification:
The first line of the input contains a single integer *n* (2<=<=≤<=<=*n*<=<=≤<=<=26) — the number of letters in the alphabet.
The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — *i*-th of these integers gives the limitation on the number of occurrences of the *i*-th character in the string.
Output Specification:
Print a single integer — the maximum length of the string that meets all the requirements.
Demo Input:
['3\n2 5 5\n', '3\n1 1 2\n']
Demo Output:
['11\n', '3\n']
Note:
For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc". | ```python
n = int(input())
s = input().split()
s = [int(i) for i in s]
answer = 0
used = []
for i in range(n):
if s[i] not in used:
answer += s[i]
used.append(s[i])
print(answer)
``` | 0 |
|
92 | B | Binary Number | PROGRAMMING | 1,300 | [
"greedy"
] | B. Binary Number | 1 | 256 | Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divides *x* by 2. Fangy knows that for any positive integer number the process ends in finite time.
How many actions should Fangy perform to get a number one from number *x*? | The first line contains a positive integer *x* in a binary system. It is guaranteed that the first digit of *x* is different from a zero and the number of its digits does not exceed 106. | Print the required number of actions. | [
"1\n",
"1001001\n",
"101110\n"
] | [
"0\n",
"12\n",
"8\n"
] | Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide it by 2 two times in a row. As a result, we get 1. | 1,000 | [
{
"input": "1",
"output": "0"
},
{
"input": "1001001",
"output": "12"
},
{
"input": "101110",
"output": "8"
},
{
"input": "11",
"output": "3"
},
{
"input": "11110001101",
"output": "16"
},
{
"input": "1010101001001111000111110011111000010101011111101010",
"output": "74"
},
{
"input": "1100000010010100111011100011110101111",
"output": "55"
},
{
"input": "11000111111110110110100110110101111100010100110110010",
"output": "74"
},
{
"input": "11100000110100011110101001101111100000011001111000011110000000111110111",
"output": "106"
},
{
"input": "1000101100110000000001111010110000000010001001111110011011000011101011001001010010111",
"output": "133"
},
{
"input": "1000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "72"
},
{
"input": "10000100000",
"output": "16"
}
] | 1,681,900,848 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 46 | 0 | s = input()
ss = s[::-1]
num = 0
j = 0
for i in range(0 , len(ss)):
if (ss[i] == '1'):
num += pow(2,j)
j += 1
ans = 0
while(num > 1):
if(num % 2):
num = num + 1
else :
num = num / 2
ans = ans + 1
print(ans)
| Title: Binary Number
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer *x* and wants to get a number one from it. While *x* is not equal to 1, Fangy repeats the following action: if *x* is odd, then he adds 1 to it, otherwise he divides *x* by 2. Fangy knows that for any positive integer number the process ends in finite time.
How many actions should Fangy perform to get a number one from number *x*?
Input Specification:
The first line contains a positive integer *x* in a binary system. It is guaranteed that the first digit of *x* is different from a zero and the number of its digits does not exceed 106.
Output Specification:
Print the required number of actions.
Demo Input:
['1\n', '1001001\n', '101110\n']
Demo Output:
['0\n', '12\n', '8\n']
Note:
Let's consider the third sample. Number 101110 is even, which means that we should divide it by 2. After the dividing Fangy gets an odd number 10111 and adds one to it. Number 11000 can be divided by 2 three times in a row and get number 11. All that's left is to increase the number by one (we get 100), and then divide it by 2 two times in a row. As a result, we get 1. | ```python
s = input()
ss = s[::-1]
num = 0
j = 0
for i in range(0 , len(ss)):
if (ss[i] == '1'):
num += pow(2,j)
j += 1
ans = 0
while(num > 1):
if(num % 2):
num = num + 1
else :
num = num / 2
ans = ans + 1
print(ans)
``` | 0 |
897 | B | Chtholly's request | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | — I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thinking about a problem for days:
If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.
Given integers *k* and *p*, calculate the sum of the *k* smallest zcy numbers and output this sum modulo *p*.
Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! | The first line contains two integers *k* and *p* (1<=≤<=*k*<=≤<=105,<=1<=≤<=*p*<=≤<=109). | Output single integer — answer to the problem. | [
"2 100\n",
"5 30\n"
] | [
"33\n",
"15\n"
] | In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.
In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 1,000 | [
{
"input": "2 100",
"output": "33"
},
{
"input": "5 30",
"output": "15"
},
{
"input": "42147 412393322",
"output": "251637727"
},
{
"input": "77809 868097296",
"output": "440411873"
},
{
"input": "5105 443422097",
"output": "363192634"
},
{
"input": "75615 376679484",
"output": "373089399"
},
{
"input": "22951 23793302",
"output": "1898631"
},
{
"input": "12785 993582106",
"output": "286204743"
},
{
"input": "60276 428978808",
"output": "376477293"
},
{
"input": "84776 104860385",
"output": "10209596"
},
{
"input": "41984 653766991",
"output": "17823101"
},
{
"input": "100000 1000000000",
"output": "495495496"
},
{
"input": "41163 472310076",
"output": "207304047"
},
{
"input": "6983 765352180",
"output": "586866999"
},
{
"input": "33493 967727004",
"output": "305705165"
},
{
"input": "90898 94010922",
"output": "65928728"
},
{
"input": "67298 349286579",
"output": "156435206"
},
{
"input": "92452 296773064",
"output": "229486976"
},
{
"input": "58832 563860457",
"output": "16775206"
},
{
"input": "90234 156145441",
"output": "44023160"
},
{
"input": "91454 977186148",
"output": "681779748"
},
{
"input": "11108 444095250",
"output": "188075844"
},
{
"input": "46304 584475527",
"output": "275627129"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 1000000000",
"output": "11"
},
{
"input": "100000 1",
"output": "0"
}
] | 1,607,101,986 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 171 | 2,150,400 | k, p = map(int, input().split())
res = 0
for i in range(1, k+1):
res += int(str(i)+(str(i)[::-1]))
res %= p
print(res) | Title: Chtholly's request
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
— I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thinking about a problem for days:
If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.
Given integers *k* and *p*, calculate the sum of the *k* smallest zcy numbers and output this sum modulo *p*.
Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!
Input Specification:
The first line contains two integers *k* and *p* (1<=≤<=*k*<=≤<=105,<=1<=≤<=*p*<=≤<=109).
Output Specification:
Output single integer — answer to the problem.
Demo Input:
['2 100\n', '5 30\n']
Demo Output:
['33\n', '15\n']
Note:
In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.
In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
k, p = map(int, input().split())
res = 0
for i in range(1, k+1):
res += int(str(i)+(str(i)[::-1]))
res %= p
print(res)
``` | 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,637,853,222 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 31 | 0 | n=int(input())
l=list(map(int,input().split()))
l=l[:n]
m=[]
for i in range(n-1):
if l[i]<l[i+1]:m.append(1)
elif l[i]==l[i+1]:m.append(0)
else:m.append(-1)
a=True
for i in range(len(m)-1):
if m[i]==-1 and (m[i+1]==1 or m[i+1]==0):
a=False
print('YES' if a else 'NO') | 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())
l=list(map(int,input().split()))
l=l[:n]
m=[]
for i in range(n-1):
if l[i]<l[i+1]:m.append(1)
elif l[i]==l[i+1]:m.append(0)
else:m.append(-1)
a=True
for i in range(len(m)-1):
if m[i]==-1 and (m[i+1]==1 or m[i+1]==0):
a=False
print('YES' if a else 'NO')
``` | 0 |
|
158 | B | Taxi | PROGRAMMING | 1,100 | [
"*special",
"greedy",
"implementation"
] | null | null | After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of groups of schoolchildren. The second line contains a sequence of integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s**i*<=≤<=4). The integers are separated by a space, *s**i* is the number of children in the *i*-th group. | Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus. | [
"5\n1 2 4 3 3\n",
"8\n2 3 4 4 2 1 3 1\n"
] | [
"4\n",
"5\n"
] | In the first test we can sort the children into four cars like this:
- the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly).
There are other ways to sort the groups into four cars. | 1,000 | [
{
"input": "5\n1 2 4 3 3",
"output": "4"
},
{
"input": "8\n2 3 4 4 2 1 3 1",
"output": "5"
},
{
"input": "5\n4 4 4 4 4",
"output": "5"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "4\n3 2 1 3",
"output": "3"
},
{
"input": "4\n2 4 1 3",
"output": "3"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n3",
"output": "1"
},
{
"input": "1\n4",
"output": "1"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "2\n4 4",
"output": "2"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "2\n3 1",
"output": "1"
},
{
"input": "2\n4 1",
"output": "2"
},
{
"input": "2\n2 3",
"output": "2"
},
{
"input": "2\n4 2",
"output": "2"
},
{
"input": "2\n4 3",
"output": "2"
},
{
"input": "4\n2 2 1 1",
"output": "2"
},
{
"input": "4\n3 1 3 1",
"output": "2"
},
{
"input": "4\n1 4 1 4",
"output": "3"
},
{
"input": "4\n2 2 3 3",
"output": "3"
},
{
"input": "4\n2 4 4 2",
"output": "3"
},
{
"input": "4\n3 3 4 4",
"output": "4"
},
{
"input": "3\n1 1 2",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "2"
},
{
"input": "3\n4 1 1",
"output": "2"
},
{
"input": "3\n3 2 2",
"output": "2"
},
{
"input": "3\n2 4 2",
"output": "2"
},
{
"input": "3\n3 4 3",
"output": "3"
},
{
"input": "3\n2 2 1",
"output": "2"
},
{
"input": "3\n1 3 3",
"output": "2"
},
{
"input": "3\n4 4 1",
"output": "3"
},
{
"input": "3\n3 3 2",
"output": "3"
},
{
"input": "3\n4 2 4",
"output": "3"
},
{
"input": "3\n4 3 4",
"output": "3"
},
{
"input": "3\n4 3 2",
"output": "3"
},
{
"input": "3\n3 1 4",
"output": "2"
},
{
"input": "3\n2 1 4",
"output": "2"
},
{
"input": "3\n3 1 2",
"output": "2"
},
{
"input": "4\n4 4 3 2",
"output": "4"
},
{
"input": "4\n1 4 3 1",
"output": "3"
},
{
"input": "4\n2 2 4 1",
"output": "3"
},
{
"input": "4\n3 2 1 2",
"output": "2"
},
{
"input": "5\n2 4 2 3 4",
"output": "4"
},
{
"input": "5\n1 3 4 1 3",
"output": "3"
},
{
"input": "5\n1 1 2 4 2",
"output": "3"
},
{
"input": "5\n1 3 2 3 2",
"output": "3"
},
{
"input": "8\n1 1 2 1 1 1 3 2",
"output": "3"
},
{
"input": "78\n2 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 3 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "39"
},
{
"input": "7\n2 2 2 1 2 1 2",
"output": "3"
},
{
"input": "9\n3 1 2 1 1 1 1 1 1",
"output": "3"
},
{
"input": "10\n3 1 2 2 2 2 2 2 1 2",
"output": "5"
},
{
"input": "18\n1 3 3 3 1 1 3 1 1 1 3 3 3 3 1 3 1 1",
"output": "9"
},
{
"input": "26\n3 1 3 3 1 3 2 3 1 3 3 2 1 2 3 2 2 1 2 1 2 1 1 3 2 1",
"output": "13"
}
] | 1,696,672,999 | 2,147,483,647 | Python 3 | OK | TESTS | 105 | 156 | 3,481,600 | def min_taxis(groups):
counts = [groups.count(i) for i in range(1, 5)]
return counts[3] + counts[2] + (counts[1]*2 + max(0, counts[0] - counts[2]) + 3) // 4
# Пример использования
n = int(input())
groups = list(map(int, input().split()))
result = min_taxis(groups)
print(result)
| Title: Taxi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of groups of schoolchildren. The second line contains a sequence of integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s**i*<=≤<=4). The integers are separated by a space, *s**i* is the number of children in the *i*-th group.
Output Specification:
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
Demo Input:
['5\n1 2 4 3 3\n', '8\n2 3 4 4 2 1 3 1\n']
Demo Output:
['4\n', '5\n']
Note:
In the first test we can sort the children into four cars like this:
- the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly).
There are other ways to sort the groups into four cars. | ```python
def min_taxis(groups):
counts = [groups.count(i) for i in range(1, 5)]
return counts[3] + counts[2] + (counts[1]*2 + max(0, counts[0] - counts[2]) + 3) // 4
# Пример использования
n = int(input())
groups = list(map(int, input().split()))
result = min_taxis(groups)
print(result)
``` | 3 |
|
149 | C | Division into Teams | PROGRAMMING | 1,500 | [
"greedy",
"math",
"sortings"
] | null | null | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are *n* boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic *a**i* (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as *x*, the number of players in the second team as *y*, the individual numbers of boys who play for the first team as *p**i* and the individual numbers of boys who play for the second team as *q**i*. Division *n* boys into two teams is considered fair if three conditions are fulfilled:
- Each boy plays for exactly one team (*x*<=+<=*y*<==<=*n*). - The sizes of teams differ in no more than one (|*x*<=-<=*y*|<=≤<=1). - The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally:
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | The first line contains the only integer *n* (2<=≤<=*n*<=≤<=105) which represents the number of guys in the yard. The next line contains *n* positive space-separated integers, *a**i* (1<=≤<=*a**i*<=≤<=104), the *i*-th number represents the *i*-th boy's playing skills. | On the first line print an integer *x* — the number of boys playing for the first team. On the second line print *x* integers — the individual numbers of boys playing for the first team. On the third line print an integer *y* — the number of boys playing for the second team, on the fourth line print *y* integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: *x*<=+<=*y*<==<=*n*, |*x*<=-<=*y*|<=≤<=1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | [
"3\n1 2 1\n",
"5\n2 3 3 1 1\n"
] | [
"2\n1 2 \n1\n3 \n",
"3\n4 1 3 \n2\n5 2 \n"
] | Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled. | 1,500 | [
{
"input": "3\n1 2 1",
"output": "2\n1 2 \n1\n3 "
},
{
"input": "5\n2 3 3 1 1",
"output": "3\n4 1 3 \n2\n5 2 "
},
{
"input": "10\n2 2 2 2 2 2 2 1 2 2",
"output": "5\n8 2 4 6 9 \n5\n1 3 5 7 10 "
},
{
"input": "10\n2 3 3 1 3 1 1 1 2 2",
"output": "5\n4 7 1 10 3 \n5\n6 8 9 2 5 "
},
{
"input": "10\n2 3 2 3 3 1 1 3 1 1",
"output": "5\n6 9 1 2 5 \n5\n7 10 3 4 8 "
},
{
"input": "11\n1 3 1 2 1 2 2 2 1 1 1",
"output": "6\n1 5 10 4 7 2 \n5\n3 9 11 6 8 "
},
{
"input": "11\n54 83 96 75 33 27 36 35 26 22 77",
"output": "6\n10 6 8 1 11 3 \n5\n9 5 7 4 2 "
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1",
"output": "6\n1 3 5 7 9 11 \n5\n2 4 6 8 10 "
},
{
"input": "2\n1 1",
"output": "1\n1 \n1\n2 "
},
{
"input": "2\n35 36",
"output": "1\n1 \n1\n2 "
},
{
"input": "25\n1 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 1 2 2 2 1 1 2 2 1",
"output": "13\n1 10 17 22 2 5 7 9 13 15 18 20 24 \n12\n4 11 21 25 3 6 8 12 14 16 19 23 "
},
{
"input": "27\n2 1 1 3 1 2 1 1 3 2 3 1 3 2 1 3 2 3 2 1 2 3 2 2 1 2 1",
"output": "14\n2 5 8 15 25 1 10 17 21 24 4 11 16 22 \n13\n3 7 12 20 27 6 14 19 23 26 9 13 18 "
},
{
"input": "30\n2 2 2 3 4 3 4 4 3 2 3 2 2 4 1 4 2 4 2 2 1 4 3 2 1 3 1 1 4 3",
"output": "15\n15 25 28 2 10 13 19 24 6 11 26 5 8 16 22 \n15\n21 27 1 3 12 17 20 4 9 23 30 7 14 18 29 "
},
{
"input": "100\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2",
"output": "50\n14 27 34 63 70 89 94 23 30 44 90 1 13 20 51 59 66 88 97 7 31 53 64 21 38 87 98 11 33 43 49 62 9 18 35 52 73 84 3 45 47 78 86 26 65 4 36 69 79 85 \n50\n17 32 56 68 81 91 12 25 37 80 100 8 15 39 54 61 77 96 2 29 42 55 71 22 76 95 6 24 41 48 60 93 10 28 40 57 74 99 5 46 67 83 19 58 75 16 50 72 82 92 "
},
{
"input": "100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52",
"output": "50\n26 20 68 7 19 89 65 93 14 62 94 3 73 8 12 43 32 18 56 28 59 15 27 96 34 51 55 41 38 48 82 72 63 5 67 47 61 99 64 33 24 80 13 17 4 90 71 74 45 95 \n50\n30 37 97 31 78 23 92 36 50 88 11 52 66 85 10 87 16 81 77 54 42 21 76 2 86 98 100 53 75 70 69 58 60 22 84 57 39 35 25 79 44 1 9 49 6 83 46 29 91 40 "
},
{
"input": "100\n2382 7572 9578 1364 2325 2929 7670 5574 2836 2440 6553 1751 929 8785 6894 9373 9308 7338 6380 9541 9951 6785 8993 9942 5087 7544 6582 7139 8458 7424 9759 8199 9464 8817 7625 6200 4955 9373 9500 3062 849 4210 9337 5466 2190 8150 4971 3145 869 5675 1975 161 1998 378 5229 9000 8958 761 358 434 7636 8295 4406 73 375 812 2473 3652 9067 3052 5287 2850 6987 5442 2625 8894 8733 791 9763 5258 8259 9530 2050 7334 2118 2726 8221 5527 8827 1585 8334 8898 6399 6217 7400 2576 5164 9063 6247 9433",
"output": "50\n64 59 54 58 66 49 4 12 53 85 5 10 96 86 72 70 48 42 37 25 55 71 44 8 36 99 93 27 15 28 18 30 2 61 46 87 62 29 14 89 92 23 98 17 16 100 39 20 31 24 \n50\n52 65 60 78 41 13 90 51 83 45 1 67 75 9 6 40 68 63 47 97 80 74 88 50 94 19 11 22 73 84 95 26 35 7 32 81 91 77 34 76 57 56 69 43 38 33 82 3 79 21 "
},
{
"input": "3\n1 2 3",
"output": "2\n1 3 \n1\n2 "
},
{
"input": "3\n10 10 10",
"output": "2\n1 3 \n1\n2 "
},
{
"input": "3\n5 10 10",
"output": "2\n1 3 \n1\n2 "
},
{
"input": "5\n6 1 1 1 1",
"output": "3\n2 4 1 \n2\n3 5 "
},
{
"input": "5\n1 100 2 200 3",
"output": "3\n1 5 4 \n2\n3 2 "
}
] | 1,669,996,809 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 280 | 9,830,400 | n = int(input())
a = list(map(int,input().split()))
b = list(range(1,n+1))
z = sorted(list(zip(a,b)))
x = []
y = []
sx = 0
sy = 0
for i,j in z:
if sx<=sy:
x.append(j)
sx+=i
else:
y.append(j)
sy+=i
print(len(x))
print(*x)
print(len(y))
print(*y) | Title: Division into Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the game begins. There are *n* boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic *a**i* (the larger it is, the better the boy plays).
Let's denote the number of players in the first team as *x*, the number of players in the second team as *y*, the individual numbers of boys who play for the first team as *p**i* and the individual numbers of boys who play for the second team as *q**i*. Division *n* boys into two teams is considered fair if three conditions are fulfilled:
- Each boy plays for exactly one team (*x*<=+<=*y*<==<=*n*). - The sizes of teams differ in no more than one (|*x*<=-<=*y*|<=≤<=1). - The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally:
Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
Input Specification:
The first line contains the only integer *n* (2<=≤<=*n*<=≤<=105) which represents the number of guys in the yard. The next line contains *n* positive space-separated integers, *a**i* (1<=≤<=*a**i*<=≤<=104), the *i*-th number represents the *i*-th boy's playing skills.
Output Specification:
On the first line print an integer *x* — the number of boys playing for the first team. On the second line print *x* integers — the individual numbers of boys playing for the first team. On the third line print an integer *y* — the number of boys playing for the second team, on the fourth line print *y* integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: *x*<=+<=*y*<==<=*n*, |*x*<=-<=*y*|<=≤<=1, and the condition that limits the total skills.
If there are multiple ways to solve the problem, print any of them.
The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
Demo Input:
['3\n1 2 1\n', '5\n2 3 3 1 1\n']
Demo Output:
['2\n1 2 \n1\n3 \n', '3\n4 1 3 \n2\n5 2 \n']
Note:
Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled. | ```python
n = int(input())
a = list(map(int,input().split()))
b = list(range(1,n+1))
z = sorted(list(zip(a,b)))
x = []
y = []
sx = 0
sy = 0
for i,j in z:
if sx<=sy:
x.append(j)
sx+=i
else:
y.append(j)
sy+=i
print(len(x))
print(*x)
print(len(y))
print(*y)
``` | 3 |
|
886 | A | ACM ICPC | PROGRAMMING | 1,000 | [
"brute force"
] | null | null | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. | The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants | Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | 500 | [
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
"input": "353 313 327 470 597 31",
"output": "NO"
},
{
"input": "835 638 673 624 232 266",
"output": "NO"
},
{
"input": "936 342 19 398 247 874",
"output": "NO"
},
{
"input": "417 666 978 553 271 488",
"output": "NO"
},
{
"input": "71 66 124 199 67 147",
"output": "YES"
},
{
"input": "54 26 0 171 239 12",
"output": "YES"
},
{
"input": "72 8 186 92 267 69",
"output": "YES"
},
{
"input": "180 179 188 50 75 214",
"output": "YES"
},
{
"input": "16 169 110 136 404 277",
"output": "YES"
},
{
"input": "101 400 9 200 300 10",
"output": "YES"
},
{
"input": "101 400 200 9 300 10",
"output": "YES"
},
{
"input": "101 200 400 9 300 10",
"output": "YES"
},
{
"input": "101 400 200 300 9 10",
"output": "YES"
},
{
"input": "101 200 400 300 9 10",
"output": "YES"
},
{
"input": "4 4 4 4 5 4",
"output": "NO"
},
{
"input": "2 2 2 2 2 1",
"output": "NO"
},
{
"input": "1000 1000 999 1000 1000 1000",
"output": "NO"
},
{
"input": "129 1 10 29 8 111",
"output": "NO"
},
{
"input": "1000 1000 1000 999 999 1000",
"output": "YES"
},
{
"input": "101 200 300 400 9 10",
"output": "YES"
},
{
"input": "101 400 200 300 10 9",
"output": "YES"
},
{
"input": "101 200 400 300 10 9",
"output": "YES"
},
{
"input": "101 200 300 400 10 9",
"output": "YES"
},
{
"input": "101 200 300 10 400 9",
"output": "YES"
},
{
"input": "1 1 1 1 1 5",
"output": "NO"
},
{
"input": "8 1 1 3 3 0",
"output": "NO"
},
{
"input": "1 1 2 2 3 3",
"output": "YES"
},
{
"input": "1 2 2 5 2 5",
"output": "NO"
},
{
"input": "1 2 3 6 6 6",
"output": "NO"
},
{
"input": "36 91 7 86 51 89",
"output": "NO"
},
{
"input": "10 1 1 1 23 24",
"output": "NO"
},
{
"input": "1 1 1 10 23 24",
"output": "NO"
},
{
"input": "20 10 1 2 3 44",
"output": "NO"
},
{
"input": "7 0 14 11 8 6",
"output": "NO"
},
{
"input": "100 496 1 1 1 1",
"output": "NO"
},
{
"input": "5 4 2 5 11 3",
"output": "NO"
},
{
"input": "1 3 7 8 8 9",
"output": "YES"
},
{
"input": "1 3 4 5 18 19",
"output": "YES"
},
{
"input": "5 5 1 2 2 15",
"output": "NO"
},
{
"input": "2 1 0 0 0 5",
"output": "NO"
},
{
"input": "1 6 6 1 20 2",
"output": "NO"
},
{
"input": "2 10 0 0 0 0",
"output": "NO"
},
{
"input": "1 1 3 1 1 11",
"output": "NO"
},
{
"input": "10 10 1 1 1 37",
"output": "NO"
},
{
"input": "1 1 0 0 0 4",
"output": "NO"
},
{
"input": "1 1 10 1 1 28",
"output": "NO"
},
{
"input": "1 5 5 5 6 8",
"output": "YES"
},
{
"input": "0 2 3 4 4 5",
"output": "YES"
}
] | 1,510,507,584 | 4,884 | Python 3 | COMPILATION_ERROR | PRETESTS | 0 | 0 | 0 | #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int i,n,s=0,maxm=0,j;
vector<int> a(6);
for (i=0;i<6;i++) {
cin >> a[i];
if (maxm < a[i])
maxm = a[i];
s += a[i];
}
if (s % 2 == 1) {
cout << "NO";
return 0;
}
s /= 2;
for (i=1;i<6;i++)
for (j=i+1;j<6;j++)
if (s - a[0] - a[i] == a[j]) {
cout << "YES";
return 0;
}
cout << "NO";
return 0;
}
| Title: ACM ICPC
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
Input Specification:
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
Output Specification:
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
Demo Input:
['1 3 2 1 2 1\n', '1 1 1 1 1 99\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | ```python
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int i,n,s=0,maxm=0,j;
vector<int> a(6);
for (i=0;i<6;i++) {
cin >> a[i];
if (maxm < a[i])
maxm = a[i];
s += a[i];
}
if (s % 2 == 1) {
cout << "NO";
return 0;
}
s /= 2;
for (i=1;i<6;i++)
for (j=i+1;j<6;j++)
if (s - a[0] - a[i] == a[j]) {
cout << "YES";
return 0;
}
cout << "NO";
return 0;
}
``` | -1 |
|
54 | A | Presents | PROGRAMMING | 1,300 | [
"implementation"
] | A. Presents | 2 | 256 | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.
Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?
In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following *N* days. Besides, he is guided by the principle:
- on each holiday day the Hedgehog will necessarily receive a present, - he receives presents at least every *K* days (i.e., if he received a present on the *i*-th day, he will receive the next present no later than on the *i*<=+<=*K*-th day).
For the given *N* and *K*, as well as the list of holidays among the following *N* days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). | The first line contains integers *N* and *K* (1<=≤<=*N*<=≤<=365, 1<=≤<=*K*<=≤<=*N*).
The second line contains a number *C* which represents the number of holidays (0<=≤<=*C*<=≤<=*N*). Then in the same line follow *C* numbers ranging from 1 to *N* which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. | Print a single number — the minimal number of presents the Hedgehog will receive over the following *N* days. | [
"5 2\n1 3\n",
"10 1\n3 6 7 8\n"
] | [
"3",
"10"
] | none | 500 | [
{
"input": "5 2\n1 3",
"output": "3"
},
{
"input": "10 1\n3 6 7 8",
"output": "10"
},
{
"input": "5 5\n1 3",
"output": "1"
},
{
"input": "10 3\n3 3 6 9",
"output": "3"
},
{
"input": "5 2\n0",
"output": "2"
},
{
"input": "1 1\n0",
"output": "1"
},
{
"input": "5 1\n0",
"output": "5"
},
{
"input": "5 1\n1 2",
"output": "5"
},
{
"input": "5 2\n0",
"output": "2"
},
{
"input": "10 3\n2 4 8",
"output": "4"
},
{
"input": "10 1\n0",
"output": "10"
},
{
"input": "10 2\n1 5",
"output": "5"
},
{
"input": "10 1\n0",
"output": "10"
},
{
"input": "10 1\n0",
"output": "10"
},
{
"input": "15 5\n0",
"output": "3"
},
{
"input": "15 1\n1 3",
"output": "15"
},
{
"input": "15 2\n1 10",
"output": "7"
},
{
"input": "15 1\n0",
"output": "15"
},
{
"input": "15 3\n1 11",
"output": "5"
},
{
"input": "20 1\n3 7 9 20",
"output": "20"
},
{
"input": "20 3\n1 11",
"output": "7"
},
{
"input": "20 2\n6 6 9 10 15 19 20",
"output": "12"
},
{
"input": "20 1\n0",
"output": "20"
},
{
"input": "20 1\n1 13",
"output": "20"
},
{
"input": "25 1\n9 2 6 8 10 14 15 17 18 23",
"output": "25"
},
{
"input": "25 1\n0",
"output": "25"
},
{
"input": "25 1\n4 8 10 13 24",
"output": "25"
},
{
"input": "25 1\n1 14",
"output": "25"
},
{
"input": "25 1\n0",
"output": "25"
},
{
"input": "100 3\n0",
"output": "33"
},
{
"input": "100 10\n0",
"output": "10"
},
{
"input": "100 23\n22 2 9 18 22 23 30 44 50 55 58 61 70 71 73 76 79 82 85 88 94 95 99",
"output": "22"
},
{
"input": "100 5\n10 2 17 21 34 52 58 60 64 68 95",
"output": "24"
},
{
"input": "100 4\n2 29 63",
"output": "26"
},
{
"input": "150 16\n9 19 31 47 53 57 96 105 108 120",
"output": "13"
},
{
"input": "150 52\n5 11 37 60 67 86",
"output": "6"
},
{
"input": "150 4\n7 21 54 106 108 109 119 123",
"output": "40"
},
{
"input": "150 3\n0",
"output": "50"
},
{
"input": "150 21\n21 22 26 30 36 39 52 59 62 66 68 78 86 92 96 103 108 113 118 119 125 139",
"output": "22"
},
{
"input": "300 15\n14 3 38 52 57 142 157 175 201 209 238 258 288 294 299",
"output": "26"
},
{
"input": "300 2\n14 29 94 122 123 158 160 164 191 200 202 208 246 272 286",
"output": "153"
},
{
"input": "300 5\n16 22 38 72 78 108 116 140 147 160 189 209 214 227 252 294 300",
"output": "66"
},
{
"input": "300 8\n4 27 76 155 260",
"output": "40"
},
{
"input": "300 24\n20 18 76 80 81 85 103 110 112 129 145 151 172 180 184 201 205 241 257 268 276",
"output": "24"
},
{
"input": "350 22\n11 38 111 115 176 194 204 207 231 274 307 348",
"output": "21"
},
{
"input": "350 22\n73 1 4 8 10 14 16 19 28 37 41 42 43 55 56 64 66 67 79 80 84 87 96 99 101 103 119 120 121 122 127 128 135 141 142 143 148 156 159 160 161 166 167 169 173 189 201 202 205 219 223 227 233 242 243 244 250 257 260 262 263 264 273 291 301 302 305 306 307 314 326 336 342 345",
"output": "73"
},
{
"input": "350 26\n10 13 16 81 99 144 191 223 258 316 329",
"output": "18"
},
{
"input": "350 16\n12 31 76 103 116 191 201 241 256 260 291 306 336",
"output": "24"
},
{
"input": "350 28\n5 23 104 135 305 331",
"output": "14"
},
{
"input": "365 34\n6 80 94 208 256 325 349",
"output": "14"
},
{
"input": "365 19\n7 47 114 139 210 226 266 279",
"output": "22"
},
{
"input": "365 8\n32 1 13 22 25 33 72 80 86 96 117 132 145 146 156 176 177 179 188 198 203 218 225 235 253 256 267 279 286 294 303 333 363",
"output": "61"
},
{
"input": "365 8\n55 3 12 26 28 36 45 47 59 61 65 82 90 103 109 114 117 121 123 126 134 142 144 146 151 154 168 175 189 193 195 197 199 210 212 214 230 232 241 248 254 267 271 291 304 306 308 311 315 317 318 334 335 346 354 365",
"output": "74"
},
{
"input": "365 2\n2 96 241",
"output": "183"
},
{
"input": "365 42\n10 8 66 77 148 161 183 231 301 340 350",
"output": "14"
},
{
"input": "365 40\n30 1 14 21 31 32 36 56 59 68 96 119 131 137 166 179 181 202 235 248 272 294 309 315 322 327 334 341 347 362 365",
"output": "30"
},
{
"input": "365 31\n19 13 18 27 33 46 58 86 114 178 187 198 228 233 240 255 277 332 348 351",
"output": "22"
},
{
"input": "365 54\n21 28 42 56 65 66 67 76 81 85 89 123 132 136 153 195 215 249 294 296 300 355",
"output": "22"
},
{
"input": "365 5\n5 10 31 121 235 322",
"output": "74"
},
{
"input": "365 81\n2 1 75",
"output": "5"
},
{
"input": "365 21\n4 1 17 344 345",
"output": "19"
},
{
"input": "11 2\n5 3 6 7 9 10",
"output": "7"
},
{
"input": "5 3\n2 2 4",
"output": "2"
},
{
"input": "362 360\n0",
"output": "1"
},
{
"input": "18 4\n4 1 9 10 18",
"output": "6"
}
] | 1,678,450,793 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n, k = map(int, input().split(" "))
days = [0] + list(map(int, input().split(" ")))
count = 1
answer = 0
for i in days:
if(not count):
answer += i
count = (count+1)%(k+1)
print(answer)
| Title: Presents
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Hedgehog likes to give presents to his friend, but no less he likes to receive them.
Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?
In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following *N* days. Besides, he is guided by the principle:
- on each holiday day the Hedgehog will necessarily receive a present, - he receives presents at least every *K* days (i.e., if he received a present on the *i*-th day, he will receive the next present no later than on the *i*<=+<=*K*-th day).
For the given *N* and *K*, as well as the list of holidays among the following *N* days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer).
Input Specification:
The first line contains integers *N* and *K* (1<=≤<=*N*<=≤<=365, 1<=≤<=*K*<=≤<=*N*).
The second line contains a number *C* which represents the number of holidays (0<=≤<=*C*<=≤<=*N*). Then in the same line follow *C* numbers ranging from 1 to *N* which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them.
Output Specification:
Print a single number — the minimal number of presents the Hedgehog will receive over the following *N* days.
Demo Input:
['5 2\n1 3\n', '10 1\n3 6 7 8\n']
Demo Output:
['3', '10']
Note:
none | ```python
n, k = map(int, input().split(" "))
days = [0] + list(map(int, input().split(" ")))
count = 1
answer = 0
for i in days:
if(not count):
answer += i
count = (count+1)%(k+1)
print(answer)
``` | 0 |
799 | A | Carrot Cakes | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.
Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable. | The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. | If it is reasonable to build the second oven, print "YES". Otherwise print "NO". | [
"8 6 4 5\n",
"8 6 4 6\n",
"10 3 11 4\n",
"4 2 1 4\n"
] | [
"YES\n",
"NO\n",
"NO\n",
"YES\n"
] | In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.
In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven. | 500 | [
{
"input": "8 6 4 5",
"output": "YES"
},
{
"input": "8 6 4 6",
"output": "NO"
},
{
"input": "10 3 11 4",
"output": "NO"
},
{
"input": "4 2 1 4",
"output": "YES"
},
{
"input": "28 17 16 26",
"output": "NO"
},
{
"input": "60 69 9 438",
"output": "NO"
},
{
"input": "599 97 54 992",
"output": "YES"
},
{
"input": "11 22 18 17",
"output": "NO"
},
{
"input": "1 13 22 11",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "NO"
},
{
"input": "3 1 1 1",
"output": "YES"
},
{
"input": "1000 1000 1000 1000",
"output": "NO"
},
{
"input": "1000 1000 1 1",
"output": "YES"
},
{
"input": "1000 1000 1 400",
"output": "YES"
},
{
"input": "1000 1000 1 1000",
"output": "YES"
},
{
"input": "1000 1000 1 999",
"output": "YES"
},
{
"input": "53 11 3 166",
"output": "YES"
},
{
"input": "313 2 3 385",
"output": "NO"
},
{
"input": "214 9 9 412",
"output": "NO"
},
{
"input": "349 9 5 268",
"output": "YES"
},
{
"input": "611 16 8 153",
"output": "YES"
},
{
"input": "877 13 3 191",
"output": "YES"
},
{
"input": "340 9 9 10",
"output": "YES"
},
{
"input": "31 8 2 205",
"output": "NO"
},
{
"input": "519 3 2 148",
"output": "YES"
},
{
"input": "882 2 21 219",
"output": "NO"
},
{
"input": "982 13 5 198",
"output": "YES"
},
{
"input": "428 13 6 272",
"output": "YES"
},
{
"input": "436 16 14 26",
"output": "YES"
},
{
"input": "628 10 9 386",
"output": "YES"
},
{
"input": "77 33 18 31",
"output": "YES"
},
{
"input": "527 36 4 8",
"output": "YES"
},
{
"input": "128 18 2 169",
"output": "YES"
},
{
"input": "904 4 2 288",
"output": "YES"
},
{
"input": "986 4 3 25",
"output": "YES"
},
{
"input": "134 8 22 162",
"output": "NO"
},
{
"input": "942 42 3 69",
"output": "YES"
},
{
"input": "894 4 9 4",
"output": "YES"
},
{
"input": "953 8 10 312",
"output": "YES"
},
{
"input": "43 8 1 121",
"output": "YES"
},
{
"input": "12 13 19 273",
"output": "NO"
},
{
"input": "204 45 10 871",
"output": "YES"
},
{
"input": "342 69 50 425",
"output": "NO"
},
{
"input": "982 93 99 875",
"output": "NO"
},
{
"input": "283 21 39 132",
"output": "YES"
},
{
"input": "1000 45 83 686",
"output": "NO"
},
{
"input": "246 69 36 432",
"output": "NO"
},
{
"input": "607 93 76 689",
"output": "NO"
},
{
"input": "503 21 24 435",
"output": "NO"
},
{
"input": "1000 45 65 989",
"output": "NO"
},
{
"input": "30 21 2 250",
"output": "YES"
},
{
"input": "1000 49 50 995",
"output": "NO"
},
{
"input": "383 69 95 253",
"output": "YES"
},
{
"input": "393 98 35 999",
"output": "YES"
},
{
"input": "1000 22 79 552",
"output": "NO"
},
{
"input": "268 294 268 154",
"output": "NO"
},
{
"input": "963 465 706 146",
"output": "YES"
},
{
"input": "304 635 304 257",
"output": "NO"
},
{
"input": "4 2 1 6",
"output": "NO"
},
{
"input": "1 51 10 50",
"output": "NO"
},
{
"input": "5 5 4 4",
"output": "YES"
},
{
"input": "3 2 1 1",
"output": "YES"
},
{
"input": "3 4 3 3",
"output": "NO"
},
{
"input": "7 3 4 1",
"output": "YES"
},
{
"input": "101 10 1 1000",
"output": "NO"
},
{
"input": "5 1 1 1",
"output": "YES"
},
{
"input": "5 10 5 5",
"output": "NO"
},
{
"input": "19 1 7 1",
"output": "YES"
},
{
"input": "763 572 745 262",
"output": "YES"
},
{
"input": "1 2 1 1",
"output": "NO"
},
{
"input": "5 1 1 3",
"output": "YES"
},
{
"input": "170 725 479 359",
"output": "NO"
},
{
"input": "6 2 1 7",
"output": "YES"
},
{
"input": "6 2 5 1",
"output": "YES"
},
{
"input": "1 2 2 1",
"output": "NO"
},
{
"input": "24 2 8 3",
"output": "YES"
},
{
"input": "7 3 3 3",
"output": "YES"
},
{
"input": "5 2 2 2",
"output": "YES"
},
{
"input": "3 2 1 2",
"output": "YES"
},
{
"input": "1000 2 200 8",
"output": "NO"
},
{
"input": "3 100 2 100",
"output": "NO"
},
{
"input": "2 999 1 1000",
"output": "NO"
},
{
"input": "2 1 1 1",
"output": "NO"
},
{
"input": "2 3 5 1",
"output": "NO"
},
{
"input": "100 1 5 1",
"output": "YES"
},
{
"input": "7 2 3 3",
"output": "YES"
},
{
"input": "4 1 1 3",
"output": "NO"
},
{
"input": "3 2 2 1",
"output": "YES"
},
{
"input": "1 1 1 2",
"output": "NO"
},
{
"input": "91 8 7 13",
"output": "YES"
},
{
"input": "3 1 2 1",
"output": "NO"
},
{
"input": "5 3 2 3",
"output": "YES"
},
{
"input": "9 6 6 3",
"output": "YES"
}
] | 1,601,927,622 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | n,t,k,d=map(int,input().split())
a=d
ans1=0
while ans1<=n:
a=a+t
ans1=ans1+2*k
ans2=0
b=0
while ans2<=n:
b=b+t
ans2=ans2+k
if a<b:
print("YES")
else:
print("NO") | Title: Carrot Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.
Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.
Input Specification:
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
Output Specification:
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
Demo Input:
['8 6 4 5\n', '8 6 4 6\n', '10 3 11 4\n', '4 2 1 4\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n', 'YES\n']
Note:
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.
In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven. | ```python
n,t,k,d=map(int,input().split())
a=d
ans1=0
while ans1<=n:
a=a+t
ans1=ans1+2*k
ans2=0
b=0
while ans2<=n:
b=b+t
ans2=ans2+k
if a<b:
print("YES")
else:
print("NO")
``` | 0 |
|
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she can spend it on reading.
Help Luba to determine the minimum number of day when she finishes reading.
It is guaranteed that the answer doesn't exceed *n*.
Remember that there are 86400 seconds in a day. | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "12"
},
{
"input": "1 1\n86399",
"output": "1"
},
{
"input": "6 1200\n86400 86400 86000 86000 86000 86400",
"output": "5"
},
{
"input": "6 1200\n86400 86400 86000 86000 86001 86399",
"output": "6"
},
{
"input": "4 172799\n1 1 86400 0",
"output": "4"
},
{
"input": "4 172799\n0 86400 86399 0",
"output": "4"
},
{
"input": "6 1\n1 1 86400 1 86399 1",
"output": "1"
},
{
"input": "4 1\n86400 86399 86400 86400",
"output": "2"
},
{
"input": "4 1\n86400 86400 0 86400",
"output": "3"
}
] | 1,568,045,649 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 0 | td,time=map(int,input().split())
ts=list(map(int,input().split()))
k=86400
sub=0
f=0
for i in range(td):
sub=k-ts[i]
f=f+1
if time==sub:
break
print(f)
| Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she can spend it on reading.
Help Luba to determine the minimum number of day when she finishes reading.
It is guaranteed that the answer doesn't exceed *n*.
Remember that there are 86400 seconds in a day.
Input Specification:
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day.
Output Specification:
Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*.
Demo Input:
['2 2\n86400 86398\n', '2 86400\n0 86400\n']
Demo Output:
['2\n', '1\n']
Note:
none | ```python
td,time=map(int,input().split())
ts=list(map(int,input().split()))
k=86400
sub=0
f=0
for i in range(td):
sub=k-ts[i]
f=f+1
if time==sub:
break
print(f)
``` | 0 |
|
471 | D | MUH and Cube Walls | PROGRAMMING | 1,800 | [
"string suffix structures",
"strings"
] | null | null | Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got hold of lots of wooden cubes somewhere. They started making cube towers by placing the cubes one on top of the other. They defined multiple towers standing in a line as a wall. A wall can consist of towers of different heights.
Horace was the first to finish making his wall. He called his wall an elephant. The wall consists of *w* towers. The bears also finished making their wall but they didn't give it a name. Their wall consists of *n* towers. Horace looked at the bears' tower and wondered: in how many parts of the wall can he "see an elephant"? He can "see an elephant" on a segment of *w* contiguous towers if the heights of the towers on the segment match as a sequence the heights of the towers in Horace's wall. In order to see as many elephants as possible, Horace can raise and lower his wall. He even can lower the wall below the ground level (see the pictures to the samples for clarification).
Your task is to count the number of segments where Horace can "see an elephant". | The first line contains two integers *n* and *w* (1<=≤<=*n*,<=*w*<=≤<=2·105) — the number of towers in the bears' and the elephant's walls correspondingly. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the heights of the towers in the bears' wall. The third line contains *w* integers *b**i* (1<=≤<=*b**i*<=≤<=109) — the heights of the towers in the elephant's wall. | Print the number of segments in the bears' wall where Horace can "see an elephant". | [
"13 5\n2 4 5 5 4 3 2 2 2 3 3 2 1\n3 4 4 3 2\n"
] | [
"2"
] | The picture to the left shows Horace's wall from the sample, the picture to the right shows the bears' wall. The segments where Horace can "see an elephant" are in gray. | 2,000 | [
{
"input": "13 5\n2 4 5 5 4 3 2 2 2 3 3 2 1\n3 4 4 3 2",
"output": "2"
},
{
"input": "5 1\n8 71 1 24 2\n31",
"output": "5"
},
{
"input": "6 3\n2 2 2 2 2 2\n5 5 5",
"output": "4"
},
{
"input": "1 1\n576560149\n691846236",
"output": "1"
},
{
"input": "10 5\n5 10 8 10 11 9 11 12 10 15\n4 2 4 5 3",
"output": "2"
},
{
"input": "10 10\n6 8 1 2 5 1 4 24 2 4\n6 8 1 2 5 1 4 24 2 4",
"output": "1"
},
{
"input": "10 10\n6 8 1 2 5 1 14 24 12 4\n7 9 2 3 6 2 15 25 13 5",
"output": "1"
},
{
"input": "8 4\n1 2 3 4 5 6 7 8\n10 11 12 13",
"output": "5"
},
{
"input": "10 5\n172960147 951061917 502625539 319177159 720665763 402410416 880790711 734191412 452846733 449904402\n640219326 792464591 173792179 691347674 125427306",
"output": "0"
},
{
"input": "10 3\n2 3 3 2 1 1 3 1 3 1\n2 1 2",
"output": "0"
},
{
"input": "10 5\n260725416 260725506 260725422 260725512 260725428 260725518 260725434 260725524 260725440 260725530\n925033135 925033225 925033141 925033231 925033147",
"output": "3"
},
{
"input": "2 2\n1000000000 10\n1 20",
"output": "0"
},
{
"input": "7 3\n1 1 1 1 1 1 1\n1000 1256 1512",
"output": "0"
},
{
"input": "3 3\n1 132 3\n2 1 3",
"output": "0"
},
{
"input": "53 3\n1 3 4 4 5 7 10 14 19 25 32 40 49 59 70 82 95 109 124 140 157 175 194 214 235 257 280 304 329 355 382 410 439 469 500 532 565 599 634 670 707 745 784 824 865 907 950 994 1039 1085 1132 1180 1229\n1 2 40",
"output": "0"
}
] | 1,696,622,947 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | def count_elephant_segments(n, w, bear_wall, elephant_wall):
# Calcula um valor de hash para a parede do elefante
elephant_hash = hash(elephant_wall)
# Calcula um valor de hash para a janela inicial na parede dos ursos
bear_hash = hash(bear_wall[:w])
count = 0
# Percorre a parede dos ursos com a janela deslizante
for i in range(n - w + 1):
if i > 0:
# Atualiza o valor de hash da janela deslizante
bear_hash = bear_hash * 101 + bear_wall[i + w - 1] - bear_wall[i - 1] * 101 ** w
if bear_hash == elephant_hash:
count += 1
return count
# Leitura da entrada
n, w = map(int, input().split())
bear_wall = list(map(int, input().split()))
elephant_wall = list(map(int, input().split()))
# Chama a função para contar os segmentos onde Horace pode "ver um elefante"
result = count_elephant_segments(n, w, bear_wall, elephant_wall)
print(result)
| Title: MUH and Cube Walls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got hold of lots of wooden cubes somewhere. They started making cube towers by placing the cubes one on top of the other. They defined multiple towers standing in a line as a wall. A wall can consist of towers of different heights.
Horace was the first to finish making his wall. He called his wall an elephant. The wall consists of *w* towers. The bears also finished making their wall but they didn't give it a name. Their wall consists of *n* towers. Horace looked at the bears' tower and wondered: in how many parts of the wall can he "see an elephant"? He can "see an elephant" on a segment of *w* contiguous towers if the heights of the towers on the segment match as a sequence the heights of the towers in Horace's wall. In order to see as many elephants as possible, Horace can raise and lower his wall. He even can lower the wall below the ground level (see the pictures to the samples for clarification).
Your task is to count the number of segments where Horace can "see an elephant".
Input Specification:
The first line contains two integers *n* and *w* (1<=≤<=*n*,<=*w*<=≤<=2·105) — the number of towers in the bears' and the elephant's walls correspondingly. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the heights of the towers in the bears' wall. The third line contains *w* integers *b**i* (1<=≤<=*b**i*<=≤<=109) — the heights of the towers in the elephant's wall.
Output Specification:
Print the number of segments in the bears' wall where Horace can "see an elephant".
Demo Input:
['13 5\n2 4 5 5 4 3 2 2 2 3 3 2 1\n3 4 4 3 2\n']
Demo Output:
['2']
Note:
The picture to the left shows Horace's wall from the sample, the picture to the right shows the bears' wall. The segments where Horace can "see an elephant" are in gray. | ```python
def count_elephant_segments(n, w, bear_wall, elephant_wall):
# Calcula um valor de hash para a parede do elefante
elephant_hash = hash(elephant_wall)
# Calcula um valor de hash para a janela inicial na parede dos ursos
bear_hash = hash(bear_wall[:w])
count = 0
# Percorre a parede dos ursos com a janela deslizante
for i in range(n - w + 1):
if i > 0:
# Atualiza o valor de hash da janela deslizante
bear_hash = bear_hash * 101 + bear_wall[i + w - 1] - bear_wall[i - 1] * 101 ** w
if bear_hash == elephant_hash:
count += 1
return count
# Leitura da entrada
n, w = map(int, input().split())
bear_wall = list(map(int, input().split()))
elephant_wall = list(map(int, input().split()))
# Chama a função para contar os segmentos onde Horace pode "ver um elefante"
result = count_elephant_segments(n, w, bear_wall, elephant_wall)
print(result)
``` | -1 |
|
11 | A | Increasing Sequence | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation",
"math"
] | A. Increasing Sequence | 1 | 64 | A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing? | The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). | Output the minimal number of moves needed to make the sequence increasing. | [
"4 2\n1 3 3 2\n"
] | [
"3\n"
] | none | 0 | [
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
{
"input": "2 7\n1 1",
"output": "1"
},
{
"input": "3 3\n18 1 9",
"output": "10"
},
{
"input": "3 3\n15 17 9",
"output": "3"
},
{
"input": "3 3\n10 9 12",
"output": "2"
},
{
"input": "10 3\n2 1 17 10 5 16 8 4 15 17",
"output": "31"
},
{
"input": "10 3\n6 11 4 12 22 15 23 26 24 26",
"output": "13"
},
{
"input": "10 3\n10 24 13 15 18 14 15 26 33 35",
"output": "29"
},
{
"input": "100 3\n529 178 280 403 326 531 671 427 188 866 669 646 421 804 494 609 53 1012 211 243 887 833 900 543 226 42 859 718 454 372 971 692 846 770 511 395 499 479 641 756 115 269 206 45 1039 727 400 779 859 614 146 214 196 919 702 959 380 830 535 878 859 784 316 305 782 924 536 243 236 978 564 150 291 877 808 983 537 839 490 120 168 838 267 650 900 170 211 504 326 771 895 984 994 483 776 100 471 1078 317 580",
"output": "15717"
},
{
"input": "100 3\n329 226 331 909 962 112 837 1005 194 818 506 416 125 648 367 459 400 582 989 547 329 438 234 121 272 226 821 376 834 427 718 164 834 113 654 177 737 212 169 696 744 180 89 944 233 147 667 990 809 1072 1085 1093 814 265 1067 312 833 572 303 901 1032 504 185 817 389 158 613 723 239 269 911 352 769 404 225 822 897 606 947 323 913 804 923 1084 552 901 486 249 209 898 847 610 728 1122 986 669 1116 1076 367 327",
"output": "16133"
}
] | 1,688,958,726 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 92 | 0 | n, d = map(int, input().split())
nums = list(map(int, input().split()))
count = 0
for i in range(1, n):
if nums[i] <= nums[i-1]:
count += (nums[i-1] - nums[i]) // d + 1
nums[i] += count * d
print(count)
| Title: Increasing Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing?
Input Specification:
The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106).
Output Specification:
Output the minimal number of moves needed to make the sequence increasing.
Demo Input:
['4 2\n1 3 3 2\n']
Demo Output:
['3\n']
Note:
none | ```python
n, d = map(int, input().split())
nums = list(map(int, input().split()))
count = 0
for i in range(1, n):
if nums[i] <= nums[i-1]:
count += (nums[i-1] - nums[i]) // d + 1
nums[i] += count * d
print(count)
``` | 0 |
436 | A | Feed with Candy | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem.
One day, Om Nom visited his friend Evan. Evan has *n* candies of two types (fruit drops and caramel drops), the *i*-th candy hangs at the height of *h**i* centimeters above the floor of the house, its mass is *m**i*. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most *x* centimeter high jumps. When Om Nom eats a candy of mass *y*, he gets stronger and the height of his jump increases by *y* centimeters.
What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | The first line contains two integers, *n* and *x* (1<=≤<=*n*,<=*x*<=≤<=2000) — the number of sweets Evan has and the initial height of Om Nom's jump.
Each of the following *n* lines contains three integers *t**i*,<=*h**i*,<=*m**i* (0<=≤<=*t**i*<=≤<=1; 1<=≤<=*h**i*,<=*m**i*<=≤<=2000) — the type, height and the mass of the *i*-th candy. If number *t**i* equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | Print a single integer — the maximum number of candies Om Nom can eat. | [
"5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5\n"
] | [
"4\n"
] | One of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario:
1. Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. 1. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. 1. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. 1. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | 1,000 | [
{
"input": "5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5",
"output": "4"
},
{
"input": "5 2\n1 15 2\n1 11 2\n0 17 2\n0 16 1\n1 18 2",
"output": "0"
},
{
"input": "6 2\n1 17 3\n1 6 1\n0 4 2\n1 10 1\n1 7 3\n1 5 1",
"output": "0"
},
{
"input": "7 2\n1 14 1\n1 9 2\n0 6 3\n0 20 2\n0 4 2\n0 3 1\n0 9 2",
"output": "0"
},
{
"input": "8 2\n0 20 3\n1 5 2\n1 4 1\n1 7 1\n0 1 3\n1 5 3\n1 7 2\n1 3 1",
"output": "2"
},
{
"input": "9 2\n0 1 1\n1 8 2\n1 11 1\n0 9 1\n1 18 2\n1 7 3\n1 8 3\n0 16 1\n0 12 2",
"output": "1"
},
{
"input": "10 2\n0 2 3\n1 5 2\n0 7 3\n1 15 2\n0 14 3\n1 19 1\n1 5 3\n0 2 2\n0 10 2\n0 10 3",
"output": "9"
},
{
"input": "2 1\n0 1 1\n1 2 1",
"output": "2"
},
{
"input": "2 1\n1 1 1\n0 2 1",
"output": "2"
},
{
"input": "2 1\n0 1 1\n0 2 1",
"output": "1"
},
{
"input": "2 1\n1 1 1\n1 2 1",
"output": "1"
},
{
"input": "2 1\n0 1 1\n1 3 1",
"output": "1"
},
{
"input": "2 1\n1 1 1\n0 3 1",
"output": "1"
},
{
"input": "1 1\n1 2 1",
"output": "0"
},
{
"input": "3 4\n1 1 2\n1 4 100\n0 104 1",
"output": "3"
},
{
"input": "3 4\n1 1 100\n1 4 2\n0 104 1",
"output": "3"
},
{
"input": "3 100\n0 1 1\n1 1 1\n1 1 1",
"output": "3"
},
{
"input": "4 20\n0 10 10\n0 20 50\n1 40 1\n1 40 1",
"output": "4"
},
{
"input": "4 2\n0 1 1\n0 2 3\n1 4 1\n1 5 1",
"output": "4"
},
{
"input": "3 10\n0 9 1\n0 10 10\n1 20 1",
"output": "3"
},
{
"input": "3 5\n0 4 1\n0 5 10\n1 15 5",
"output": "3"
},
{
"input": "3 4\n0 2 1\n0 3 3\n1 6 5",
"output": "3"
},
{
"input": "3 3\n0 1 1\n0 2 100\n1 10 1",
"output": "3"
},
{
"input": "3 2\n0 1 1\n0 2 2\n1 4 4",
"output": "3"
},
{
"input": "5 3\n0 1 5\n0 1 5\n0 1 5\n1 1 10\n1 1 1",
"output": "5"
},
{
"input": "3 2\n0 1 1\n0 2 2\n1 4 2",
"output": "3"
},
{
"input": "4 10\n0 20 1\n1 1 9\n1 2 11\n1 3 8",
"output": "3"
},
{
"input": "7 1\n0 1 99\n1 100 1\n0 100 1\n0 101 1000\n1 1000 1\n0 1000 1\n1 1000 1",
"output": "7"
},
{
"input": "4 3\n0 1 1\n0 2 100\n0 3 1\n1 100 1",
"output": "3"
},
{
"input": "3 3\n0 1 100\n0 2 1\n1 100 100",
"output": "3"
},
{
"input": "3 2\n0 1 1\n0 2 100\n1 10 1",
"output": "3"
},
{
"input": "3 1\n0 1 1\n1 1 5\n0 7 1",
"output": "3"
},
{
"input": "3 5\n0 2 3\n1 9 10\n0 4 4",
"output": "3"
},
{
"input": "3 3\n0 2 1\n0 3 2\n1 5 10",
"output": "3"
}
] | 1,426,598,581 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 545 | 819,200 | from copy import deepcopy
def getBetter(h, a):
maxi = -1
im = -1
for i in range(len(a)):
if (h >= a[i][0]):
if (maxi < a[i][1]):
im = i
maxi = a[i][1]
return(im, maxi)
n, h0 = map(int, input().split())
lolipops0 = [[], []]
for i in range(n):
t, h, m = map(int, input().split())
lolipops0[t].append((h, m))
lolipops0[1].sort()
lolipops0[0].sort()
lolipops1 = deepcopy(lolipops0)
lol0 = getBetter(h0, lolipops0[0])
t1 = 0
h1 = h0
lol1 = getBetter(h0, lolipops0[1])
t2 = 1 # ---- WARNING --------
h2 = h0
while(lol0[0] >= 0 or lol1[0] >=0):
if (lol0[0] > -1):
if (len(lolipops0[t1 % 2]) != 1 and lol0[0] != -1):
lolipops0[t1 % 2].pop(lol0[0])
else:
lolipops0[t1 % 2] = []
t1 += 1
h1 += lol0[1]
lol0 = getBetter(h1, lolipops0[t1 % 2])
if (lol1[0] > -1):
if (len(lolipops1[t2 % 2]) != 1 and lol1[0] != -1):
lolipops1[t2 % 2].pop(lol1[0])
else:
lolipops1[t2 % 2] = []
t2 += 1
h2 += lol1[1]
lol1 = getBetter(h2, lolipops1[t2 % 2])
print(max(t1, t2 - 1)) | Title: Feed with Candy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem.
One day, Om Nom visited his friend Evan. Evan has *n* candies of two types (fruit drops and caramel drops), the *i*-th candy hangs at the height of *h**i* centimeters above the floor of the house, its mass is *m**i*. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most *x* centimeter high jumps. When Om Nom eats a candy of mass *y*, he gets stronger and the height of his jump increases by *y* centimeters.
What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)?
Input Specification:
The first line contains two integers, *n* and *x* (1<=≤<=*n*,<=*x*<=≤<=2000) — the number of sweets Evan has and the initial height of Om Nom's jump.
Each of the following *n* lines contains three integers *t**i*,<=*h**i*,<=*m**i* (0<=≤<=*t**i*<=≤<=1; 1<=≤<=*h**i*,<=*m**i*<=≤<=2000) — the type, height and the mass of the *i*-th candy. If number *t**i* equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop.
Output Specification:
Print a single integer — the maximum number of candies Om Nom can eat.
Demo Input:
['5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5\n']
Demo Output:
['4\n']
Note:
One of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario:
1. Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. 1. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. 1. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. 1. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | ```python
from copy import deepcopy
def getBetter(h, a):
maxi = -1
im = -1
for i in range(len(a)):
if (h >= a[i][0]):
if (maxi < a[i][1]):
im = i
maxi = a[i][1]
return(im, maxi)
n, h0 = map(int, input().split())
lolipops0 = [[], []]
for i in range(n):
t, h, m = map(int, input().split())
lolipops0[t].append((h, m))
lolipops0[1].sort()
lolipops0[0].sort()
lolipops1 = deepcopy(lolipops0)
lol0 = getBetter(h0, lolipops0[0])
t1 = 0
h1 = h0
lol1 = getBetter(h0, lolipops0[1])
t2 = 1 # ---- WARNING --------
h2 = h0
while(lol0[0] >= 0 or lol1[0] >=0):
if (lol0[0] > -1):
if (len(lolipops0[t1 % 2]) != 1 and lol0[0] != -1):
lolipops0[t1 % 2].pop(lol0[0])
else:
lolipops0[t1 % 2] = []
t1 += 1
h1 += lol0[1]
lol0 = getBetter(h1, lolipops0[t1 % 2])
if (lol1[0] > -1):
if (len(lolipops1[t2 % 2]) != 1 and lol1[0] != -1):
lolipops1[t2 % 2].pop(lol1[0])
else:
lolipops1[t2 % 2] = []
t2 += 1
h2 += lol1[1]
lol1 = getBetter(h2, lolipops1[t2 % 2])
print(max(t1, t2 - 1))
``` | 3 |
|
842 | B | Gleb And Pizza | PROGRAMMING | 1,100 | [
"geometry"
] | null | null | Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center at the origin. Pizza consists of the main part — circle of radius *r*<=-<=*d* with center at the origin, and crust around the main part of the width *d*. Pieces of sausage are also circles. The radius of the *i* -th piece of the sausage is *r**i*, and the center is given as a pair (*x**i*, *y**i*).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust. | First string contains two integer numbers *r* and *d* (0<=≤<=*d*<=<<=*r*<=≤<=500) — the radius of pizza and the width of crust.
Next line contains one integer number *n* — the number of pieces of sausage (1<=≤<=*n*<=≤<=105).
Each of next *n* lines contains three integer numbers *x**i*, *y**i* and *r**i* (<=-<=500<=≤<=*x**i*,<=*y**i*<=≤<=500, 0<=≤<=*r**i*<=≤<=500), where *x**i* and *y**i* are coordinates of the center of *i*-th peace of sausage, *r**i* — radius of *i*-th peace of sausage. | Output the number of pieces of sausage that lay on the crust. | [
"8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1\n",
"10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2\n"
] | [
"2\n",
"0\n"
] | Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust. | 1,000 | [
{
"input": "8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1",
"output": "2"
},
{
"input": "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2",
"output": "0"
},
{
"input": "1 0\n1\n1 1 0",
"output": "0"
},
{
"input": "3 0\n5\n3 0 0\n0 3 0\n-3 0 0\n0 -3 0\n3 0 1",
"output": "4"
},
{
"input": "9 0\n5\n8 1 0\n8 2 0\n8 3 0\n-8 3 0\n-8 2 0",
"output": "0"
},
{
"input": "10 2\n11\n1 1 0\n2 2 3\n3 3 0\n4 4 0\n5 5 0\n6 6 0\n7 7 4\n8 8 7\n9 9 3\n10 10 100\n9 0 1",
"output": "2"
},
{
"input": "5 3\n1\n500 500 10",
"output": "0"
}
] | 1,584,903,502 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 124 | 0 | r, d = map(int, input().split())
n = int(input())
ans = 0
for _ in range(n):
a, b, c = map(int, input().split())
if (a * a + b * b) ** 0.5 - c >= d and (a * a + b * b) ** 0.5 + c <= r:
ans += 1
print(ans)
| Title: Gleb And Pizza
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center at the origin. Pizza consists of the main part — circle of radius *r*<=-<=*d* with center at the origin, and crust around the main part of the width *d*. Pieces of sausage are also circles. The radius of the *i* -th piece of the sausage is *r**i*, and the center is given as a pair (*x**i*, *y**i*).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input Specification:
First string contains two integer numbers *r* and *d* (0<=≤<=*d*<=<<=*r*<=≤<=500) — the radius of pizza and the width of crust.
Next line contains one integer number *n* — the number of pieces of sausage (1<=≤<=*n*<=≤<=105).
Each of next *n* lines contains three integer numbers *x**i*, *y**i* and *r**i* (<=-<=500<=≤<=*x**i*,<=*y**i*<=≤<=500, 0<=≤<=*r**i*<=≤<=500), where *x**i* and *y**i* are coordinates of the center of *i*-th peace of sausage, *r**i* — radius of *i*-th peace of sausage.
Output Specification:
Output the number of pieces of sausage that lay on the crust.
Demo Input:
['8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1\n', '10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2\n']
Demo Output:
['2\n', '0\n']
Note:
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust. | ```python
r, d = map(int, input().split())
n = int(input())
ans = 0
for _ in range(n):
a, b, c = map(int, input().split())
if (a * a + b * b) ** 0.5 - c >= d and (a * a + b * b) ** 0.5 + c <= r:
ans += 1
print(ans)
``` | 0 |
|
675 | A | Infinite Sequence | PROGRAMMING | 1,100 | [
"math"
] | null | null | Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help. | The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. | If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). | [
"1 7 3\n",
"10 10 0\n",
"1 -4 5\n",
"0 60 50\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer. | 500 | [
{
"input": "1 7 3",
"output": "YES"
},
{
"input": "10 10 0",
"output": "YES"
},
{
"input": "1 -4 5",
"output": "NO"
},
{
"input": "0 60 50",
"output": "NO"
},
{
"input": "1 -4 -5",
"output": "YES"
},
{
"input": "0 1 0",
"output": "NO"
},
{
"input": "10 10 42",
"output": "YES"
},
{
"input": "-1000000000 1000000000 -1",
"output": "NO"
},
{
"input": "10 16 4",
"output": "NO"
},
{
"input": "-1000000000 1000000000 5",
"output": "YES"
},
{
"input": "1000000000 -1000000000 5",
"output": "NO"
},
{
"input": "1000000000 -1000000000 0",
"output": "NO"
},
{
"input": "1000000000 1000000000 0",
"output": "YES"
},
{
"input": "115078364 -899474523 -1",
"output": "YES"
},
{
"input": "-245436499 416383245 992",
"output": "YES"
},
{
"input": "-719636354 536952440 2",
"output": "YES"
},
{
"input": "-198350539 963391024 68337739",
"output": "YES"
},
{
"input": "-652811055 875986516 1091",
"output": "YES"
},
{
"input": "119057893 -516914539 -39748277",
"output": "YES"
},
{
"input": "989140430 731276607 -36837689",
"output": "YES"
},
{
"input": "677168390 494583489 -985071853",
"output": "NO"
},
{
"input": "58090193 777423708 395693923",
"output": "NO"
},
{
"input": "479823846 -403424770 -653472589",
"output": "NO"
},
{
"input": "-52536829 -132023273 -736287999",
"output": "NO"
},
{
"input": "-198893776 740026818 -547885271",
"output": "NO"
},
{
"input": "-2 -2 -2",
"output": "YES"
},
{
"input": "-2 -2 -1",
"output": "YES"
},
{
"input": "-2 -2 0",
"output": "YES"
},
{
"input": "-2 -2 1",
"output": "YES"
},
{
"input": "-2 -2 2",
"output": "YES"
},
{
"input": "-2 -1 -2",
"output": "NO"
},
{
"input": "-2 -1 -1",
"output": "NO"
},
{
"input": "-2 -1 0",
"output": "NO"
},
{
"input": "-2 -1 1",
"output": "YES"
},
{
"input": "-2 -1 2",
"output": "NO"
},
{
"input": "-2 0 -2",
"output": "NO"
},
{
"input": "-2 0 -1",
"output": "NO"
},
{
"input": "-2 0 0",
"output": "NO"
},
{
"input": "-2 0 1",
"output": "YES"
},
{
"input": "-2 0 2",
"output": "YES"
},
{
"input": "-2 1 -2",
"output": "NO"
},
{
"input": "-2 1 -1",
"output": "NO"
},
{
"input": "-2 1 0",
"output": "NO"
},
{
"input": "-2 1 1",
"output": "YES"
},
{
"input": "-2 1 2",
"output": "NO"
},
{
"input": "-2 2 -2",
"output": "NO"
},
{
"input": "-2 2 -1",
"output": "NO"
},
{
"input": "-2 2 0",
"output": "NO"
},
{
"input": "-2 2 1",
"output": "YES"
},
{
"input": "-2 2 2",
"output": "YES"
},
{
"input": "-1 -2 -2",
"output": "NO"
},
{
"input": "-1 -2 -1",
"output": "YES"
},
{
"input": "-1 -2 0",
"output": "NO"
},
{
"input": "-1 -2 1",
"output": "NO"
},
{
"input": "-1 -2 2",
"output": "NO"
},
{
"input": "-1 -1 -2",
"output": "YES"
},
{
"input": "-1 -1 -1",
"output": "YES"
},
{
"input": "-1 -1 0",
"output": "YES"
},
{
"input": "-1 -1 1",
"output": "YES"
},
{
"input": "-1 -1 2",
"output": "YES"
},
{
"input": "-1 0 -2",
"output": "NO"
},
{
"input": "-1 0 -1",
"output": "NO"
},
{
"input": "-1 0 0",
"output": "NO"
},
{
"input": "-1 0 1",
"output": "YES"
},
{
"input": "-1 0 2",
"output": "NO"
},
{
"input": "-1 1 -2",
"output": "NO"
},
{
"input": "-1 1 -1",
"output": "NO"
},
{
"input": "-1 1 0",
"output": "NO"
},
{
"input": "-1 1 1",
"output": "YES"
},
{
"input": "-1 1 2",
"output": "YES"
},
{
"input": "-1 2 -2",
"output": "NO"
},
{
"input": "-1 2 -1",
"output": "NO"
},
{
"input": "-1 2 0",
"output": "NO"
},
{
"input": "-1 2 1",
"output": "YES"
},
{
"input": "-1 2 2",
"output": "NO"
},
{
"input": "0 -2 -2",
"output": "YES"
},
{
"input": "0 -2 -1",
"output": "YES"
},
{
"input": "0 -2 0",
"output": "NO"
},
{
"input": "0 -2 1",
"output": "NO"
},
{
"input": "0 -2 2",
"output": "NO"
},
{
"input": "0 -1 -2",
"output": "NO"
},
{
"input": "0 -1 -1",
"output": "YES"
},
{
"input": "0 -1 0",
"output": "NO"
},
{
"input": "0 -1 1",
"output": "NO"
},
{
"input": "0 -1 2",
"output": "NO"
},
{
"input": "0 0 -2",
"output": "YES"
},
{
"input": "0 0 -1",
"output": "YES"
},
{
"input": "0 0 0",
"output": "YES"
},
{
"input": "0 0 1",
"output": "YES"
},
{
"input": "0 0 2",
"output": "YES"
},
{
"input": "0 1 -2",
"output": "NO"
},
{
"input": "0 1 -1",
"output": "NO"
},
{
"input": "0 1 0",
"output": "NO"
},
{
"input": "0 1 1",
"output": "YES"
},
{
"input": "0 1 2",
"output": "NO"
},
{
"input": "0 2 -2",
"output": "NO"
},
{
"input": "0 2 -1",
"output": "NO"
},
{
"input": "0 2 0",
"output": "NO"
},
{
"input": "0 2 1",
"output": "YES"
},
{
"input": "0 2 2",
"output": "YES"
},
{
"input": "1 -2 -2",
"output": "NO"
},
{
"input": "1 -2 -1",
"output": "YES"
},
{
"input": "1 -2 0",
"output": "NO"
},
{
"input": "1 -2 1",
"output": "NO"
},
{
"input": "1 -2 2",
"output": "NO"
},
{
"input": "1 -1 -2",
"output": "YES"
},
{
"input": "1 -1 -1",
"output": "YES"
},
{
"input": "1 -1 0",
"output": "NO"
},
{
"input": "1 -1 1",
"output": "NO"
},
{
"input": "1 -1 2",
"output": "NO"
},
{
"input": "1 0 -2",
"output": "NO"
},
{
"input": "1 0 -1",
"output": "YES"
},
{
"input": "1 0 0",
"output": "NO"
},
{
"input": "1 0 1",
"output": "NO"
},
{
"input": "1 0 2",
"output": "NO"
},
{
"input": "1 1 -2",
"output": "YES"
},
{
"input": "1 1 -1",
"output": "YES"
},
{
"input": "1 1 0",
"output": "YES"
},
{
"input": "1 1 1",
"output": "YES"
},
{
"input": "1 1 2",
"output": "YES"
},
{
"input": "1 2 -2",
"output": "NO"
},
{
"input": "1 2 -1",
"output": "NO"
},
{
"input": "1 2 0",
"output": "NO"
},
{
"input": "1 2 1",
"output": "YES"
},
{
"input": "1 2 2",
"output": "NO"
},
{
"input": "2 -2 -2",
"output": "YES"
},
{
"input": "2 -2 -1",
"output": "YES"
},
{
"input": "2 -2 0",
"output": "NO"
},
{
"input": "2 -2 1",
"output": "NO"
},
{
"input": "2 -2 2",
"output": "NO"
},
{
"input": "2 -1 -2",
"output": "NO"
},
{
"input": "2 -1 -1",
"output": "YES"
},
{
"input": "2 -1 0",
"output": "NO"
},
{
"input": "2 -1 1",
"output": "NO"
},
{
"input": "2 -1 2",
"output": "NO"
},
{
"input": "2 0 -2",
"output": "YES"
},
{
"input": "2 0 -1",
"output": "YES"
},
{
"input": "2 0 0",
"output": "NO"
},
{
"input": "2 0 1",
"output": "NO"
},
{
"input": "2 0 2",
"output": "NO"
},
{
"input": "2 1 -2",
"output": "NO"
},
{
"input": "2 1 -1",
"output": "YES"
},
{
"input": "2 1 0",
"output": "NO"
},
{
"input": "2 1 1",
"output": "NO"
},
{
"input": "2 1 2",
"output": "NO"
},
{
"input": "2 2 -2",
"output": "YES"
},
{
"input": "2 2 -1",
"output": "YES"
},
{
"input": "2 2 0",
"output": "YES"
},
{
"input": "2 2 1",
"output": "YES"
},
{
"input": "2 2 2",
"output": "YES"
},
{
"input": "-1000000000 1000000000 1",
"output": "YES"
},
{
"input": "-1000000000 1000000000 2",
"output": "YES"
},
{
"input": "1000000000 -1000000000 -1",
"output": "YES"
},
{
"input": "5 2 3",
"output": "NO"
},
{
"input": "2 1 -1",
"output": "YES"
},
{
"input": "3 2 1",
"output": "NO"
},
{
"input": "0 -5 -3",
"output": "NO"
},
{
"input": "2 5 5",
"output": "NO"
},
{
"input": "0 10 1",
"output": "YES"
},
{
"input": "15 5 -5",
"output": "YES"
},
{
"input": "2 1 1",
"output": "NO"
},
{
"input": "20 10 0",
"output": "NO"
},
{
"input": "20 15 5",
"output": "NO"
},
{
"input": "1 6 1",
"output": "YES"
},
{
"input": "1000000000 0 -1000000000",
"output": "YES"
},
{
"input": "1 1 -5",
"output": "YES"
},
{
"input": "4 6 1",
"output": "YES"
},
{
"input": "-5 -10 -5",
"output": "YES"
},
{
"input": "2 0 0",
"output": "NO"
},
{
"input": "10 9 -1",
"output": "YES"
},
{
"input": "-2 -1 -1",
"output": "NO"
},
{
"input": "1 13 3",
"output": "YES"
},
{
"input": "2 3 0",
"output": "NO"
},
{
"input": "1 1 -1",
"output": "YES"
},
{
"input": "5 -10 -5",
"output": "YES"
},
{
"input": "5 3 1",
"output": "NO"
},
{
"input": "1 1000000000 1",
"output": "YES"
},
{
"input": "-1000000000 1000000000 1000000000",
"output": "YES"
}
] | 1,531,498,908 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | def favourite_number(a, b, c):
if a - b == 0:
return "YES"
elif c == 0:
return "NO"
elif (a - b) % c != 0 and (a - b) * c < 0:
return "NO"
return "YES"
A, B, C = [int(i) for i in input().split()]
print(favourite_number(A, B, C))
| Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help.
Input Specification:
The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output Specification:
If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes).
Demo Input:
['1 7 3\n', '10 10 0\n', '1 -4 5\n', '0 60 50\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n', 'NO\n']
Note:
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer. | ```python
def favourite_number(a, b, c):
if a - b == 0:
return "YES"
elif c == 0:
return "NO"
elif (a - b) % c != 0 and (a - b) * c < 0:
return "NO"
return "YES"
A, B, C = [int(i) for i in input().split()]
print(favourite_number(A, B, C))
``` | 0 |
|
813 | E | Army Creation | PROGRAMMING | 2,200 | [
"binary search",
"data structures"
] | null | null | As you might remember from our previous rounds, Vova really likes computer games. Now he is playing a strategy game known as Rage of Empires.
In the game Vova can hire *n* different warriors; *i*th warrior has the type *a**i*. Vova wants to create a balanced army hiring some subset of warriors. An army is called balanced if for each type of warrior present in the game there are not more than *k* warriors of this type in the army. Of course, Vova wants his army to be as large as possible.
To make things more complicated, Vova has to consider *q* different plans of creating his army. *i*th plan allows him to hire only warriors whose numbers are not less than *l**i* and not greater than *r**i*.
Help Vova to determine the largest size of a balanced army for each plan.
Be aware that the plans are given in a modified way. See input section for details. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100000).
The second line contains *n* integers *a*1, *a*2, ... *a**n* (1<=≤<=*a**i*<=≤<=100000).
The third line contains one integer *q* (1<=≤<=*q*<=≤<=100000).
Then *q* lines follow. *i*th line contains two numbers *x**i* and *y**i* which represent *i*th plan (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*).
You have to keep track of the answer to the last plan (let's call it *last*). In the beginning *last*<==<=0. Then to restore values of *l**i* and *r**i* for the *i*th plan, you have to do the following:
1. *l**i*<==<=((*x**i*<=+<=*last*) *mod* *n*)<=+<=1; 1. *r**i*<==<=((*y**i*<=+<=*last*) *mod* *n*)<=+<=1; 1. If *l**i*<=><=*r**i*, swap *l**i* and *r**i*. | Print *q* numbers. *i*th number must be equal to the maximum size of a balanced army when considering *i*th plan. | [
"6 2\n1 1 1 2 2 2\n5\n1 6\n4 3\n1 1\n2 6\n2 6\n"
] | [
"2\n4\n1\n3\n2\n"
] | In the first example the real plans are:
1. 1 2 1. 1 6 1. 6 6 1. 2 4 1. 4 6 | 0 | [
{
"input": "6 2\n1 1 1 2 2 2\n5\n1 6\n4 3\n1 1\n2 6\n2 6",
"output": "2\n4\n1\n3\n2"
},
{
"input": "5 5\n3 4 4 2 1\n5\n5 5\n5 4\n5 4\n3 4\n5 5",
"output": "1\n2\n2\n2\n1"
},
{
"input": "5 5\n2 1 2 4 1\n5\n5 3\n1 1\n5 1\n2 1\n2 3",
"output": "4\n1\n2\n2\n5"
},
{
"input": "10 5\n4 5 7 3 5 6 6 8 10 9\n5\n10 8\n9 8\n7 5\n8 10\n5 8",
"output": "9\n2\n3\n3\n8"
},
{
"input": "20 5\n9 5 4 10 2 1 8 9 7 4 1 5 4 9 8 10 5 8 4 10\n5\n9 13\n17 13\n6 12\n13 11\n8 8",
"output": "5\n17\n7\n19\n1"
},
{
"input": "100 5\n45 51 23 10 62 69 48 47 47 59 58 14 54 34 66 78 92 66 42 25 96 68 35 50 58 77 87 100 57 42 43 76 24 70 26 98 33 11 41 9 17 65 53 23 45 5 24 98 73 91 92 73 51 68 82 95 24 61 88 3 64 74 28 7 77 49 55 62 64 4 51 86 72 26 65 82 13 55 31 44 10 59 83 16 27 67 2 36 52 12 3 26 36 38 58 25 23 3 69 16\n5\n13 49\n86 62\n91 77\n84 50\n33 66",
"output": "37\n77\n15\n35\n68"
},
{
"input": "1 1\n1\n1\n1 1",
"output": "1"
},
{
"input": "1 5\n8\n9\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": "5 1\n10 7 6 6 6\n8\n5 2\n4 5\n2 1\n5 2\n3 1\n3 1\n4 1\n5 2",
"output": "3\n1\n1\n2\n3\n2\n2\n1"
}
] | 1,691,763,970 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1691763970.7246501")# 1691763970.7246654 | Title: Army Creation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you might remember from our previous rounds, Vova really likes computer games. Now he is playing a strategy game known as Rage of Empires.
In the game Vova can hire *n* different warriors; *i*th warrior has the type *a**i*. Vova wants to create a balanced army hiring some subset of warriors. An army is called balanced if for each type of warrior present in the game there are not more than *k* warriors of this type in the army. Of course, Vova wants his army to be as large as possible.
To make things more complicated, Vova has to consider *q* different plans of creating his army. *i*th plan allows him to hire only warriors whose numbers are not less than *l**i* and not greater than *r**i*.
Help Vova to determine the largest size of a balanced army for each plan.
Be aware that the plans are given in a modified way. See input section for details.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100000).
The second line contains *n* integers *a*1, *a*2, ... *a**n* (1<=≤<=*a**i*<=≤<=100000).
The third line contains one integer *q* (1<=≤<=*q*<=≤<=100000).
Then *q* lines follow. *i*th line contains two numbers *x**i* and *y**i* which represent *i*th plan (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*).
You have to keep track of the answer to the last plan (let's call it *last*). In the beginning *last*<==<=0. Then to restore values of *l**i* and *r**i* for the *i*th plan, you have to do the following:
1. *l**i*<==<=((*x**i*<=+<=*last*) *mod* *n*)<=+<=1; 1. *r**i*<==<=((*y**i*<=+<=*last*) *mod* *n*)<=+<=1; 1. If *l**i*<=><=*r**i*, swap *l**i* and *r**i*.
Output Specification:
Print *q* numbers. *i*th number must be equal to the maximum size of a balanced army when considering *i*th plan.
Demo Input:
['6 2\n1 1 1 2 2 2\n5\n1 6\n4 3\n1 1\n2 6\n2 6\n']
Demo Output:
['2\n4\n1\n3\n2\n']
Note:
In the first example the real plans are:
1. 1 2 1. 1 6 1. 6 6 1. 2 4 1. 4 6 | ```python
print("_RANDOM_GUESS_1691763970.7246501")# 1691763970.7246654
``` | 0 |
|
681 | A | A Good Contest | PROGRAMMING | 800 | [
"implementation"
] | null | null | Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.
Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same? | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest .
The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters.
It is guaranteed that all handles are distinct. | Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise. | [
"3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n",
"3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n"
] | [
"YES",
"NO"
] | In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest. | 500 | [
{
"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "NO"
},
{
"input": "1\nDb -3373 3591",
"output": "NO"
},
{
"input": "5\nQ2bz 960 2342\nhmX 2710 -1348\ngbAe -1969 -963\nE -160 196\npsi 2665 -3155",
"output": "NO"
},
{
"input": "9\nmwAz9lQ 1786 -1631\nnYgYFXZQfY -1849 -1775\nKU4jF -1773 -3376\nopR 3752 2931\nGl -1481 -1002\nR -1111 3778\n0i9B21DC 3650 289\nQ8L2dS0 358 -3305\ng -2662 3968",
"output": "NO"
},
{
"input": "5\nzMSBcOUf -2883 -2238\nYN -3314 -1480\nfHpuccQn06 -1433 -589\naM1NVEPQi 399 3462\n_L 2516 -3290",
"output": "NO"
},
{
"input": "1\na 2400 2401",
"output": "YES"
},
{
"input": "1\nfucker 4000 4000",
"output": "NO"
},
{
"input": "1\nJora 2400 2401",
"output": "YES"
},
{
"input": "1\nACA 2400 2420",
"output": "YES"
},
{
"input": "1\nAca 2400 2420",
"output": "YES"
},
{
"input": "1\nSub_d 2401 2402",
"output": "YES"
},
{
"input": "2\nHack 2400 2401\nDum 1243 555",
"output": "YES"
},
{
"input": "1\nXXX 2400 2500",
"output": "YES"
},
{
"input": "1\nfucker 2400 2401",
"output": "YES"
},
{
"input": "1\nX 2400 2500",
"output": "YES"
},
{
"input": "1\nvineet 2400 2401",
"output": "YES"
},
{
"input": "1\nabc 2400 2500",
"output": "YES"
},
{
"input": "1\naaaaa 2400 2401",
"output": "YES"
},
{
"input": "1\nhoge 2400 2401",
"output": "YES"
},
{
"input": "1\nInfinity 2400 2468",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2401",
"output": "YES"
},
{
"input": "1\nFuck 2400 2401",
"output": "YES"
},
{
"input": "1\nfuck 2400 2401",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2401\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "YES"
},
{
"input": "1\nalex 2400 2401",
"output": "YES"
},
{
"input": "1\nA 2400 2401",
"output": "YES"
},
{
"input": "1\na 2400 2455",
"output": "YES"
},
{
"input": "1\nlol 2400 2401",
"output": "YES"
},
{
"input": "2\nBurunduk1 2400 2537\nBudAlNik 2084 2214",
"output": "YES"
},
{
"input": "1\naaaaaa 2400 2401",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2500",
"output": "YES"
},
{
"input": "1\nds 2400 2410",
"output": "YES"
},
{
"input": "1\nas 2400 2401",
"output": "YES"
},
{
"input": "1\nabc 2400 2401",
"output": "YES"
},
{
"input": "3\nBudAlNik 2084 2214\nsubscriber 2833 2749\nBurunduk1 2526 2537",
"output": "YES"
},
{
"input": "1\ncaonima 2400 2401",
"output": "YES"
},
{
"input": "1\narr 2400 2500",
"output": "YES"
},
{
"input": "1\nx 2400 2401",
"output": "YES"
},
{
"input": "1\narrr 2400 2500",
"output": "YES"
},
{
"input": "1\nabc 2400 2405",
"output": "YES"
},
{
"input": "3\nBurunduk1 2400 2420\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "1\nBurunduk1 2400 2537",
"output": "YES"
},
{
"input": "1\nHELLO 2400 2401",
"output": "YES"
},
{
"input": "1\neatmore 2400 2500",
"output": "YES"
},
{
"input": "1\nb 2400 2401",
"output": "YES"
},
{
"input": "3\nBurunduk1 2400 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "1\nApplejack 2400 2410",
"output": "YES"
},
{
"input": "1\nabacaba 2400 2451",
"output": "YES"
},
{
"input": "1\nrekt_n00b 2500 2600",
"output": "YES"
}
] | 1,576,218,606 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input())
i=0
k=0
while i<n:
A=input().split()
if int(A[1])>=2400 and int(A[1])<int(A[2]):
k=1
break
i+=1
if k==1:
print('YES')
else:
print('NO')
| Title: A Good Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.
Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same?
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest .
The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters.
It is guaranteed that all handles are distinct.
Output Specification:
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
Demo Input:
['3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n', '3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n']
Demo Output:
['YES', 'NO']
Note:
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest. | ```python
n=int(input())
i=0
k=0
while i<n:
A=input().split()
if int(A[1])>=2400 and int(A[1])<int(A[2]):
k=1
break
i+=1
if k==1:
print('YES')
else:
print('NO')
``` | -1 |
|
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "6"
},
{
"input": "5 1\n998 997 985 937 998",
"output": "0"
},
{
"input": "2 2\n-742 -187",
"output": "929"
},
{
"input": "3 3\n522 597 384",
"output": "0"
},
{
"input": "4 2\n-215 -620 192 647",
"output": "835"
},
{
"input": "10 6\n557 605 685 231 910 633 130 838 -564 -85",
"output": "649"
},
{
"input": "20 14\n932 442 960 943 624 624 955 998 631 910 850 517 715 123 1000 155 -10 961 966 59",
"output": "10"
},
{
"input": "30 5\n991 997 996 967 977 999 991 986 1000 965 984 997 998 1000 958 983 974 1000 991 999 1000 978 961 992 990 998 998 978 998 1000",
"output": "0"
},
{
"input": "50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -799 -886",
"output": "19441"
},
{
"input": "88 64\n999 999 1000 1000 999 996 995 1000 1000 999 1000 997 998 1000 999 1000 997 1000 993 998 994 999 998 996 1000 997 1000 1000 1000 997 1000 998 997 1000 1000 998 1000 998 999 1000 996 999 999 999 996 995 999 1000 998 999 1000 999 999 1000 1000 1000 996 1000 1000 1000 997 1000 1000 997 999 1000 1000 1000 1000 1000 999 999 1000 1000 996 999 1000 1000 995 999 1000 996 1000 998 999 999 1000 999",
"output": "0"
},
{
"input": "99 17\n-993 -994 -959 -989 -991 -995 -976 -997 -990 -1000 -996 -994 -999 -995 -1000 -983 -979 -1000 -989 -968 -994 -992 -962 -993 -999 -983 -991 -979 -995 -993 -973 -999 -995 -995 -999 -993 -995 -992 -947 -1000 -999 -998 -982 -988 -979 -993 -963 -988 -980 -990 -979 -976 -995 -999 -981 -988 -998 -999 -970 -1000 -983 -994 -943 -975 -998 -977 -973 -997 -959 -999 -983 -985 -950 -977 -977 -991 -998 -973 -987 -985 -985 -986 -984 -994 -978 -998 -989 -989 -988 -970 -985 -974 -997 -981 -962 -972 -995 -988 -993",
"output": "16984"
},
{
"input": "100 37\n205 19 -501 404 912 -435 -322 -469 -655 880 -804 -470 793 312 -108 586 -642 -928 906 605 -353 -800 745 -440 -207 752 -50 -28 498 -800 -62 -195 602 -833 489 352 536 404 -775 23 145 -512 524 759 651 -461 -427 -557 684 -366 62 592 -563 -811 64 418 -881 -308 591 -318 -145 -261 -321 -216 -18 595 -202 960 -4 219 226 -238 -882 -963 425 970 -434 -160 243 -672 -4 873 8 -633 904 -298 -151 -377 -61 -72 -677 -66 197 -716 3 -870 -30 152 -469 981",
"output": "21743"
},
{
"input": "100 99\n-931 -806 -830 -828 -916 -962 -660 -867 -952 -966 -820 -906 -724 -982 -680 -717 -488 -741 -897 -613 -986 -797 -964 -939 -808 -932 -810 -860 -641 -916 -858 -628 -821 -929 -917 -976 -664 -985 -778 -665 -624 -928 -940 -958 -884 -757 -878 -896 -634 -526 -514 -873 -990 -919 -988 -878 -650 -973 -774 -783 -733 -648 -756 -895 -833 -974 -832 -725 -841 -748 -806 -613 -924 -867 -881 -943 -864 -991 -809 -926 -777 -817 -998 -682 -910 -996 -241 -722 -964 -904 -821 -920 -835 -699 -805 -632 -779 -317 -915 -654",
"output": "81283"
},
{
"input": "100 14\n995 994 745 684 510 737 984 690 979 977 542 933 871 603 758 653 962 997 747 974 773 766 975 770 527 960 841 989 963 865 974 967 950 984 757 685 986 809 982 959 931 880 978 867 805 562 970 900 834 782 616 885 910 608 974 918 576 700 871 980 656 941 978 759 767 840 573 859 841 928 693 853 716 927 976 851 962 962 627 797 707 873 869 988 993 533 665 887 962 880 929 980 877 887 572 790 721 883 848 782",
"output": "0"
},
{
"input": "100 84\n768 946 998 752 931 912 826 1000 991 910 875 962 901 952 958 733 959 908 872 840 923 826 952 980 974 980 947 955 959 822 997 963 966 933 829 923 971 999 926 932 865 984 974 858 994 855 949 941 992 861 951 949 991 711 763 728 935 485 716 907 869 952 960 859 909 963 978 942 968 933 923 909 997 962 687 764 924 774 875 1000 961 951 987 974 848 921 966 859 995 997 974 931 886 941 974 986 906 978 998 823",
"output": "0"
},
{
"input": "100 80\n-795 -994 -833 -930 -974 -980 -950 -940 -788 -927 -583 -956 -945 -949 -809 -974 -957 -736 -967 -908 -975 -961 -986 -983 -963 -771 -952 -847 -751 -741 -982 -959 -925 -931 -839 -937 -880 -914 -858 -998 -812 -911 -862 -965 -943 -984 -738 -920 -950 -998 -909 -998 -781 -901 -677 -940 -985 -951 -675 -952 -967 -949 -882 -641 -969 -937 -975 -993 -913 -941 -807 -851 -832 -960 -939 -943 -895 -929 -528 -880 -823 -930 -888 -862 -948 -966 -962 -857 -799 -969 -833 -998 -952 -878 -946 -971 -976 -974 -723 -992",
"output": "75068"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 1\n555",
"output": "0"
},
{
"input": "1 1\n-1",
"output": "1"
},
{
"input": "1 1\n-24",
"output": "24"
}
] | 1,687,679,840 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | #F
n, m = [int(x) for x in input().split()]
total = int(0)
a = [int(x) for x in input().split()]
a.sort()
for i in range(m):
if (a[i]<=0):
total+=a[i]
else :
break
print(total*-1)
| Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output Specification:
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
Demo Input:
['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n']
Demo Output:
['8\n', '7\n']
Note:
none | ```python
#F
n, m = [int(x) for x in input().split()]
total = int(0)
a = [int(x) for x in input().split()]
a.sort()
for i in range(m):
if (a[i]<=0):
total+=a[i]
else :
break
print(total*-1)
``` | 3.977 |
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,695,700,468 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 62 | 0 | n, m, a = map(int, input().split())
width_stones = -(-n // a)
length_stones = -(-m // a)
total_stones = width_stones * length_stones
print(total_stones) | 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
n, m, a = map(int, input().split())
width_stones = -(-n // a)
length_stones = -(-m // a)
total_stones = width_stones * length_stones
print(total_stones)
``` | 3.969 |
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,592,203,350 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 374 | 307,200 | n=int(input())
lst=list(map(int,input().split(' ')))
lstc={}
for i in range(n):
if(lst[i] in lstc.keys()):
continue
else:
count=0
for j in range(n):
if(lst[i]==lst[j]):
count+=1
lstc[lst[i]]=count
height=max(lstc.values())
print(height,len(lstc.values())) | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.
Input Specification:
The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
Output Specification:
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
Demo Input:
['3\n1 2 3\n', '4\n6 5 6 7\n']
Demo Output:
['1 3\n', '2 3\n']
Note:
none | ```python
n=int(input())
lst=list(map(int,input().split(' ')))
lstc={}
for i in range(n):
if(lst[i] in lstc.keys()):
continue
else:
count=0
for j in range(n):
if(lst[i]==lst[j]):
count+=1
lstc[lst[i]]=count
height=max(lstc.values())
print(height,len(lstc.values()))
``` | 3.905928 |
592 | A | PawnChess | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed.
Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as (*r*,<=*c*) the cell located at the row *r* and at the column *c*.
There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row 1, while player B tries to put any of his pawns to the row 8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner.
Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players.
Moving upward means that the pawn located in (*r*,<=*c*) will go to the cell (*r*<=-<=1,<=*c*), while moving down means the pawn located in (*r*,<=*c*) will go to the cell (*r*<=+<=1,<=*c*). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color.
Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available. | The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'.
It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row. | Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board. | [
"........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n",
"..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n"
] | [
"A\n",
"B\n"
] | In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner. | 500 | [
{
"input": ".BB.B.B.\nB..B..B.\n.B.BB...\nBB.....B\nBBB....B\nB..BB...\nBB.B...B\n....WWW.",
"output": "B"
},
{
"input": "B.B.BB.B\nW.WWW.WW\n.WWWWW.W\nW.BB.WBW\n.W..BBWB\nBB.WWBBB\n.W.W.WWB\nWWW..WW.",
"output": "A"
},
{
"input": "BB..BB..\nBW.W.W.B\n..B.....\n.....BB.\n.B..B..B\n........\n...BB.B.\nW.WWWW.W",
"output": "A"
},
{
"input": "BB......\nW....BBW\n........\n.B.B.BBB\n....BB..\nB....BB.\n...WWWW.\n....WW..",
"output": "A"
},
{
"input": ".B.B..B.\nB.B....B\n...B.B.B\n..B.W..B\n.BBB.B.B\nB.BB.B.B\nBB..BBBB\nW.W.W.WW",
"output": "B"
},
{
"input": "..BB....\n.B.B.B.B\n..B.B...\n..B..B.B\nWWWBWWB.\n.BB...B.\n..BBB...\n......W.",
"output": "B"
},
{
"input": "..BB....\n.WBWBWBB\n.....BBB\n..WW....\n.W.W...W\nWWW...W.\n.W....W.\nW...W.W.",
"output": "A"
},
{
"input": "....BB..\nBB......\n.B.....B\nWW..WWW.\n...BB.B.\nB...BB..\n..W..WWW\n...W...W",
"output": "B"
},
{
"input": "B...BBBB\n...BBB..\nBBWBWW.W\n.B..BB.B\nW..W..WW\nW.WW....\n........\nWW.....W",
"output": "A"
},
{
"input": ".B......\n.B....B.\n...W....\n......W.\nW.WWWW.W\nW.WW....\n..WWW...\n..W...WW",
"output": "A"
},
{
"input": "B.......\nBBB.....\n.B....B.\n.W.BWB.W\n......B.\nW..WW...\n...W....\nW...W..W",
"output": "A"
},
{
"input": ".....B..\n........\n........\n.BB..B..\n..BB....\n........\n....WWW.\n......W.",
"output": "B"
},
{
"input": "B.B...B.\n...BBBBB\n....B...\n...B...B\nB.B.B..B\n........\n........\nWWW..WW.",
"output": "B"
},
{
"input": "B.B...B.\n........\n.......B\n.BB....B\n.....W..\n.W.WW.W.\n...W.WW.\nW..WW..W",
"output": "A"
},
{
"input": "......B.\nB....B..\n...B.BB.\n...B....\n........\n..W....W\nWW......\n.W....W.",
"output": "B"
},
{
"input": ".BBB....\nB.B.B...\nB.BB.B..\nB.BB.B.B\n........\n........\nW.....W.\n..WW..W.",
"output": "B"
},
{
"input": "..B..BBB\n........\n........\n........\n...W.W..\n...W..W.\nW.......\n..W...W.",
"output": "A"
},
{
"input": "........\n.B.B....\n...B..BB\n........\n........\nW...W...\nW...W...\nW.WW.W..",
"output": "A"
},
{
"input": "B....BB.\n...B...B\n.B......\n........\n........\n........\n........\n....W..W",
"output": "B"
},
{
"input": "...BB.BB\nBB...B..\n........\n........\n........\n........\n..W..W..\n......W.",
"output": "A"
},
{
"input": "...BB...\n........\n........\n........\n........\n........\n......W.\nWW...WW.",
"output": "A"
},
{
"input": "...B.B..\n........\n........\n........\n........\n........\n........\nWWW...WW",
"output": "A"
},
{
"input": "BBBBBBB.\n........\n........\n........\n........\n........\n........\n.WWWWWWW",
"output": "A"
},
{
"input": ".BBBBBB.\nB.......\n........\n........\n........\n........\n........\n.WWWWWWW",
"output": "B"
},
{
"input": ".BBBBBBB\n........\n........\n........\n........\n........\n........\nWWWWWWW.",
"output": "A"
},
{
"input": ".BBBBBB.\n.......B\n........\n........\n........\n........\n........\nWWWWWWW.",
"output": "B"
},
{
"input": "B..BB...\n..B...B.\n.WBB...B\nBW......\nW.B...W.\n..BBW.B.\nBW..BB..\n......W.",
"output": "B"
},
{
"input": "B.BBBBBB\nB..BBB.B\nW.BB.W.B\nB.BWBB.B\nBWBWBBBB\n...BBBBB\nB.B...BB\nWW..WW.W",
"output": "B"
},
{
"input": "BBBB.BBB\nBBBB.B.B\nB.B..BBB\nB.BB.BWW\nB.BB.BBB\nB.BB.BBB\n..BW.BB.\nW.WWWWWW",
"output": "B"
},
{
"input": "BBBB.BBB\n.B....WB\nBB.B...B\nWWWW.WWB\nBB...BWW\nWWW..BBB\nW.BW.BB.\nWWWWWWW.",
"output": "B"
},
{
"input": "B.BBBBBB\nW.WWBBBW\nW.BB.WBB\nW.W.BBBW\nW.BWW.WB\nB..B..BB\nB.B.W.BB\nWWWWW.WW",
"output": "B"
},
{
"input": "BBBBBB.B\n.BBWBB.B\nWWW..B.W\n..WW.W.W\nBWB..W.W\n..BW.B.W\nB..B....\nWWWW.WWW",
"output": "B"
},
{
"input": ".B...BB.\nWBB.BWBB\n.BWBW...\n..W...B.\nWB.BWW..\nWBW.....\n.W..W.B.\n.W.W.WW.",
"output": "A"
},
{
"input": ".B..BBBB\nBB...WWB\nB..B.W.B\nWB.W...B\n...W.WW.\nW.....W.\nWB.W.W.W\n.WW...WW",
"output": "A"
},
{
"input": "B.BBBBBB\nW.BB.W.B\nW.BBW...\n..WWWW.B\n....W..B\n.WW.W..W\n.W..WW.W\nW.W....W",
"output": "A"
},
{
"input": "........\n.B......\n.W......\n........\n....B...\n........\n........\n.......W",
"output": "B"
}
] | 1,489,420,890 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 109 | 23,142,400 | grid = []
for k in range(8):
grid.append(input())
bbc = [] #blocked black columns
bwc = [] #blocked white columns
#first processing : downwards
white = 8
for k in range(8):
for j in range(8):
if grid[k][j] == "B":
bbc.append(j)
if grid[k][j] == "W" and not j in bbc and white == 8:
white = k
black = 8
for k in range(7,-1,-1):
for j in range(8):
if grid[k][j] == "W":
bwc.append(j)
if grid[k][j] == "B" and not j in bwc and black == 8:
black = 7-k
if white <= black:
print("A")
else:
print("B")
| Title: PawnChess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed.
Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as (*r*,<=*c*) the cell located at the row *r* and at the column *c*.
There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row 1, while player B tries to put any of his pawns to the row 8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner.
Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players.
Moving upward means that the pawn located in (*r*,<=*c*) will go to the cell (*r*<=-<=1,<=*c*), while moving down means the pawn located in (*r*,<=*c*) will go to the cell (*r*<=+<=1,<=*c*). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color.
Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available.
Input Specification:
The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'.
It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row.
Output Specification:
Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board.
Demo Input:
['........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n', '..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n']
Demo Output:
['A\n', 'B\n']
Note:
In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner. | ```python
grid = []
for k in range(8):
grid.append(input())
bbc = [] #blocked black columns
bwc = [] #blocked white columns
#first processing : downwards
white = 8
for k in range(8):
for j in range(8):
if grid[k][j] == "B":
bbc.append(j)
if grid[k][j] == "W" and not j in bbc and white == 8:
white = k
black = 8
for k in range(7,-1,-1):
for j in range(8):
if grid[k][j] == "W":
bwc.append(j)
if grid[k][j] == "B" and not j in bwc and black == 8:
black = 7-k
if white <= black:
print("A")
else:
print("B")
``` | 3 |
|
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times? | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1",
"output": "3"
},
{
"input": "15 2\n0 1 2 3 4 0 1 2 3 4 0 1 2 3 4",
"output": "4"
},
{
"input": "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1",
"output": "3"
},
{
"input": "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0",
"output": "5"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4",
"output": "4"
},
{
"input": "6 3\n4 4 4 4 4 4",
"output": "0"
},
{
"input": "1 4\n1",
"output": "0"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "2 3\n0 0",
"output": "0"
}
] | 1,658,973,787 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 62 | 1,843,200 | n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
for i in range(n):
arr[i] = (5-arr[i])-k
ans = 0
for i in range(n):
if arr[i] >=0:
ans += 1
print(ans//3)
| Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
Input Specification:
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Output Specification:
Print a single number — the answer to the problem.
Demo Input:
['5 2\n0 4 5 1 0\n', '6 4\n0 1 2 3 4 5\n', '6 5\n0 0 0 0 0 0\n']
Demo Output:
['1\n', '0\n', '2\n']
Note:
In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | ```python
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
for i in range(n):
arr[i] = (5-arr[i])-k
ans = 0
for i in range(n):
if arr[i] >=0:
ans += 1
print(ans//3)
``` | 3 |
|
837 | B | Flag of Berland | PROGRAMMING | 1,600 | [
"brute force",
"implementation"
] | null | null | The flag of Berland is such rectangular field *n*<=×<=*m* that satisfies following conditions:
- Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. - Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. - Each color should be used in exactly one stripe.
You are given a field *n*<=×<=*m*, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the field.
Each of the following *n* lines consisting of *m* characters 'R', 'G' and 'B' — the description of the field. | Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). | [
"6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG\n",
"4 3\nBRG\nBRG\nBRG\nBRG\n",
"6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB\n",
"4 4\nRRRR\nRRRR\nBBBB\nGGGG\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1. | 0 | [
{
"input": "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG",
"output": "YES"
},
{
"input": "4 3\nBRG\nBRG\nBRG\nBRG",
"output": "YES"
},
{
"input": "6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB",
"output": "NO"
},
{
"input": "4 4\nRRRR\nRRRR\nBBBB\nGGGG",
"output": "NO"
},
{
"input": "1 3\nGRB",
"output": "YES"
},
{
"input": "3 1\nR\nG\nB",
"output": "YES"
},
{
"input": "4 3\nRGB\nGRB\nGRB\nGRB",
"output": "NO"
},
{
"input": "4 6\nGGRRBB\nGGRRBB\nGGRRBB\nRRGGBB",
"output": "NO"
},
{
"input": "100 3\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nGRB",
"output": "NO"
},
{
"input": "3 100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRG",
"output": "NO"
},
{
"input": "3 1\nR\nR\nB",
"output": "NO"
},
{
"input": "3 2\nRR\nBB\nRR",
"output": "NO"
},
{
"input": "3 2\nRR\nBG\nBG",
"output": "NO"
},
{
"input": "3 2\nBB\nRR\nBB",
"output": "NO"
},
{
"input": "3 3\nRRR\nRRR\nRRR",
"output": "NO"
},
{
"input": "3 3\nGGG\nGGG\nGGG",
"output": "NO"
},
{
"input": "1 3\nRGG",
"output": "NO"
},
{
"input": "4 3\nRGR\nRGR\nRGR\nRGR",
"output": "NO"
},
{
"input": "3 4\nRRGG\nRRGG\nBBBB",
"output": "NO"
},
{
"input": "3 3\nBRG\nBRG\nBRG",
"output": "YES"
},
{
"input": "3 1\nR\nG\nR",
"output": "NO"
},
{
"input": "5 3\nBBG\nBBG\nBBG\nBBG\nBBG",
"output": "NO"
},
{
"input": "3 3\nRRR\nGGG\nRRR",
"output": "NO"
},
{
"input": "1 3\nRGR",
"output": "NO"
},
{
"input": "3 6\nRRBBGG\nRRBBGG\nRRBBGG",
"output": "YES"
},
{
"input": "6 6\nRRBBGG\nRRBBGG\nRRBBGG\nRRBBGG\nRRBBGG\nRRBBGG",
"output": "YES"
},
{
"input": "4 3\nRRR\nGGG\nBBB\nBBB",
"output": "NO"
},
{
"input": "3 3\nRRR\nBBB\nRRR",
"output": "NO"
},
{
"input": "3 1\nB\nR\nB",
"output": "NO"
},
{
"input": "1 3\nBGB",
"output": "NO"
},
{
"input": "3 1\nB\nB\nB",
"output": "NO"
},
{
"input": "3 4\nRRRR\nBBBB\nRRRR",
"output": "NO"
},
{
"input": "1 6\nRGGGBB",
"output": "NO"
},
{
"input": "9 3\nBBB\nBBB\nBBB\nGGG\nGGG\nGRG\nRGR\nRRR\nRRR",
"output": "NO"
},
{
"input": "4 4\nRGBB\nRGBB\nRGBB\nRGBB",
"output": "NO"
},
{
"input": "3 3\nRBR\nRBR\nRBR",
"output": "NO"
},
{
"input": "1 6\nRRRRBB",
"output": "NO"
},
{
"input": "1 6\nRRRRRR",
"output": "NO"
},
{
"input": "1 6\nRRGGGG",
"output": "NO"
},
{
"input": "4 4\nRRRR\nRRRR\nRRRR\nRRRR",
"output": "NO"
},
{
"input": "3 1\nB\nG\nB",
"output": "NO"
},
{
"input": "3 1\nR\nR\nR",
"output": "NO"
},
{
"input": "1 9\nRRRGGGBBB",
"output": "YES"
},
{
"input": "1 3\nRRR",
"output": "NO"
},
{
"input": "3 5\nRRRRR\nBBBBB\nBBBBB",
"output": "NO"
},
{
"input": "3 3\nRRR\nGGG\nGGG",
"output": "NO"
},
{
"input": "1 1\nR",
"output": "NO"
},
{
"input": "3 3\nRGR\nRGR\nRGR",
"output": "NO"
},
{
"input": "1 3\nGGG",
"output": "NO"
},
{
"input": "3 3\nRBG\nGBR\nRGB",
"output": "NO"
},
{
"input": "3 3\nRGB\nRGB\nRGB",
"output": "YES"
},
{
"input": "1 3\nBRB",
"output": "NO"
},
{
"input": "2 1\nR\nB",
"output": "NO"
},
{
"input": "1 3\nRBR",
"output": "NO"
},
{
"input": "3 5\nRRGBB\nRRGBB\nRRGBB",
"output": "NO"
},
{
"input": "5 3\nBBR\nBBR\nBBR\nBBR\nBBR",
"output": "NO"
},
{
"input": "3 3\nRGB\nRBG\nRGB",
"output": "NO"
},
{
"input": "1 2\nRB",
"output": "NO"
},
{
"input": "4 3\nBBB\nBBB\nBBB\nBBB",
"output": "NO"
},
{
"input": "36 6\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR",
"output": "NO"
},
{
"input": "4 1\nR\nB\nG\nR",
"output": "NO"
},
{
"input": "13 12\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR",
"output": "NO"
},
{
"input": "2 2\nRR\nRR",
"output": "NO"
},
{
"input": "6 6\nRRGGBB\nGRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB",
"output": "NO"
},
{
"input": "70 3\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG",
"output": "NO"
},
{
"input": "4 3\nBBG\nBBG\nBBG\nBBG",
"output": "NO"
},
{
"input": "6 3\nBBB\nGGG\nRRR\nBRG\nBRG\nBRG",
"output": "NO"
},
{
"input": "3 6\nRRBBGG\nRBBBGG\nRBBBGG",
"output": "NO"
},
{
"input": "6 6\nGGGGGG\nGGGGGG\nBBBBBB\nBBBBBB\nGGGGGG\nGGGGGG",
"output": "NO"
},
{
"input": "6 1\nR\nB\nG\nR\nB\nG",
"output": "NO"
},
{
"input": "6 5\nRRRRR\nBBBBB\nGGGGG\nRRRRR\nBBBBB\nGGGGG",
"output": "NO"
},
{
"input": "6 3\nRRR\nGGG\nBBB\nRRR\nGGG\nBBB",
"output": "NO"
},
{
"input": "6 5\nRRRRR\nRRRRR\nRRRRR\nGGGGG\nGGGGG\nGGGGG",
"output": "NO"
},
{
"input": "15 28\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "NO"
},
{
"input": "21 10\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nBBBBBBBBBB\nBBBBBBBBBB\nBBBBBGBBBB\nBBBBBBBBBB\nBBBBBBBBBB\nBBBBBBBBBB\nBBBBBBBBBB\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG",
"output": "NO"
},
{
"input": "3 2\nRR\nGB\nGB",
"output": "NO"
},
{
"input": "3 2\nRG\nRG\nBB",
"output": "NO"
},
{
"input": "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nRRRRR\nRRRRR",
"output": "NO"
},
{
"input": "3 3\nRGB\nGBR\nBRG",
"output": "NO"
},
{
"input": "1 3\nRBB",
"output": "NO"
},
{
"input": "3 3\nBGR\nBGR\nBGR",
"output": "YES"
},
{
"input": "6 6\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB",
"output": "YES"
},
{
"input": "4 2\nRR\nGG\nRR\nBB",
"output": "NO"
},
{
"input": "3 3\nRRR\nRRR\nGGG",
"output": "NO"
},
{
"input": "8 6\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR",
"output": "NO"
},
{
"input": "3 4\nRRRR\nRRRR\nGGGG",
"output": "NO"
},
{
"input": "3 4\nRRRR\nRRRR\nRRRR",
"output": "NO"
},
{
"input": "6 1\nR\nR\nR\nR\nR\nR",
"output": "NO"
},
{
"input": "1 6\nRRBBGG",
"output": "YES"
},
{
"input": "1 6\nRGBRGB",
"output": "NO"
},
{
"input": "3 4\nRRRR\nGGGG\nRRRR",
"output": "NO"
},
{
"input": "3 3\nRRB\nGRG\nGBB",
"output": "NO"
},
{
"input": "3 7\nRRGGBBB\nRRGGBBB\nRRGGBBB",
"output": "NO"
},
{
"input": "3 1\nG\nR\nR",
"output": "NO"
},
{
"input": "2 3\nRGG\nRBB",
"output": "NO"
},
{
"input": "3 3\nRRG\nGGG\nBBB",
"output": "NO"
},
{
"input": "3 3\nRGB\nRBB\nRGB",
"output": "NO"
},
{
"input": "3 3\nRGR\nRGB\nRGB",
"output": "NO"
},
{
"input": "3 1\nB\nR\nR",
"output": "NO"
},
{
"input": "1 3\nGRR",
"output": "NO"
},
{
"input": "4 4\nRRRR\nGGGG\nBBBB\nBBBB",
"output": "NO"
},
{
"input": "1 3\nGGR",
"output": "NO"
},
{
"input": "3 3\nRGB\nGGB\nRGB",
"output": "NO"
},
{
"input": "3 3\nRGR\nGGG\nBBB",
"output": "NO"
},
{
"input": "6 6\nRRRRRR\nGGGGGG\nGGGGGG\nGGGGGG\nBBBBBB\nBBBBBB",
"output": "NO"
},
{
"input": "6 6\nRRRRRR\nRRRRRR\nGGGGGG\nBBBBBB\nBBBBBB\nBBBBBB",
"output": "NO"
},
{
"input": "3 1\nG\nB\nR",
"output": "YES"
},
{
"input": "3 3\nGGB\nRGB\nRGB",
"output": "NO"
},
{
"input": "3 3\nGRR\nGGG\nBBB",
"output": "NO"
},
{
"input": "6 6\nRRRRRR\nRRRRRR\nGGGGGG\nGGGGGG\nBBBBBB\nRRRRRR",
"output": "NO"
},
{
"input": "3 3\nRRR\nGBG\nBBB",
"output": "NO"
},
{
"input": "3 8\nRRGGBBBB\nRRGGBBBB\nRRGGBBBB",
"output": "NO"
},
{
"input": "2 2\nRR\nGG",
"output": "NO"
},
{
"input": "3 3\nRGB\nRGR\nRGB",
"output": "NO"
},
{
"input": "1 3\nRBG",
"output": "YES"
},
{
"input": "2 6\nRRGGBB\nGGRRBB",
"output": "NO"
},
{
"input": "6 2\nRR\nGG\nBB\nRR\nGG\nBB",
"output": "NO"
},
{
"input": "1 5\nRRGGB",
"output": "NO"
},
{
"input": "1 2\nRG",
"output": "NO"
},
{
"input": "1 6\nRGBRBG",
"output": "NO"
},
{
"input": "1 6\nRRRGGB",
"output": "NO"
},
{
"input": "1 3\nRGB",
"output": "YES"
},
{
"input": "4 3\nRRR\nBBR\nGBB\nGGG",
"output": "NO"
},
{
"input": "6 3\nRRR\nBBB\nBBB\nBBB\nGGG\nGGG",
"output": "NO"
},
{
"input": "3 3\nRBG\nRBG\nRBG",
"output": "YES"
},
{
"input": "6 3\nRRR\nBBB\nGGG\nRRR\nBBB\nGGG",
"output": "NO"
},
{
"input": "1 4\nRGBB",
"output": "NO"
},
{
"input": "6 6\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR",
"output": "NO"
},
{
"input": "6 5\nRRRRR\nRRRRR\nGGGGG\nGGGGG\nRRRRR\nRRRRR",
"output": "NO"
},
{
"input": "3 3\nRGB\nBRG\nGBR",
"output": "NO"
},
{
"input": "6 10\nRRRRRRRRRR\nGGGGGGGGGG\nBBBBBBBBBB\nRRRRRRRRRR\nGGGGGGGGGG\nBBBBBBBBBB",
"output": "NO"
},
{
"input": "20 6\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB",
"output": "YES"
},
{
"input": "4 1\nR\nG\nB\nR",
"output": "NO"
},
{
"input": "1 4\nRGBR",
"output": "NO"
},
{
"input": "2 4\nRGBB\nRRGB",
"output": "NO"
}
] | 1,520,609,900 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 77 | 5,632,000 | # KALAM
n , m = map(int , input().split())
l = []
for i in range(n):
l.append([])
s = input()
for j in s:
l[i].append(j)
A = 'YES'
a = True;b = True
if(n % 3 != 0 and m % 3 != 0):A = 'NO'
if(n % 3 == 0):
s = l[0][0]
for i in range(n // 3):
for j in range(m):
if(l[i][j] != s):
a = False
s = l[n // 3][0]
for i in range(n // 3 , n // 3 * 2):
for j in range(m):
if(l[i][j] != s):
a = False
s = l[n // 3 * 2][0]
for i in range(n // 3 * 2 , n):
for j in range(m):
if(l[i][j] != s):
a = False
else :a = False
if(m % 3 == 0):
s = l[0][0]
for i in range(n):
for j in range(m // 3):
if(l[i][j] != s):
b = False
s = l[0][m // 3]
for i in range(n):
for j in range(m // 3 , m // 3 * 2):
if(l[i][j] != s):
b = False
s = l[0][m // 3 * 2]
for i in range(n):
for j in range(m // 3 * 2 , m):
if(l[i][j] != s):
b = False
else :b = False
if((not a) and (not b) ):
A = 'NO'
print(A)
| Title: Flag of Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The flag of Berland is such rectangular field *n*<=×<=*m* that satisfies following conditions:
- Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. - Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. - Each color should be used in exactly one stripe.
You are given a field *n*<=×<=*m*, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input Specification:
The first line contains two integer numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the field.
Each of the following *n* lines consisting of *m* characters 'R', 'G' and 'B' — the description of the field.
Output Specification:
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Demo Input:
['6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG\n', '4 3\nBRG\nBRG\nBRG\nBRG\n', '6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB\n', '4 4\nRRRR\nRRRR\nBBBB\nGGGG\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n', 'NO\n']
Note:
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1. | ```python
# KALAM
n , m = map(int , input().split())
l = []
for i in range(n):
l.append([])
s = input()
for j in s:
l[i].append(j)
A = 'YES'
a = True;b = True
if(n % 3 != 0 and m % 3 != 0):A = 'NO'
if(n % 3 == 0):
s = l[0][0]
for i in range(n // 3):
for j in range(m):
if(l[i][j] != s):
a = False
s = l[n // 3][0]
for i in range(n // 3 , n // 3 * 2):
for j in range(m):
if(l[i][j] != s):
a = False
s = l[n // 3 * 2][0]
for i in range(n // 3 * 2 , n):
for j in range(m):
if(l[i][j] != s):
a = False
else :a = False
if(m % 3 == 0):
s = l[0][0]
for i in range(n):
for j in range(m // 3):
if(l[i][j] != s):
b = False
s = l[0][m // 3]
for i in range(n):
for j in range(m // 3 , m // 3 * 2):
if(l[i][j] != s):
b = False
s = l[0][m // 3 * 2]
for i in range(n):
for j in range(m // 3 * 2 , m):
if(l[i][j] != s):
b = False
else :b = False
if((not a) and (not b) ):
A = 'NO'
print(A)
``` | 0 |
|
1,009 | E | Intercity Travelling | PROGRAMMING | 2,000 | [
"combinatorics",
"math",
"probabilities"
] | null | null | Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.
The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance between Moscow and Saratov is $n$ km. Let's say that Moscow is situated at the point with coordinate $0$ km, and Saratov — at coordinate $n$ km.
Driving for a long time may be really difficult. Formally, if Leha has already covered $i$ kilometers since he stopped to have a rest, he considers the difficulty of covering $(i + 1)$-th kilometer as $a_{i + 1}$. It is guaranteed that for every $i \in [1, n - 1]$ $a_i \le a_{i + 1}$. The difficulty of the journey is denoted as the sum of difficulties of each kilometer in the journey.
Fortunately, there may be some rest sites between Moscow and Saratov. Every integer point from $1$ to $n - 1$ may contain a rest site. When Leha enters a rest site, he may have a rest, and the next kilometer will have difficulty $a_1$, the kilometer after it — difficulty $a_2$, and so on.
For example, if $n = 5$ and there is a rest site in coordinate $2$, the difficulty of journey will be $2a_1 + 2a_2 + a_3$: the first kilometer will have difficulty $a_1$, the second one — $a_2$, then Leha will have a rest, and the third kilometer will have difficulty $a_1$, the fourth — $a_2$, and the last one — $a_3$. Another example: if $n = 7$ and there are rest sites in coordinates $1$ and $5$, the difficulty of Leha's journey is $3a_1 + 2a_2 + a_3 + a_4$.
Leha doesn't know which integer points contain rest sites. So he has to consider every possible situation. Obviously, there are $2^{n - 1}$ different distributions of rest sites (two distributions are different if there exists some point $x$ such that it contains a rest site in exactly one of these distributions). Leha considers all these distributions to be equiprobable. He wants to calculate $p$ — the expected value of difficulty of his journey.
Obviously, $p \cdot 2^{n - 1}$ is an integer number. You have to calculate it modulo $998244353$. | The first line contains one number $n$ ($1 \le n \le 10^6$) — the distance from Moscow to Saratov.
The second line contains $n$ integer numbers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_1 \le a_2 \le \dots \le a_n \le 10^6$), where $a_i$ is the difficulty of $i$-th kilometer after Leha has rested. | Print one number — $p \cdot 2^{n - 1}$, taken modulo $998244353$. | [
"2\n1 2\n",
"4\n1 3 3 7\n"
] | [
"5\n",
"60\n"
] | none | 0 | [
{
"input": "2\n1 2",
"output": "5"
},
{
"input": "4\n1 3 3 7",
"output": "60"
},
{
"input": "100\n3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 76 76 77 77 78 78 79 80 81 81 82 82 84 85 86 87 87 87 89 91 92 92 92 92 97 98 99 100 100",
"output": "758086002"
},
{
"input": "1\n12",
"output": "12"
}
] | 1,531,822,689 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | #/user/bin/python
if __name__ == '__main__':
sum = 0
_n = input()
_s = input()
s = _s.split(' ')
n = int(_n)
taxi = 0
group3 = 0
group2 = 0
group1 = 0
for i in range(0, n):
if int(s[i]) == 4:
taxi += 1
elif int(s[i]) == 3:
group3 += 1
elif int(s[i]) == 2:
group2 += 1
elif int(s[i]) == 1:
group1 += 1
print()
if group2 >= 2:
taxi += group2/2
if group2%2 != 0:
group2 = 1
else:
group2 = 0
if group3 <= group1:
taxi += group3
group1 -= group3
elif group3 > group1:
taxi += group3
if group1 >= 4:
if group1%4 == 0:
taxi += group1/4
if (group2 > 0) or (group1 == 2) or (group1 == 1):
taxi += group2
group1 -= group2*2
if group1 > 0:
taxi += 1
print(int(taxi)) | Title: Intercity Travelling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.
The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance between Moscow and Saratov is $n$ km. Let's say that Moscow is situated at the point with coordinate $0$ km, and Saratov — at coordinate $n$ km.
Driving for a long time may be really difficult. Formally, if Leha has already covered $i$ kilometers since he stopped to have a rest, he considers the difficulty of covering $(i + 1)$-th kilometer as $a_{i + 1}$. It is guaranteed that for every $i \in [1, n - 1]$ $a_i \le a_{i + 1}$. The difficulty of the journey is denoted as the sum of difficulties of each kilometer in the journey.
Fortunately, there may be some rest sites between Moscow and Saratov. Every integer point from $1$ to $n - 1$ may contain a rest site. When Leha enters a rest site, he may have a rest, and the next kilometer will have difficulty $a_1$, the kilometer after it — difficulty $a_2$, and so on.
For example, if $n = 5$ and there is a rest site in coordinate $2$, the difficulty of journey will be $2a_1 + 2a_2 + a_3$: the first kilometer will have difficulty $a_1$, the second one — $a_2$, then Leha will have a rest, and the third kilometer will have difficulty $a_1$, the fourth — $a_2$, and the last one — $a_3$. Another example: if $n = 7$ and there are rest sites in coordinates $1$ and $5$, the difficulty of Leha's journey is $3a_1 + 2a_2 + a_3 + a_4$.
Leha doesn't know which integer points contain rest sites. So he has to consider every possible situation. Obviously, there are $2^{n - 1}$ different distributions of rest sites (two distributions are different if there exists some point $x$ such that it contains a rest site in exactly one of these distributions). Leha considers all these distributions to be equiprobable. He wants to calculate $p$ — the expected value of difficulty of his journey.
Obviously, $p \cdot 2^{n - 1}$ is an integer number. You have to calculate it modulo $998244353$.
Input Specification:
The first line contains one number $n$ ($1 \le n \le 10^6$) — the distance from Moscow to Saratov.
The second line contains $n$ integer numbers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_1 \le a_2 \le \dots \le a_n \le 10^6$), where $a_i$ is the difficulty of $i$-th kilometer after Leha has rested.
Output Specification:
Print one number — $p \cdot 2^{n - 1}$, taken modulo $998244353$.
Demo Input:
['2\n1 2\n', '4\n1 3 3 7\n']
Demo Output:
['5\n', '60\n']
Note:
none | ```python
#/user/bin/python
if __name__ == '__main__':
sum = 0
_n = input()
_s = input()
s = _s.split(' ')
n = int(_n)
taxi = 0
group3 = 0
group2 = 0
group1 = 0
for i in range(0, n):
if int(s[i]) == 4:
taxi += 1
elif int(s[i]) == 3:
group3 += 1
elif int(s[i]) == 2:
group2 += 1
elif int(s[i]) == 1:
group1 += 1
print()
if group2 >= 2:
taxi += group2/2
if group2%2 != 0:
group2 = 1
else:
group2 = 0
if group3 <= group1:
taxi += group3
group1 -= group3
elif group3 > group1:
taxi += group3
if group1 >= 4:
if group1%4 == 0:
taxi += group1/4
if (group2 > 0) or (group1 == 2) or (group1 == 1):
taxi += group2
group1 -= group2*2
if group1 > 0:
taxi += 1
print(int(taxi))
``` | 0 |
|
960 | C | Subsequence Counting | PROGRAMMING | 1,700 | [
"bitmasks",
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size *n* has 2*n*<=-<=1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence <=-<= Minimum_element_of_subsequence <=≥<=*d*
Pikachu was finally left with *X* subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers *X* and *d*. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 1018.
Note the number of elements in the output array should not be more than 104. If no answer is possible, print <=-<=1. | The only line of input consists of two space separated integers *X* and *d* (1<=≤<=*X*,<=*d*<=≤<=109). | Output should consist of two lines.
First line should contain a single integer *n* (1<=≤<=*n*<=≤<=10<=000)— the number of integers in the final array.
Second line should consist of *n* space separated integers — *a*1,<=*a*2,<=... ,<=*a**n* (1<=≤<=*a**i*<=<<=1018).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them. | [
"10 5\n",
"4 2\n"
] | [
"6\n5 50 7 15 6 100",
"4\n10 100 1000 10000"
] | In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence ≥ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence ≥ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | 1,500 | [
{
"input": "10 5",
"output": "6\n1 1 1 7 13 19 "
},
{
"input": "4 2",
"output": "3\n1 1 4 "
},
{
"input": "4 1",
"output": "3\n1 1 3 "
},
{
"input": "1 1",
"output": "1\n1 "
},
{
"input": "63 1",
"output": "21\n1 1 1 1 1 3 3 3 3 5 5 5 7 7 9 11 13 15 17 19 21 "
},
{
"input": "98 88",
"output": "15\n1 1 1 1 1 1 90 90 90 90 90 179 268 357 446 "
},
{
"input": "746 173",
"output": "37\n1 1 1 1 1 1 1 1 1 175 175 175 175 175 175 175 349 349 349 349 349 349 523 523 523 523 523 697 697 697 871 1045 1219 1393 1567 1741 1915 "
},
{
"input": "890 553",
"output": "43\n1 1 1 1 1 1 1 1 1 555 555 555 555 555 555 555 555 1109 1109 1109 1109 1109 1109 1663 1663 1663 1663 1663 2217 2217 2217 2217 2771 2771 2771 3325 3879 4433 4987 5541 6095 6649 7203 "
},
{
"input": "883 1000",
"output": "40\n1 1 1 1 1 1 1 1 1 1002 1002 1002 1002 1002 1002 1002 1002 2003 2003 2003 2003 2003 2003 3004 3004 3004 3004 3004 4005 4005 4005 4005 5006 6007 7008 8009 9010 10011 11012 12013 "
},
{
"input": "1 1000",
"output": "1\n1 "
},
{
"input": "695 188",
"output": "35\n1 1 1 1 1 1 1 1 1 190 190 190 190 190 190 190 379 379 379 379 379 568 568 568 568 757 757 946 1135 1324 1513 1702 1891 2080 2269 "
},
{
"input": "2060 697",
"output": "19\n1 1 1 1 1 1 1 1 1 1 1 699 699 699 1397 1397 2095 2793 3491 "
},
{
"input": "70 3321",
"output": "12\n1 1 1 1 1 1 3323 3323 6645 9967 13289 16611 "
},
{
"input": "6358 1646",
"output": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1648 1648 1648 1648 1648 1648 1648 1648 1648 1648 1648 3295 3295 3295 3295 3295 3295 3295 4942 4942 4942 4942 4942 4942 6589 6589 6589 6589 8236 8236 9883 11530 13177 14824 16471 18118 19765 21412 "
},
{
"input": "167959139 481199252",
"output": "154\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 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 481199254 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 962398507 1443597760 1443597760 1443597760..."
},
{
"input": "641009859 54748096",
"output": "192\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 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 54748098 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 109496195 1094..."
},
{
"input": "524125987 923264237",
"output": "289\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 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 923264239 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846528477 1846..."
},
{
"input": "702209411 496813081",
"output": "276\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 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 496813083 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 993626165 99362616..."
},
{
"input": "585325539 365329221",
"output": "243\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 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 365329223 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 730658445 73065844..."
},
{
"input": "58376259 643910770",
"output": "196\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 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 643910772 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821543 1287821..."
},
{
"input": "941492387 72235422",
"output": "194\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 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 72235424 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470847 144470..."
},
{
"input": "824608515 940751563",
"output": "192\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 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 940751565 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 1881503129 188..."
},
{
"input": "2691939 514300407",
"output": "107\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 514300409 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1028600817 1542901225 1542901225 1542901225 1542901225 1542901225 1542901225 1542901225 1542901225 1542901225..."
},
{
"input": "802030518 598196518",
"output": "283\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 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 598196520 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 1196393039 11..."
},
{
"input": "685146646 26521171",
"output": "199\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 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 26521173 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 53042345 5304234..."
},
{
"input": "863230070 895037311",
"output": "290\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 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 895037313 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 1790074625 179..."
},
{
"input": "41313494 468586155",
"output": "194\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 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 468586157 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 937172313 1405758469 1405758469 1405..."
},
{
"input": "219396918 747167704",
"output": "226\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 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 747167706 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 1494335411 14943..."
},
{
"input": "102513046 615683844",
"output": "179\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 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 615683846 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 1231367691 123136..."
},
{
"input": "985629174 189232688",
"output": "310\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 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 189232690 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 378465379 37846537..."
},
{
"input": "458679894 912524637",
"output": "272\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 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 912524639 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825049277 1825..."
},
{
"input": "341796022 486073481",
"output": "238\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 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 486073483 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 972146965 ..."
},
{
"input": "519879446 764655030",
"output": "323\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 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 764655032 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529310063 1529..."
},
{
"input": "452405440 586588704",
"output": "268\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 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 586588706 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173177411 1173..."
},
{
"input": "335521569 160137548",
"output": "311\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 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 160137550 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 320275099 ..."
},
{
"input": "808572289 733686393",
"output": "192\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 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 733686395 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 1467372789 146..."
},
{
"input": "691688417 162011045",
"output": "233\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 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 162011047 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 324022093 32402209..."
},
{
"input": "869771841 30527185",
"output": "292\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 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 30527187 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 61054373 6105437..."
},
{
"input": "752887969 604076030",
"output": "195\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 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 604076032 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 1208152063 12..."
},
{
"input": "930971393 177624874",
"output": "344\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 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 177624876 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 355249751 35524975..."
},
{
"input": "109054817 751173719",
"output": "122\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 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 751173721 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 1502347441 150234..."
},
{
"input": "992170945 324722563",
"output": "258\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 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 324722565 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 649445129 64944512..."
},
{
"input": "170254369 48014511",
"output": "164\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 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 48014513 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 96029025 144043537 144043537 144043537 14404353..."
},
{
"input": "248004555 280013594",
"output": "239\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 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 280013596 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 560027191 56..."
},
{
"input": "131120683 148529734",
"output": "235\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 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 148529736 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 297059471 2970..."
},
{
"input": "604171403 722078578",
"output": "158\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 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 722078580 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 1444157159 2..."
},
{
"input": "487287531 295627423",
"output": "243\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 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 295627425 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 591254849 ..."
},
{
"input": "665370955 18919371",
"output": "228\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 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 18919373 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 37838745 3783874..."
},
{
"input": "843454379 297500920",
"output": "209\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 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 297500922 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 595001843 59500184..."
},
{
"input": "21537803 166017060",
"output": "116\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 166017062 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 332034123 498051184 498051184 498051184 498051184 49805118..."
},
{
"input": "904653932 739565904",
"output": "323\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 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 739565906 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 1479131811 147..."
},
{
"input": "787770060 313114749",
"output": "293\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 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 313114751 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 626229501 62622950..."
},
{
"input": "260820780 181630889",
"output": "271\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 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 181630891 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 363261781 36..."
},
{
"input": "43603670 268405779",
"output": "182\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 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 268405781 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 536811561 805217341 805217341 805217..."
},
{
"input": "1000000000 1000000000",
"output": "274\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 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 1000000002 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 2000000003 20000000..."
},
{
"input": "15000 1",
"output": "66\n1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 11 11 11 11 13 13 13 15 17 19 21 23 25 27 "
},
{
"input": "1048576 1",
"output": "21\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 "
},
{
"input": "1000000000 1",
"output": "274\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 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 19 ..."
},
{
"input": "100000000 1",
"output": "232\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 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 19 19 19 19 19 19 19 19 19 19 19 19 19 19 21 21 21 21 21 21 21 21 2..."
},
{
"input": "1000000 1",
"output": "106\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 15 17 19 21 23 25 27 "
},
{
"input": "536870911 1",
"output": "435\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 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 ..."
},
{
"input": "10009 1",
"output": "54\n1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 9 9 9 9 11 11 11 13 15 17 19 21 23 25 "
},
{
"input": "10001 1",
"output": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 9 9 9 9 11 13 15 17 19 21 "
}
] | 1,535,370,987 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 14 | 1,000 | 102,400 | n,d=map(int,input().split())
print(n)
s=1
for i in range(n):
print(s,end=' ')
s+=d+1
| Title: Subsequence Counting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size *n* has 2*n*<=-<=1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence <=-<= Minimum_element_of_subsequence <=≥<=*d*
Pikachu was finally left with *X* subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers *X* and *d*. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 1018.
Note the number of elements in the output array should not be more than 104. If no answer is possible, print <=-<=1.
Input Specification:
The only line of input consists of two space separated integers *X* and *d* (1<=≤<=*X*,<=*d*<=≤<=109).
Output Specification:
Output should consist of two lines.
First line should contain a single integer *n* (1<=≤<=*n*<=≤<=10<=000)— the number of integers in the final array.
Second line should consist of *n* space separated integers — *a*1,<=*a*2,<=... ,<=*a**n* (1<=≤<=*a**i*<=<<=1018).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
Demo Input:
['10 5\n', '4 2\n']
Demo Output:
['6\n5 50 7 15 6 100', '4\n10 100 1000 10000']
Note:
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence ≥ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence ≥ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid. | ```python
n,d=map(int,input().split())
print(n)
s=1
for i in range(n):
print(s,end=' ')
s+=d+1
``` | 0 |
|
886 | B | Vlad and Cafes | PROGRAMMING | 1,000 | [] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe. | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted. | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | 1,000 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000 1000",
"output": "100"
},
{
"input": "8\n200000 1 200000 1 200000 1 200000 2",
"output": "1"
},
{
"input": "5\n20000 1 2 3 4",
"output": "20000"
},
{
"input": "2\n200000 1",
"output": "200000"
},
{
"input": "3\n2 100 2",
"output": "100"
},
{
"input": "2\n10 1",
"output": "10"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "3\n5 5 5",
"output": "5"
},
{
"input": "2\n5 1",
"output": "5"
}
] | 1,510,511,594 | 8,894 | Python 3 | RUNTIME_ERROR | PRETESTS | 0 | 46 | 0 | n = int(input())
cafes = [int(x) for x in input().split()]
for i in range(n-1):
e =cafes[i]
for j in range(i,n):
if cafes[i] == cafes[j]:
e = cafes[j+1]
print(e) | Title: Vlad and Cafes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input Specification:
In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output Specification:
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Demo Input:
['5\n1 3 2 1 2\n', '6\n2 1 2 2 4 1\n']
Demo Output:
['3\n', '2\n']
Note:
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes. | ```python
n = int(input())
cafes = [int(x) for x in input().split()]
for i in range(n-1):
e =cafes[i]
for j in range(i,n):
if cafes[i] == cafes[j]:
e = cafes[j+1]
print(e)
``` | -1 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,643,549,762 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | a = int(input())
b = int(input())
d = int(str(a), 2)
e = int(str(b), 2)
c = d ^ e
e = bin(c)[2:]
print(("0"*(len(str(a))-len(e))+e))
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
a = int(input())
b = int(input())
d = int(str(a), 2)
e = int(str(b), 2)
c = d ^ e
e = bin(c)[2:]
print(("0"*(len(str(a))-len(e))+e))
``` | 0 |
1,011 | A | Stages | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.
There are $n$ stages available. The rocket must contain exactly $k$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.
For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' — $26$ tons.
Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once. | The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket.
The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once. | Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all. | [
"5 3\nxyabd\n",
"7 4\nproblem\n",
"2 2\nab\n",
"12 1\nabaabbaaabbb\n"
] | [
"29",
"34",
"-1",
"1"
] | In the first example, the following rockets satisfy the condition:
- "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$).
Rocket "adx" has the minimal weight, so the answer is $29$.
In the second example, target rocket is "belo". Its weight is $2+5+12+15=34$.
In the third example, $n=k=2$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1. | 500 | [
{
"input": "5 3\nxyabd",
"output": "29"
},
{
"input": "7 4\nproblem",
"output": "34"
},
{
"input": "2 2\nab",
"output": "-1"
},
{
"input": "12 1\nabaabbaaabbb",
"output": "1"
},
{
"input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "169"
},
{
"input": "50 14\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "1 1\na",
"output": "1"
},
{
"input": "50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "1"
},
{
"input": "50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "13 13\nuwgmkyqeiaocs",
"output": "169"
},
{
"input": "13 13\nhzdxpbfvrltnj",
"output": "182"
},
{
"input": "1 1\nn",
"output": "14"
},
{
"input": "10 8\nsmzeblyjqw",
"output": "113"
},
{
"input": "20 20\ntzmvhskkyugkuuxpvtbh",
"output": "-1"
},
{
"input": "30 15\nwjzolzzkfulwgioksfxmcxmnnjtoav",
"output": "-1"
},
{
"input": "40 30\nxumfrflllrrgswehqtsskefixhcxjrxbjmrpsshv",
"output": "-1"
},
{
"input": "50 31\nahbyyoxltryqdmvenemaqnbakglgqolxnaifnqtoclnnqiabpz",
"output": "-1"
},
{
"input": "10 7\niuiukrxcml",
"output": "99"
},
{
"input": "38 2\nvjzarfykmrsrvwbwfwldsulhxtykmjbnwmdufa",
"output": "5"
},
{
"input": "12 6\nfwseyrarkwcd",
"output": "61"
},
{
"input": "2 2\nac",
"output": "4"
},
{
"input": "1 1\nc",
"output": "3"
},
{
"input": "2 2\nad",
"output": "5"
},
{
"input": "2 1\nac",
"output": "1"
},
{
"input": "4 3\nadjz",
"output": "15"
},
{
"input": "3 3\naoz",
"output": "42"
},
{
"input": "3 1\nzzz",
"output": "26"
},
{
"input": "2 1\nxz",
"output": "24"
},
{
"input": "5 1\naaddd",
"output": "1"
}
] | 1,584,113,695 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 108 | 307,200 | def mi():
return map(int, input().split())
n,k = mi()
s = list(input())
s.sort()
for i in range(n):
s[i] = ord(s[i])-ord('a')+1
ans = s[0]
k-=1
for i in range(1,n):
if not k:
break
if s[i]-s[i-1]>1:
ans+=s[i]
k-=1
if k:
print (-1)
else:
print(ans)
| Title: Stages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.
There are $n$ stages available. The rocket must contain exactly $k$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.
For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' — $26$ tons.
Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once.
Input Specification:
The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket.
The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once.
Output Specification:
Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.
Demo Input:
['5 3\nxyabd\n', '7 4\nproblem\n', '2 2\nab\n', '12 1\nabaabbaaabbb\n']
Demo Output:
['29', '34', '-1', '1']
Note:
In the first example, the following rockets satisfy the condition:
- "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$).
Rocket "adx" has the minimal weight, so the answer is $29$.
In the second example, target rocket is "belo". Its weight is $2+5+12+15=34$.
In the third example, $n=k=2$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1. | ```python
def mi():
return map(int, input().split())
n,k = mi()
s = list(input())
s.sort()
for i in range(n):
s[i] = ord(s[i])-ord('a')+1
ans = s[0]
k-=1
for i in range(1,n):
if not k:
break
if s[i]-s[i-1]>1:
ans+=s[i]
k-=1
if k:
print (-1)
else:
print(ans)
``` | 0 |
|
721 | C | Journey | PROGRAMMING | 1,800 | [
"dp",
"graphs"
] | null | null | Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace *n*. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than *T* time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace *n* within a time not exceeding *T*. It is guaranteed that there is at least one route from showplace 1 to showplace *n* such that Irina will spend no more than *T* time units passing it. | The first line of the input contains three integers *n*,<=*m* and *T* (2<=≤<=*n*<=≤<=5000,<=<=1<=≤<=*m*<=≤<=5000,<=<=1<=≤<=*T*<=≤<=109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next *m* lines describes roads in Berlatov. *i*-th of them contains 3 integers *u**i*,<=*v**i*,<=*t**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*,<=1<=≤<=*t**i*<=≤<=109), meaning that there is a road starting from showplace *u**i* and leading to showplace *v**i*, and Irina spends *t**i* time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces. | Print the single integer *k* (2<=≤<=*k*<=≤<=*n*) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace *n* within time not exceeding *T*, in the first line.
Print *k* distinct integers in the second line — indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them. | [
"4 3 13\n1 2 5\n2 3 7\n2 4 8\n",
"6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n",
"5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n"
] | [
"3\n1 2 4 \n",
"4\n1 2 4 6 \n",
"3\n1 3 5 \n"
] | none | 1,500 | [
{
"input": "4 3 13\n1 2 5\n2 3 7\n2 4 8",
"output": "3\n1 2 4 "
},
{
"input": "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1",
"output": "4\n1 2 4 6 "
},
{
"input": "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2",
"output": "3\n1 3 5 "
},
{
"input": "10 10 100\n1 4 1\n6 4 1\n9 3 2\n2 7 2\n5 8 11\n1 2 8\n4 10 10\n8 9 2\n7 5 8\n3 6 4",
"output": "10\n1 2 7 5 8 9 3 6 4 10 "
},
{
"input": "10 10 56\n4 8 5\n9 3 11\n2 5 5\n5 9 9\n3 6 1\n1 4 9\n8 7 7\n6 10 1\n1 6 12\n7 2 9",
"output": "3\n1 6 10 "
},
{
"input": "4 4 3\n1 2 1\n2 3 1\n3 4 1\n1 3 1",
"output": "4\n1 2 3 4 "
},
{
"input": "4 4 2\n1 2 1\n2 3 1\n3 4 1\n1 3 1",
"output": "3\n1 3 4 "
},
{
"input": "10 45 8\n1 2 1\n1 3 1\n1 4 1\n1 5 1\n1 6 1\n1 7 1\n1 8 1\n1 9 1\n1 10 1\n2 3 1\n2 4 1\n2 5 1\n2 6 1\n2 7 1\n2 8 1\n2 9 1\n2 10 1\n3 4 1\n3 5 1\n3 6 1\n3 7 1\n3 8 1\n3 9 1\n3 10 1\n4 5 1\n4 6 1\n4 7 1\n4 8 1\n4 9 1\n4 10 1\n5 6 1\n5 7 1\n5 8 1\n5 9 1\n5 10 1\n6 7 1\n6 8 1\n6 9 1\n6 10 1\n7 8 1\n7 9 1\n7 10 1\n8 9 1\n8 10 1\n9 10 1",
"output": "9\n1 2 3 4 5 6 7 8 10 "
},
{
"input": "2 1 1\n1 2 1",
"output": "2\n1 2 "
},
{
"input": "12 12 8\n1 2 2\n2 3 5\n3 12 1\n4 5 1000000000\n1 7 1\n7 6 3\n6 12 1\n1 9 1\n9 10 1\n10 11 1\n11 8 1\n8 12 1",
"output": "6\n1 9 10 11 8 12 "
},
{
"input": "12 12 5\n1 2 2\n2 3 5\n3 12 1\n4 5 1000000000\n1 7 1\n7 6 3\n6 12 1\n1 9 1\n9 10 1\n10 11 1\n11 8 1\n8 12 1",
"output": "6\n1 9 10 11 8 12 "
},
{
"input": "12 12 4\n1 2 2\n2 3 5\n3 12 1\n4 5 1000000000\n1 7 1\n7 6 2\n6 12 1\n1 9 1\n9 10 1\n10 11 1\n11 8 1\n8 12 1",
"output": "4\n1 7 6 12 "
},
{
"input": "11 11 9\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 11 1\n11 10 1\n10 9 1",
"output": "8\n1 4 5 6 3 7 8 11 "
},
{
"input": "11 11 7\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 11 1\n11 10 1\n10 9 1",
"output": "8\n1 4 5 6 3 7 8 11 "
},
{
"input": "11 11 6\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 11 1\n11 10 1\n10 9 1",
"output": "6\n1 2 3 7 8 11 "
},
{
"input": "12 12 9\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6 3 1\n3 7 1\n7 8 1\n8 12 1\n12 10 1\n10 9 1\n11 1 1",
"output": "8\n1 4 5 6 3 7 8 12 "
},
{
"input": "4 4 120\n1 2 11\n1 3 20\n2 3 10\n3 4 100",
"output": "3\n1 3 4 "
},
{
"input": "4 4 10\n2 1 1\n2 3 1\n1 3 1\n3 4 1",
"output": "3\n1 3 4 "
},
{
"input": "5 5 200\n1 2 100\n2 4 100\n1 3 1\n3 4 1\n4 5 1",
"output": "4\n1 3 4 5 "
},
{
"input": "5 5 2\n1 2 1\n1 3 1\n3 4 1\n2 5 1\n4 2 1",
"output": "3\n1 2 5 "
},
{
"input": "4 4 1000000000\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n1 4 1000000000",
"output": "2\n1 4 "
}
] | 1,616,490,453 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 3,000 | 103,628,800 | from sys import stdout
from sys import stdin
def get():
return stdin.readline().strip()
def getf():
return [int(i) for i in get().split()]
def put(a, end = "\n"):
stdout.write(str(a) + end)
def putf(a, sep = " ", end = "\n"):
stdout.write(sep.join([str(i) for i in a]) + end)
#from collections import defaultdict as dd
def bruh():
n, m, t = getf()
g = [[] for i in range(n + 1)]
for i in range(m):
v, u, ti = getf()
g[v].append([u, ti])
#g[u].append([v, ti])
inf = 10 ** 18 + 7
a = [[inf] * (n + 1) for i in range(n + 1)]
a[1][0] = 0
ans = 0
par = dict()
for k in range(1, n + 1):
for i in range(1, n + 1):
for e in g[i]:
if(a[e[0]][k] > a[i][k - 1] + e[1]):
a[e[0]][k] = a[i][k - 1] + e[1]
par[e[0], k] = i
res = 0
for j in range(1, n + 1):
if(a[n][j] <= t):
res = j
put(res + 1)
ans = [n]
cur = n
#print(res, par)
while(cur != 1):
ans.append(par[cur, res])
cur = par[cur, res]
res -= 1
#for i in a:
# putf(i)
putf(ans[ :: -1])
bruh()
| Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are *n* showplaces in the city, numbered from 1 to *n*, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace *n*. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than *T* time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace *n* within a time not exceeding *T*. It is guaranteed that there is at least one route from showplace 1 to showplace *n* such that Irina will spend no more than *T* time units passing it.
Input Specification:
The first line of the input contains three integers *n*,<=*m* and *T* (2<=≤<=*n*<=≤<=5000,<=<=1<=≤<=*m*<=≤<=5000,<=<=1<=≤<=*T*<=≤<=109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next *m* lines describes roads in Berlatov. *i*-th of them contains 3 integers *u**i*,<=*v**i*,<=*t**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*,<=1<=≤<=*t**i*<=≤<=109), meaning that there is a road starting from showplace *u**i* and leading to showplace *v**i*, and Irina spends *t**i* time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Output Specification:
Print the single integer *k* (2<=≤<=*k*<=≤<=*n*) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace *n* within time not exceeding *T*, in the first line.
Print *k* distinct integers in the second line — indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
Demo Input:
['4 3 13\n1 2 5\n2 3 7\n2 4 8\n', '6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n', '5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n']
Demo Output:
['3\n1 2 4 \n', '4\n1 2 4 6 \n', '3\n1 3 5 \n']
Note:
none | ```python
from sys import stdout
from sys import stdin
def get():
return stdin.readline().strip()
def getf():
return [int(i) for i in get().split()]
def put(a, end = "\n"):
stdout.write(str(a) + end)
def putf(a, sep = " ", end = "\n"):
stdout.write(sep.join([str(i) for i in a]) + end)
#from collections import defaultdict as dd
def bruh():
n, m, t = getf()
g = [[] for i in range(n + 1)]
for i in range(m):
v, u, ti = getf()
g[v].append([u, ti])
#g[u].append([v, ti])
inf = 10 ** 18 + 7
a = [[inf] * (n + 1) for i in range(n + 1)]
a[1][0] = 0
ans = 0
par = dict()
for k in range(1, n + 1):
for i in range(1, n + 1):
for e in g[i]:
if(a[e[0]][k] > a[i][k - 1] + e[1]):
a[e[0]][k] = a[i][k - 1] + e[1]
par[e[0], k] = i
res = 0
for j in range(1, n + 1):
if(a[n][j] <= t):
res = j
put(res + 1)
ans = [n]
cur = n
#print(res, par)
while(cur != 1):
ans.append(par[cur, res])
cur = par[cur, res]
res -= 1
#for i in a:
# putf(i)
putf(ans[ :: -1])
bruh()
``` | 0 |
|
964 | A | Splits | PROGRAMMING | 800 | [
"math"
] | null | null | Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$.
The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $[1, 1, 1, 1, 1]$ is $5$, the weight of the split $[5, 5, 3, 3, 3]$ is $2$ and the weight of the split $[9]$ equals $1$.
For a given $n$, find out the number of different weights of its splits. | The first line contains one integer $n$ ($1 \leq n \leq 10^9$). | Output one integer — the answer to the problem. | [
"7\n",
"8\n",
"9\n"
] | [
"4\n",
"5\n",
"5\n"
] | In the first sample, there are following possible weights of splits of $7$:
Weight 1: [$\textbf 7$]
Weight 2: [$\textbf 3$, $\textbf 3$, 1]
Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1]
Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$] | 500 | [
{
"input": "7",
"output": "4"
},
{
"input": "8",
"output": "5"
},
{
"input": "9",
"output": "5"
},
{
"input": "1",
"output": "1"
},
{
"input": "286",
"output": "144"
},
{
"input": "48",
"output": "25"
},
{
"input": "941",
"output": "471"
},
{
"input": "45154",
"output": "22578"
},
{
"input": "60324",
"output": "30163"
},
{
"input": "91840",
"output": "45921"
},
{
"input": "41909",
"output": "20955"
},
{
"input": "58288",
"output": "29145"
},
{
"input": "91641",
"output": "45821"
},
{
"input": "62258",
"output": "31130"
},
{
"input": "79811",
"output": "39906"
},
{
"input": "88740",
"output": "44371"
},
{
"input": "12351",
"output": "6176"
},
{
"input": "1960",
"output": "981"
},
{
"input": "29239",
"output": "14620"
},
{
"input": "85801",
"output": "42901"
},
{
"input": "43255",
"output": "21628"
},
{
"input": "13439",
"output": "6720"
},
{
"input": "35668",
"output": "17835"
},
{
"input": "19122",
"output": "9562"
},
{
"input": "60169",
"output": "30085"
},
{
"input": "50588",
"output": "25295"
},
{
"input": "2467",
"output": "1234"
},
{
"input": "39315",
"output": "19658"
},
{
"input": "29950",
"output": "14976"
},
{
"input": "17286",
"output": "8644"
},
{
"input": "7359066",
"output": "3679534"
},
{
"input": "1016391",
"output": "508196"
},
{
"input": "7928871",
"output": "3964436"
},
{
"input": "3968891",
"output": "1984446"
},
{
"input": "2636452",
"output": "1318227"
},
{
"input": "5076901",
"output": "2538451"
},
{
"input": "9870265",
"output": "4935133"
},
{
"input": "2453786",
"output": "1226894"
},
{
"input": "7263670",
"output": "3631836"
},
{
"input": "1890845",
"output": "945423"
},
{
"input": "574128507",
"output": "287064254"
},
{
"input": "648476655",
"output": "324238328"
},
{
"input": "97349542",
"output": "48674772"
},
{
"input": "716489761",
"output": "358244881"
},
{
"input": "858771038",
"output": "429385520"
},
{
"input": "520778784",
"output": "260389393"
},
{
"input": "439004204",
"output": "219502103"
},
{
"input": "589992198",
"output": "294996100"
},
{
"input": "371106544",
"output": "185553273"
},
{
"input": "894241590",
"output": "447120796"
},
{
"input": "123957268",
"output": "61978635"
},
{
"input": "234149297",
"output": "117074649"
},
{
"input": "789954052",
"output": "394977027"
},
{
"input": "667978920",
"output": "333989461"
},
{
"input": "154647261",
"output": "77323631"
},
{
"input": "751453521",
"output": "375726761"
},
{
"input": "848862308",
"output": "424431155"
},
{
"input": "323926781",
"output": "161963391"
},
{
"input": "576768825",
"output": "288384413"
},
{
"input": "31293802",
"output": "15646902"
},
{
"input": "2",
"output": "2"
},
{
"input": "1000000000",
"output": "500000001"
},
{
"input": "3",
"output": "2"
}
] | 1,523,974,159 | 259 | Python 3 | COMPILATION_ERROR | PRETESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
int n ;
cin >> n ;
ll x = n/2 + 1 ;
cout<<x;
return 0;
} | Title: Splits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$.
The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $[1, 1, 1, 1, 1]$ is $5$, the weight of the split $[5, 5, 3, 3, 3]$ is $2$ and the weight of the split $[9]$ equals $1$.
For a given $n$, find out the number of different weights of its splits.
Input Specification:
The first line contains one integer $n$ ($1 \leq n \leq 10^9$).
Output Specification:
Output one integer — the answer to the problem.
Demo Input:
['7\n', '8\n', '9\n']
Demo Output:
['4\n', '5\n', '5\n']
Note:
In the first sample, there are following possible weights of splits of $7$:
Weight 1: [$\textbf 7$]
Weight 2: [$\textbf 3$, $\textbf 3$, 1]
Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1]
Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$] | ```python
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
int n ;
cin >> n ;
ll x = n/2 + 1 ;
cout<<x;
return 0;
}
``` | -1 |
|
595 | A | Vitaly and Night | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats numbered from 1 to *m*, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·*m* from left to right, then the *j*-th flat of the *i*-th floor has windows 2·*j*<=-<=1 and 2·*j* in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on, then the *i*-th character of this line is '1', otherwise it is '0'. | Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off. | 500 | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 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 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "99"
},
{
"input": "1 100\n0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "6"
},
{
"input": "1 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "100"
},
{
"input": "100 1\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0",
"output": "8"
},
{
"input": "100 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\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": "1 1\n0 0",
"output": "0"
},
{
"input": "1 1\n0 1",
"output": "1"
},
{
"input": "1 1\n1 0",
"output": "1"
},
{
"input": "1 1\n1 1",
"output": "1"
}
] | 1,529,501,681 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 155 | 614,400 | n,m=list(map(int,input().split()))
c=0
for i in range(n):
l=list(map(int,input().split()))
for i in range(0,len(l),2):
if l[i]==0 and l[i+1]==1 or l[i]==1 and l[i+1]==1 or l[i]==1 and l[i+1]==0:
c+=1
i+=1
#i+=1
print(c) | Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats numbered from 1 to *m*, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·*m* from left to right, then the *j*-th flat of the *i*-th floor has windows 2·*j*<=-<=1 and 2·*j* in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on, then the *i*-th character of this line is '1', otherwise it is '0'.
Output Specification:
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Demo Input:
['2 2\n0 0 0 1\n1 0 1 1\n', '1 3\n1 1 0 1 0 0\n']
Demo Output:
['3\n', '2\n']
Note:
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off. | ```python
n,m=list(map(int,input().split()))
c=0
for i in range(n):
l=list(map(int,input().split()))
for i in range(0,len(l),2):
if l[i]==0 and l[i+1]==1 or l[i]==1 and l[i+1]==1 or l[i]==1 and l[i+1]==0:
c+=1
i+=1
#i+=1
print(c)
``` | 3 |
|
44 | C | Holidays | PROGRAMMING | 1,300 | [
"implementation"
] | C. Holidays | 2 | 256 | School holidays come in Berland. The holidays are going to continue for *n* days. The students of school №*N* are having the time of their lives and the IT teacher Marina Sergeyevna, who has spent all the summer busy checking the BSE (Berland State Examination) results, has finally taken a vacation break! Some people are in charge of the daily watering of flowers in shifts according to the schedule. However when Marina Sergeyevna was making the schedule, she was so tired from work and so lost in dreams of the oncoming vacation that she perhaps made several mistakes. In fact, it is possible that according to the schedule, on some days during the holidays the flowers will not be watered or will be watered multiple times. Help Marina Sergeyevna to find a mistake. | The first input line contains two numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of days in Berland holidays and the number of people in charge of the watering respectively. The next *m* lines contain the description of the duty schedule. Each line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*b**i*<=≤<=*n*), meaning that the *i*-th person in charge should water the flowers from the *a**i*-th to the *b**i*-th day inclusively, once a day. The duty shifts are described sequentially, i.e. *b**i*<=≤<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1 inclusively. | Print "OK" (without quotes), if the schedule does not contain mistakes. Otherwise you have to find the minimal number of a day when the flowers will not be watered or will be watered multiple times, and output two integers — the day number and the number of times the flowers will be watered that day. | [
"10 5\n1 2\n3 3\n4 6\n7 7\n8 10\n",
"10 5\n1 2\n2 3\n4 5\n7 8\n9 10\n",
"10 5\n1 2\n3 3\n5 7\n7 7\n7 10\n"
] | [
"OK\n",
"2 2\n",
"4 0\n"
] | Keep in mind that in the second sample the mistake occurs not only on the second day, but also on the sixth day, when nobody waters the flowers. However, you have to print the second day, i.e. the day with the minimal number. | 0 | [
{
"input": "10 5\n1 2\n3 3\n4 6\n7 7\n8 10",
"output": "OK"
},
{
"input": "10 5\n1 2\n2 3\n4 5\n7 8\n9 10",
"output": "2 2"
},
{
"input": "10 5\n1 2\n3 3\n5 7\n7 7\n7 10",
"output": "4 0"
},
{
"input": "5 4\n1 1\n2 2\n3 3\n4 5",
"output": "OK"
},
{
"input": "100 50\n1 2\n3 3\n4 5\n6 8\n9 10\n11 11\n12 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 21\n22 23\n24 24\n25 26\n27 30\n31 34\n35 37\n38 38\n39 40\n41 43\n44 46\n47 53\n54 54\n55 55\n56 59\n60 60\n61 61\n62 64\n65 69\n70 72\n73 73\n74 74\n75 76\n77 79\n80 82\n83 83\n84 84\n85 85\n86 86\n87 88\n89 89\n90 90\n91 91\n92 92\n93 93\n94 97\n98 98\n99 100",
"output": "OK"
},
{
"input": "50 50\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50",
"output": "OK"
},
{
"input": "5 1\n1 5",
"output": "OK"
},
{
"input": "6 2\n1 5\n6 6",
"output": "OK"
},
{
"input": "7 5\n1 1\n2 2\n3 3\n4 4\n5 7",
"output": "OK"
},
{
"input": "10 2\n1 2\n3 10",
"output": "OK"
},
{
"input": "21 15\n1 1\n2 2\n3 3\n4 5\n6 6\n7 7\n8 8\n9 9\n10 11\n12 12\n13 13\n14 14\n15 17\n18 19\n20 21",
"output": "OK"
},
{
"input": "100 7\n1 8\n9 26\n27 28\n29 30\n31 38\n39 95\n96 100",
"output": "OK"
},
{
"input": "100 13\n1 4\n5 11\n12 18\n19 24\n25 31\n32 38\n39 39\n40 45\n46 55\n56 69\n70 70\n71 75\n76 100",
"output": "OK"
},
{
"input": "100 50\n1 8\n9 12\n13 19\n20 22\n23 27\n28 31\n32 36\n36 40\n40 43\n47 47\n48 51\n51 55\n62 63\n69 77\n77 84\n85 90\n98 99\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100\n100 100",
"output": "36 2"
},
{
"input": "1 1\n1 1",
"output": "OK"
},
{
"input": "10 1\n2 3",
"output": "1 0"
},
{
"input": "10 9\n1 1\n2 2\n3 4\n6 6\n8 8\n8 10\n10 10\n10 10\n10 10",
"output": "5 0"
},
{
"input": "27 10\n1 1\n2 3\n4 5\n6 7\n8 9\n10 11\n12 13\n14 15\n16 17\n17 18",
"output": "17 2"
},
{
"input": "67 15\n1 6\n7 14\n15 16\n17 23\n24 30\n31 34\n35 41\n42 48\n48 56\n56 62\n66 67\n67 67\n67 67\n67 67\n67 67",
"output": "48 2"
},
{
"input": "68 13\n1 2\n3 11\n12 21\n22 30\n31 38\n39 43\n44 44\n45 46\n47 50\n51 55\n64 68\n68 68\n68 68",
"output": "56 0"
},
{
"input": "47 45\n1 3\n4 7\n8 11\n12 15\n16 18\n19 23\n24 26\n27 28\n29 31\n32 33\n34 37\n37 40\n45 45\n46 46\n46 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47\n47 47",
"output": "37 2"
},
{
"input": "5 2\n1 1\n3 3",
"output": "2 0"
},
{
"input": "5 3\n1 2\n3 3\n3 5",
"output": "3 2"
},
{
"input": "5 4\n1 2\n3 4\n5 5\n5 5",
"output": "5 2"
},
{
"input": "10 5\n2 5\n5 6\n7 9\n9 9\n9 10",
"output": "1 0"
},
{
"input": "20 6\n1 1\n1 1\n1 3\n5 7\n7 13\n14 20",
"output": "1 3"
},
{
"input": "20 7\n1 3\n4 8\n8 8\n8 8\n8 9\n15 20\n20 20",
"output": "8 4"
},
{
"input": "20 7\n1 5\n6 8\n10 10\n12 15\n15 16\n16 16\n16 20",
"output": "9 0"
},
{
"input": "20 13\n1 2\n3 4\n5 7\n7 7\n7 7\n7 9\n10 11\n11 11\n11 12\n12 12\n12 13\n15 18\n19 20",
"output": "7 4"
},
{
"input": "20 7\n1 3\n4 5\n6 6\n7 11\n12 15\n16 17\n18 19",
"output": "20 0"
},
{
"input": "20 7\n1 6\n7 9\n10 11\n12 14\n15 19\n19 20\n20 20",
"output": "19 2"
}
] | 1,563,266,875 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 310 | 0 | n,m = map(int,input().split())
Ln = [0]*n
while m!=0:
a,b = map(int,input().split())
for i in range(a,b+1):
Ln[i-1]+=1
m-=1
for i in range(0,len(Ln)):
if Ln[i]==0 :
print(i+1,0)
exit(0)
elif Ln[i]>1:
print(i+1,Ln[i])
exit(0)
print('OK')
exit(0)
| Title: Holidays
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
School holidays come in Berland. The holidays are going to continue for *n* days. The students of school №*N* are having the time of their lives and the IT teacher Marina Sergeyevna, who has spent all the summer busy checking the BSE (Berland State Examination) results, has finally taken a vacation break! Some people are in charge of the daily watering of flowers in shifts according to the schedule. However when Marina Sergeyevna was making the schedule, she was so tired from work and so lost in dreams of the oncoming vacation that she perhaps made several mistakes. In fact, it is possible that according to the schedule, on some days during the holidays the flowers will not be watered or will be watered multiple times. Help Marina Sergeyevna to find a mistake.
Input Specification:
The first input line contains two numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of days in Berland holidays and the number of people in charge of the watering respectively. The next *m* lines contain the description of the duty schedule. Each line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*b**i*<=≤<=*n*), meaning that the *i*-th person in charge should water the flowers from the *a**i*-th to the *b**i*-th day inclusively, once a day. The duty shifts are described sequentially, i.e. *b**i*<=≤<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1 inclusively.
Output Specification:
Print "OK" (without quotes), if the schedule does not contain mistakes. Otherwise you have to find the minimal number of a day when the flowers will not be watered or will be watered multiple times, and output two integers — the day number and the number of times the flowers will be watered that day.
Demo Input:
['10 5\n1 2\n3 3\n4 6\n7 7\n8 10\n', '10 5\n1 2\n2 3\n4 5\n7 8\n9 10\n', '10 5\n1 2\n3 3\n5 7\n7 7\n7 10\n']
Demo Output:
['OK\n', '2 2\n', '4 0\n']
Note:
Keep in mind that in the second sample the mistake occurs not only on the second day, but also on the sixth day, when nobody waters the flowers. However, you have to print the second day, i.e. the day with the minimal number. | ```python
n,m = map(int,input().split())
Ln = [0]*n
while m!=0:
a,b = map(int,input().split())
for i in range(a,b+1):
Ln[i-1]+=1
m-=1
for i in range(0,len(Ln)):
if Ln[i]==0 :
print(i+1,0)
exit(0)
elif Ln[i]>1:
print(i+1,Ln[i])
exit(0)
print('OK')
exit(0)
``` | 3.9225 |
446 | C | DZY Loves Fibonacci Numbers | PROGRAMMING | 2,400 | [
"data structures",
"math",
"number theory"
] | null | null | In mathematical terms, the sequence *F**n* of Fibonacci numbers is defined by the recurrence relation
DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Moreover, there are *m* queries, each query has one of the two types:
1. Format of the query "1 *l* *r*". In reply to the query, you need to add *F**i*<=-<=*l*<=+<=1 to each element *a**i*, where *l*<=≤<=*i*<=≤<=*r*. 1. Format of the query "2 *l* *r*". In reply to the query you should output the value of modulo 1000000009 (109<=+<=9).
Help DZY reply to all the queries. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=300000). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — initial array *a*.
Then, *m* lines follow. A single line describes a single query in the format given in the statement. It is guaranteed that for each query inequality 1<=≤<=*l*<=≤<=*r*<=≤<=*n* holds. | For each query of the second type, print the value of the sum on a single line. | [
"4 4\n1 2 3 4\n1 1 4\n2 1 4\n1 2 4\n2 1 3\n"
] | [
"17\n12\n"
] | After the first query, *a* = [2, 3, 5, 7].
For the second query, *sum* = 2 + 3 + 5 + 7 = 17.
After the third query, *a* = [2, 4, 6, 9].
For the fourth query, *sum* = 2 + 4 + 6 = 12. | 1,500 | [
{
"input": "4 4\n1 2 3 4\n1 1 4\n2 1 4\n1 2 4\n2 1 3",
"output": "17\n12"
},
{
"input": "2 2\n1 2\n2 1 2\n2 1 2",
"output": "3\n3"
},
{
"input": "10 20\n56 12 68 23 41 29 97 69 79 76\n1 3 5\n1 8 9\n2 3 10\n1 7 10\n2 1 10\n1 5 10\n2 2 4\n1 2 4\n1 5 6\n2 1 2\n2 4 5\n1 1 5\n1 8 9\n2 5 8\n2 4 7\n2 9 10\n2 4 9\n1 2 10\n1 2 9\n2 7 8",
"output": "488\n563\n105\n69\n71\n256\n210\n175\n373\n217"
}
] | 1,692,845,033 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = int(input())
arr = [int(s) for s in input().split()]
s = sum(arr)
t = []
if s % 3 == 0:
sum = 0
for i in range(n):
sum += arr[i]
v = (0 if len(t) < 1 else t[len(t) - 1]) + (1 if sum == s // 3 else 0)
t.append(v)
res = 0
sum = arr[0]
for i in range(1, n - 1):
sum += arr[i]
if sum == 2 * s // 3:
res += t[i - 1]
print(res)
else:
print(0)
| Title: DZY Loves Fibonacci Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In mathematical terms, the sequence *F**n* of Fibonacci numbers is defined by the recurrence relation
DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Moreover, there are *m* queries, each query has one of the two types:
1. Format of the query "1 *l* *r*". In reply to the query, you need to add *F**i*<=-<=*l*<=+<=1 to each element *a**i*, where *l*<=≤<=*i*<=≤<=*r*. 1. Format of the query "2 *l* *r*". In reply to the query you should output the value of modulo 1000000009 (109<=+<=9).
Help DZY reply to all the queries.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=300000). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — initial array *a*.
Then, *m* lines follow. A single line describes a single query in the format given in the statement. It is guaranteed that for each query inequality 1<=≤<=*l*<=≤<=*r*<=≤<=*n* holds.
Output Specification:
For each query of the second type, print the value of the sum on a single line.
Demo Input:
['4 4\n1 2 3 4\n1 1 4\n2 1 4\n1 2 4\n2 1 3\n']
Demo Output:
['17\n12\n']
Note:
After the first query, *a* = [2, 3, 5, 7].
For the second query, *sum* = 2 + 3 + 5 + 7 = 17.
After the third query, *a* = [2, 4, 6, 9].
For the fourth query, *sum* = 2 + 4 + 6 = 12. | ```python
n = int(input())
arr = [int(s) for s in input().split()]
s = sum(arr)
t = []
if s % 3 == 0:
sum = 0
for i in range(n):
sum += arr[i]
v = (0 if len(t) < 1 else t[len(t) - 1]) + (1 if sum == s // 3 else 0)
t.append(v)
res = 0
sum = arr[0]
for i in range(1, n - 1):
sum += arr[i]
if sum == 2 * s // 3:
res += t[i - 1]
print(res)
else:
print(0)
``` | -1 |
|
612 | C | Replace To Make Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"data structures",
"expression parsing",
"math"
] | null | null | You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a regular bracket sequence is well-known, so you can be familiar with it.
Let's define a regular bracket sequence (RBS). Empty string is RBS. Let *s*1 and *s*2 be a RBS then the strings <*s*1>*s*2, {*s*1}*s*2, [*s*1]*s*2, (*s*1)*s*2 are also RBS.
For example the string "[[(){}]<>]" is RBS, but the strings "[)()" and "][()()" are not.
Determine the least number of replaces to make the string *s* RBS. | The only line contains a non empty string *s*, consisting of only opening and closing brackets of four kinds. The length of *s* does not exceed 106. | If it's impossible to get RBS from *s* print Impossible.
Otherwise print the least number of replaces needed to get RBS from *s*. | [
"[<}){}\n",
"{()}[]\n",
"]]\n"
] | [
"2",
"0",
"Impossible"
] | none | 0 | [
{
"input": "[<}){}",
"output": "2"
},
{
"input": "{()}[]",
"output": "0"
},
{
"input": "]]",
"output": "Impossible"
},
{
"input": ">",
"output": "Impossible"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{]",
"output": "1"
},
{
"input": "{]",
"output": "1"
},
{
"input": "{]",
"output": "1"
},
{
"input": "[]{[]({)([",
"output": "Impossible"
},
{
"input": "(([{>}{[{[)]]>>]",
"output": "7"
},
{
"input": "((<>)[]<]><]",
"output": "3"
},
{
"input": "[[([[(>]>)))[<)>",
"output": "6"
},
{
"input": "({)[}<)](}",
"output": "5"
},
{
"input": "(}{)[<][)(]}",
"output": "6"
},
{
"input": ">}({>]{[}<{<{{)[]]{)]>]]]<(][{)<<<{<<)>)()[>{<]]{}<>}}}}(>}<})(][>{((<{<)]}>)))][>[}[])<]){]]][<[)([",
"output": "Impossible"
},
{
"input": "<<[<{{<([({<<[)<>(]]){})>[](])[)))[[}>]<)>[[>{>>>[<]}<>>)[>]<{)<[><(<]][>(>]>][(<][{]}(()<[()[>><<])<]})]<]}{)",
"output": "45"
},
{
"input": "[<<{{((}[}<<)<)>})(][{>}})((>)<[)[>}[})[)>()[()[((}<<(>)<>](<>(}[>})[[[{)<}<<(}{>>}[<([[])<><)]<{>}[>>>{({>)}]})>)",
"output": "42"
},
{
"input": "(<[([(<({>(}{]>[(})])}])()<<}{]{[>]>(>>[(>>}[){(}<[{(()]{{<(<{][[{<><{<{)<>>]}}}{)(}{})}[<))>>}((({>){({}{{]}]>>}})>))",
"output": "43"
},
{
"input": "{(]}<([]<]{>]<{<({{{<>))}[({(}{)[}({>]}}<<)}<]))(<>(>{>{{{)<}({<]<>{)(>[)>{({}<([<[[)]><>{]}}(>]{}<)[})]}]]}]}>}",
"output": "40"
},
{
"input": "<(([)]<[}>{)>][[(<()({{{>>((]<}<{{<>}><<[)}[[)([[)[)}<]<{(<>){([)><{[([[][({])})<][(}]}>>[){)[({>){(}[}})>}>]>)]}))})>}]",
"output": "45"
},
{
"input": ")(",
"output": "Impossible"
},
{
"input": "[[[[[[[[",
"output": "Impossible"
}
] | 1,525,359,871 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 77 | 7,065,600 | R = lambda: list(map(int,input().split()))
s = input()
ok = True
ans = 0
st = []
opn = set("<[({")
inv = {'}':'{', ')':'(', '>':'<', ']':'['}
for i in s:
if i in opn:
st.append(i)
else:
if not st:
ok = False
break
if inv[i]!=st[-1]: ans += 1
st.pop()
if not ok: print("Impossible")
else: print(ans) | Title: Replace To Make Regular Bracket Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a regular bracket sequence is well-known, so you can be familiar with it.
Let's define a regular bracket sequence (RBS). Empty string is RBS. Let *s*1 and *s*2 be a RBS then the strings <*s*1>*s*2, {*s*1}*s*2, [*s*1]*s*2, (*s*1)*s*2 are also RBS.
For example the string "[[(){}]<>]" is RBS, but the strings "[)()" and "][()()" are not.
Determine the least number of replaces to make the string *s* RBS.
Input Specification:
The only line contains a non empty string *s*, consisting of only opening and closing brackets of four kinds. The length of *s* does not exceed 106.
Output Specification:
If it's impossible to get RBS from *s* print Impossible.
Otherwise print the least number of replaces needed to get RBS from *s*.
Demo Input:
['[<}){}\n', '{()}[]\n', ']]\n']
Demo Output:
['2', '0', 'Impossible']
Note:
none | ```python
R = lambda: list(map(int,input().split()))
s = input()
ok = True
ans = 0
st = []
opn = set("<[({")
inv = {'}':'{', ')':'(', '>':'<', ']':'['}
for i in s:
if i in opn:
st.append(i)
else:
if not st:
ok = False
break
if inv[i]!=st[-1]: ans += 1
st.pop()
if not ok: print("Impossible")
else: print(ans)
``` | 0 |
|
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9).
What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel. | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels. | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change. | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
"output": "1"
},
{
"input": "1000 9",
"output": "1"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "999 9",
"output": "1"
},
{
"input": "999 8",
"output": "2"
},
{
"input": "105 6",
"output": "2"
},
{
"input": "403 9",
"output": "3"
},
{
"input": "546 4",
"output": "4"
},
{
"input": "228 9",
"output": "5"
},
{
"input": "57 2",
"output": "6"
},
{
"input": "437 9",
"output": "7"
},
{
"input": "997 6",
"output": "8"
},
{
"input": "109 1",
"output": "9"
},
{
"input": "998 9",
"output": "5"
},
{
"input": "4 2",
"output": "3"
},
{
"input": "9 3",
"output": "7"
},
{
"input": "8 2",
"output": "4"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "1 4",
"output": "4"
},
{
"input": "1 5",
"output": "5"
},
{
"input": "1 6",
"output": "6"
},
{
"input": "1 7",
"output": "7"
},
{
"input": "1 8",
"output": "8"
},
{
"input": "100 3",
"output": "1"
},
{
"input": "1000 2",
"output": "1"
},
{
"input": "1000 4",
"output": "1"
},
{
"input": "1000 5",
"output": "1"
},
{
"input": "1000 6",
"output": "1"
},
{
"input": "1000 7",
"output": "1"
},
{
"input": "1000 8",
"output": "1"
},
{
"input": "23 4",
"output": "8"
},
{
"input": "33 1",
"output": "7"
},
{
"input": "33 2",
"output": "4"
},
{
"input": "666 5",
"output": "5"
},
{
"input": "2 3",
"output": "5"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "12 4",
"output": "2"
},
{
"input": "15 5",
"output": "1"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "25 5",
"output": "1"
},
{
"input": "2 9",
"output": "5"
},
{
"input": "6 7",
"output": "5"
},
{
"input": "8 9",
"output": "5"
},
{
"input": "2 7",
"output": "5"
},
{
"input": "4 7",
"output": "5"
},
{
"input": "2 1",
"output": "5"
},
{
"input": "261 1",
"output": "1"
}
] | 1,678,481,167 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 62 | 0 | inp = input().split()
inp = [int(x) for x in inp]
a=0
for i in range(15):
if(i>0):
if(inp[0]%10==0 or (inp[0]-inp[1])%10==0 or ((inp[0]*i)-inp[1])%10==0 or (inp[0]*i)%10==0):# :
a=i
break
print(a) | Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9).
What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
Input Specification:
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
Output Specification:
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
Demo Input:
['117 3\n', '237 7\n', '15 2\n']
Demo Output:
['9\n', '1\n', '2\n']
Note:
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change. | ```python
inp = input().split()
inp = [int(x) for x in inp]
a=0
for i in range(15):
if(i>0):
if(inp[0]%10==0 or (inp[0]-inp[1])%10==0 or ((inp[0]*i)-inp[1])%10==0 or (inp[0]*i)%10==0):# :
a=i
break
print(a)
``` | 3 |
|
252 | A | Little Xor | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, such that the *xor* of all numbers from this segment was maximal possible. Help him with that.
The *xor* operation is the bitwise exclusive "OR", that is denoted as "xor" in Pascal and "^" in C/C++/Java. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230. | Print a single integer — the required maximal *xor* of a segment of consecutive elements. | [
"5\n1 2 1 1 2\n",
"3\n1 2 7\n",
"4\n4 2 4 8\n"
] | [
"3\n",
"7\n",
"14\n"
] | In the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one.
The second sample contains only one optimal segment, which contains exactly one array element (element with index three). | 500 | [
{
"input": "5\n1 2 1 1 2",
"output": "3"
},
{
"input": "3\n1 2 7",
"output": "7"
},
{
"input": "4\n4 2 4 8",
"output": "14"
},
{
"input": "5\n1 1 1 1 1",
"output": "1"
},
{
"input": "16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
"output": "15"
},
{
"input": "20\n1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10",
"output": "15"
},
{
"input": "100\n28 20 67 103 72 81 82 83 7 109 122 30 50 118 83 89 108 82 92 17 97 3 62 12 9 100 14 11 99 106 10 8 60 101 88 119 104 62 76 6 5 57 32 94 60 50 58 97 1 97 107 108 80 24 45 20 112 1 98 106 49 98 25 57 47 90 74 68 14 35 22 10 61 80 10 4 53 13 90 99 57 100 40 84 22 116 60 61 98 57 74 127 61 73 49 51 20 19 56 111",
"output": "127"
},
{
"input": "99\n87 67 4 84 13 20 35 7 11 86 25 1 58 1 74 64 74 86 98 74 72 46 63 78 84 13 60 38 30 45 45 60 9 44 36 70 33 22 82 15 71 7 43 47 23 2 20 49 42 43 54 27 51 51 53 23 27 37 17 66 90 89 61 0 18 20 49 30 84 20 13 32 64 69 56 68 59 10 91 96 43 64 19 10 2 57 62 23 100 39 32 19 95 55 77 19 24 4 77",
"output": "127"
},
{
"input": "1\n100",
"output": "100"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n4 10",
"output": "14"
},
{
"input": "99\n3511 2076 9314 3598 7737 271 4110 4454 5830 8661 8584 8227 2236 2626 1025 3806 3162 2837 6071 9627 1836 7729 6629 4054 9377 3261 1325 8859 3610 7616 5052 9736 1249 6224 7031 6074 4196 8075 4005 5419 5664 8214 4391 731 8714 8622 6122 6976 4057 1770 8025 3778 2792 994 5204 1826 6083 5438 8409 8029 1962 3133 9836 8884 1234 1776 824 1630 6523 2869 9950 8609 5397 1472 7120 5012 6490 5958 8030 7741 5077 2771 7925 9784 9456 8596 6288 8939 4779 4415 3743 5188 5574 9686 1483 4245 4769 4917 1887",
"output": "16383"
},
{
"input": "27\n78 918 443 3900 591 12 4 10 1 24 70 88 429 2 3257 65 275 2 258 62 587 625 25 26 853 728 765",
"output": "4027"
},
{
"input": "2\n3 1",
"output": "3"
},
{
"input": "2\n3 2",
"output": "3"
},
{
"input": "3\n7 3 1",
"output": "7"
},
{
"input": "3\n1 7 2",
"output": "7"
},
{
"input": "2\n7 1",
"output": "7"
},
{
"input": "4\n1 2 7 1",
"output": "7"
},
{
"input": "3\n10 5 1",
"output": "15"
}
] | 1,618,227,954 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | 5
1912 1123
5 6213
999 11234
88 214
12 100124
| Title: Little Xor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, such that the *xor* of all numbers from this segment was maximal possible. Help him with that.
The *xor* operation is the bitwise exclusive "OR", that is denoted as "xor" in Pascal and "^" in C/C++/Java.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230.
Output Specification:
Print a single integer — the required maximal *xor* of a segment of consecutive elements.
Demo Input:
['5\n1 2 1 1 2\n', '3\n1 2 7\n', '4\n4 2 4 8\n']
Demo Output:
['3\n', '7\n', '14\n']
Note:
In the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one.
The second sample contains only one optimal segment, which contains exactly one array element (element with index three). | ```python
5
1912 1123
5 6213
999 11234
88 214
12 100124
``` | -1 |
|
602 | B | Approximating a Constant Range | PROGRAMMING | 1,400 | [
"dp",
"implementation",
"two pointers"
] | null | null | When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their average. Of course, with the usual sizes of data, it's nothing challenging — but why not make a similar programming contest problem while we're at it?
You're given a sequence of *n* data points *a*1,<=...,<=*a**n*. There aren't any big jumps between consecutive data points — for each 1<=≤<=*i*<=<<=*n*, it's guaranteed that |*a**i*<=+<=1<=-<=*a**i*|<=≤<=1.
A range [*l*,<=*r*] of data points is said to be almost constant if the difference between the largest and the smallest value in that range is at most 1. Formally, let *M* be the maximum and *m* the minimum value of *a**i* for *l*<=≤<=*i*<=≤<=*r*; the range [*l*,<=*r*] is almost constant if *M*<=-<=*m*<=≤<=1.
Find the length of the longest almost constant range. | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000). | Print a single number — the maximum length of an almost constant range of the given sequence. | [
"5\n1 2 3 3 2\n",
"11\n5 4 5 5 6 7 8 8 8 7 6\n"
] | [
"4\n",
"5\n"
] | In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4.
In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10]. | 1,000 | [
{
"input": "5\n1 2 3 3 2",
"output": "4"
},
{
"input": "11\n5 4 5 5 6 7 8 8 8 7 6",
"output": "5"
},
{
"input": "2\n3 2",
"output": "2"
},
{
"input": "4\n1001 1000 1000 1001",
"output": "4"
},
{
"input": "4\n1 1 2 3",
"output": "3"
},
{
"input": "3\n1 2 1",
"output": "3"
},
{
"input": "3\n1 2 3",
"output": "2"
},
{
"input": "18\n10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9",
"output": "3"
},
{
"input": "3\n1 2 2",
"output": "3"
},
{
"input": "4\n10 9 10 9",
"output": "4"
},
{
"input": "4\n4 3 2 3",
"output": "3"
},
{
"input": "4\n8 8 7 7",
"output": "4"
},
{
"input": "3\n99998 99999 100000",
"output": "2"
},
{
"input": "3\n100000 99999 99998",
"output": "2"
},
{
"input": "3\n1 1 1",
"output": "3"
},
{
"input": "2\n99999 100000",
"output": "2"
},
{
"input": "2\n100000 100000",
"output": "2"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "15\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "15"
}
] | 1,590,289,475 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 21 | 2,000 | 7,680,000 |
# Approximating a Constant Range
def calculate_constant_range(data_points, n):
i = 0
const_max = 0
while i <= n - const_max:
temp_lst = []
count = 0
j = i
while j < n:
if data_points[j] not in temp_lst:
temp_lst.append(data_points[j])
if len(temp_lst) > 2:
break
count += 1
j += 1
if count > const_max:
const_max = count
i += 1
return const_max
if __name__ == "__main__":
# # Input handling
n = int(input())
data_points = list(map(int, input().split()))
# data_points = [5, 4, 5, 5, 6, 7, 8, 8, 8, 7, 6]
# data_points = [1, 2, 3, 3, 2]
# n = len(data_points)
print(calculate_constant_range(data_points, n))
| Title: Approximating a Constant Range
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their average. Of course, with the usual sizes of data, it's nothing challenging — but why not make a similar programming contest problem while we're at it?
You're given a sequence of *n* data points *a*1,<=...,<=*a**n*. There aren't any big jumps between consecutive data points — for each 1<=≤<=*i*<=<<=*n*, it's guaranteed that |*a**i*<=+<=1<=-<=*a**i*|<=≤<=1.
A range [*l*,<=*r*] of data points is said to be almost constant if the difference between the largest and the smallest value in that range is at most 1. Formally, let *M* be the maximum and *m* the minimum value of *a**i* for *l*<=≤<=*i*<=≤<=*r*; the range [*l*,<=*r*] is almost constant if *M*<=-<=*m*<=≤<=1.
Find the length of the longest almost constant range.
Input Specification:
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000).
Output Specification:
Print a single number — the maximum length of an almost constant range of the given sequence.
Demo Input:
['5\n1 2 3 3 2\n', '11\n5 4 5 5 6 7 8 8 8 7 6\n']
Demo Output:
['4\n', '5\n']
Note:
In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4.
In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10]. | ```python
# Approximating a Constant Range
def calculate_constant_range(data_points, n):
i = 0
const_max = 0
while i <= n - const_max:
temp_lst = []
count = 0
j = i
while j < n:
if data_points[j] not in temp_lst:
temp_lst.append(data_points[j])
if len(temp_lst) > 2:
break
count += 1
j += 1
if count > const_max:
const_max = count
i += 1
return const_max
if __name__ == "__main__":
# # Input handling
n = int(input())
data_points = list(map(int, input().split()))
# data_points = [5, 4, 5, 5, 6, 7, 8, 8, 8, 7, 6]
# data_points = [1, 2, 3, 3, 2]
# n = len(data_points)
print(calculate_constant_range(data_points, n))
``` | 0 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,570,801,198 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 218 | 0 | s=input()
t=input()
x=0
if len(s)>len(t) or len(s)<len(t):
print('NO')
else:
for i in range(len(s)):
if s[i]==t[-i-1]:
x=x+1
if x==len(s):
print('YES')
else:
print('NO')
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
s=input()
t=input()
x=0
if len(s)>len(t) or len(s)<len(t):
print('NO')
else:
for i in range(len(s)):
if s[i]==t[-i-1]:
x=x+1
if x==len(s):
print('YES')
else:
print('NO')
``` | 3.9455 |
626 | B | Cards | PROGRAMMING | 1,300 | [
"constructive algorithms",
"dp",
"math"
] | null | null | Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:
- take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color.
She repeats this process until there is only one card left. What are the possible colors for the final card? | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200) — the total number of cards.
The next line contains a string *s* of length *n* — the colors of the cards. *s* contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively. | Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order. | [
"2\nRB\n",
"3\nGRG\n",
"5\nBBBBB\n"
] | [
"G\n",
"BR\n",
"B\n"
] | In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card.
In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card.
In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards. | 750 | [
{
"input": "2\nRB",
"output": "G"
},
{
"input": "3\nGRG",
"output": "BR"
},
{
"input": "5\nBBBBB",
"output": "B"
},
{
"input": "1\nR",
"output": "R"
},
{
"input": "200\nBBRGRRBBRGGGBGBGBGRRGRGRGRBGRGRRBBGRGBGRRGRRRGGBBRGBGBGBRBBBBBBBGGBRGGRRRGGRGBGBGGBRRRRBRRRBRBBGGBGBRGRGBBBBGGBGBBBGBGRRBRRRGBGGBBBRBGRBRRGGGRRGBBBGBGRRRRRRGGRGRGBBBRGGGBGGGBRBBRRGBGRGRBRRRBRBGRGGBRBB",
"output": "BGR"
},
{
"input": "101\nRRRRRRRRRRRRRRRRRRRBRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "BG"
},
{
"input": "7\nBBBGBRG",
"output": "BGR"
},
{
"input": "5\nGRRGR",
"output": "BGR"
},
{
"input": "3\nGBR",
"output": "BGR"
},
{
"input": "1\nB",
"output": "B"
},
{
"input": "2\nBB",
"output": "B"
},
{
"input": "1\nG",
"output": "G"
},
{
"input": "2\nBG",
"output": "R"
},
{
"input": "3\nBGB",
"output": "GR"
},
{
"input": "2\nGG",
"output": "G"
},
{
"input": "3\nGBG",
"output": "BR"
},
{
"input": "4\nBGBG",
"output": "BGR"
},
{
"input": "1\nR",
"output": "R"
},
{
"input": "2\nBR",
"output": "G"
},
{
"input": "3\nBRB",
"output": "GR"
},
{
"input": "2\nRG",
"output": "B"
},
{
"input": "3\nBGR",
"output": "BGR"
},
{
"input": "4\nRBGB",
"output": "BGR"
},
{
"input": "3\nGGR",
"output": "BR"
},
{
"input": "4\nGGRB",
"output": "BGR"
},
{
"input": "5\nBGBGR",
"output": "BGR"
},
{
"input": "2\nRR",
"output": "R"
},
{
"input": "3\nRBR",
"output": "BG"
},
{
"input": "4\nRRBB",
"output": "BGR"
},
{
"input": "3\nRRG",
"output": "BG"
},
{
"input": "4\nBRRG",
"output": "BGR"
},
{
"input": "5\nRBRBG",
"output": "BGR"
},
{
"input": "4\nRGGR",
"output": "BGR"
},
{
"input": "5\nBRGRG",
"output": "BGR"
},
{
"input": "6\nGRRGBB",
"output": "BGR"
},
{
"input": "150\nGRGBBBBRBGGBGBBGBBBBGRBBRRBBGRRGGGBRBBRGRRRRGBGRRBGBGBGRBBBGBBBGBGBRGBRRRRRGGGRGRBBGBRGGGRBBRGBBGRGGGBBRBRRGRGRRGRRGRRRGBGBRRGGRGGBRBGGGBBBRGRGBRGRRRR",
"output": "BGR"
},
{
"input": "16\nRRGRRRRRRGGRGRRR",
"output": "BGR"
},
{
"input": "190\nBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "GR"
},
{
"input": "200\nRGRGRRRRRGRRGRRRGRGRRRGGRGRRGGGRRGGRRRRRRRRRRRGRRGRRRGRRRGRRRRRRRGRRRRRRRRRRRGGRRGGRRRRGGRRRRRRRRRGGGRGRGRGRRGRGGRGRGRRRGRRRRRRGGRGRRRRGRRGRGGRRRRRRRGRGGRRGRRRRRRRGGRRRRGRRRRRRRGRRRGGRRRRRRGRRGGGRRRGR",
"output": "BGR"
},
{
"input": "200\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "G"
},
{
"input": "52\nBBBBBBBBBBBBBBBBBBBBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "BGR"
},
{
"input": "200\nGRGRRGRBRRRGGGRGGRRRRRBBGRRGRBBGRRGBGRRBBRBBRRBBBGRBRGGGGBGGBRRBBRGRBGGRRGGBBRBGGRGBBRRBBRGBRRBGBRBGBBRGGRRRGGGBRGGGGRRRBBRRGRGRBRRGRBBGGRBBRGRGRBGRBBRGGBBBGRGBBGGBGBGBBRRBGRGRGGBRRGRGGGGGBRGGGGBBBBRB",
"output": "BGR"
},
{
"input": "102\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGRGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "BGR"
},
{
"input": "193\nRRRGGGRBGGBGGGBGGBBGRBGGRBGGBBRBGGRBBBRBRRGGBBRBRGRRRBGBBRGGRGGGBGGRRGGRGRRBRBRBRRGRGBGBRGBBRGRRRBGRGGBGBRBBBGBRBBGBGBGGGBGGGGBRBBRRBGRGGBBBRBBBBBGRRRGBRGBRRRBBBGBGGGGRGGRRBRBGRRGBGBRBGGGRBRRGG",
"output": "BGR"
},
{
"input": "90\nBGBGGRRBGGRRRRRGGRGBBBBBRRBGBGBGBGGBBGRGGGGRBRBBRRRGBRRGBBGBBGGGRGRGRBGBBBRRGRRBRBRRGGRBRB",
"output": "BGR"
},
{
"input": "3\nGGB",
"output": "BR"
}
] | 1,455,385,954 | 1,054 | Python 3 | WRONG_ANSWER | PRETESTS | 1 | 62 | 0 | l=int(input())
c=input()
if len(set(c))==1:
print(c[0])
elif c.count('R')==c.count('B') and c.count('R')==c.count('G'):
print('BGR')
rc=['R', 'G', 'B']
rc.sort(key=lambda x: c.count(x))
#rc=list(sorted(map(lambda x: c.count(x), rc)))
print(rc[0])
| Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:
- take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color.
She repeats this process until there is only one card left. What are the possible colors for the final card?
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200) — the total number of cards.
The next line contains a string *s* of length *n* — the colors of the cards. *s* contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively.
Output Specification:
Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order.
Demo Input:
['2\nRB\n', '3\nGRG\n', '5\nBBBBB\n']
Demo Output:
['G\n', 'BR\n', 'B\n']
Note:
In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card.
In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card.
In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards. | ```python
l=int(input())
c=input()
if len(set(c))==1:
print(c[0])
elif c.count('R')==c.count('B') and c.count('R')==c.count('G'):
print('BGR')
rc=['R', 'G', 'B']
rc.sort(key=lambda x: c.count(x))
#rc=list(sorted(map(lambda x: c.count(x), rc)))
print(rc[0])
``` | 0 |
|
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
"output": "QCCYXL"
},
{
"input": "3\nAZID\nEERWBC\nEERWBC",
"output": "EERWBC"
},
{
"input": "3\nHNCGYL\nHNCGYL\nHNCGYL",
"output": "HNCGYL"
},
{
"input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG",
"output": "ZZWZTG"
},
{
"input": "4\nA\nA\nKUDLJMXCSE\nA",
"output": "A"
},
{
"input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW",
"output": "PHBTW"
},
{
"input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN",
"output": "PKUZYTFYWN"
},
{
"input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH",
"output": "HH"
},
{
"input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW",
"output": "W"
},
{
"input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP",
"output": "XBCP"
},
{
"input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS",
"output": "PYPAS"
},
{
"input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC",
"output": "NC"
},
{
"input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI",
"output": "VOCI"
},
{
"input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA",
"output": "HA"
},
{
"input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS",
"output": "G"
},
{
"input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL",
"output": "WL"
}
] | 1,684,592,469 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 186 | 0 | n = int(input())
d = {}
ans = ""
m = 0
for i in range(n):
s = input()
if s not in d:
d[s] = 0
d[s] += 1
if d[s] > m:
m = d[s]
ans = s
print(ans) | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output Specification:
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Demo Input:
['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n']
Demo Output:
['ABC\n', 'A\n']
Note:
none | ```python
n = int(input())
d = {}
ans = ""
m = 0
for i in range(n):
s = input()
if s not in d:
d[s] = 0
d[s] += 1
if d[s] > m:
m = d[s]
ans = s
print(ans)
``` | 3.9535 |
1,011 | A | Stages | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.
There are $n$ stages available. The rocket must contain exactly $k$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.
For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' — $26$ tons.
Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once. | The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket.
The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once. | Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all. | [
"5 3\nxyabd\n",
"7 4\nproblem\n",
"2 2\nab\n",
"12 1\nabaabbaaabbb\n"
] | [
"29",
"34",
"-1",
"1"
] | In the first example, the following rockets satisfy the condition:
- "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$).
Rocket "adx" has the minimal weight, so the answer is $29$.
In the second example, target rocket is "belo". Its weight is $2+5+12+15=34$.
In the third example, $n=k=2$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1. | 500 | [
{
"input": "5 3\nxyabd",
"output": "29"
},
{
"input": "7 4\nproblem",
"output": "34"
},
{
"input": "2 2\nab",
"output": "-1"
},
{
"input": "12 1\nabaabbaaabbb",
"output": "1"
},
{
"input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "169"
},
{
"input": "50 14\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "1 1\na",
"output": "1"
},
{
"input": "50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "1"
},
{
"input": "50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "13 13\nuwgmkyqeiaocs",
"output": "169"
},
{
"input": "13 13\nhzdxpbfvrltnj",
"output": "182"
},
{
"input": "1 1\nn",
"output": "14"
},
{
"input": "10 8\nsmzeblyjqw",
"output": "113"
},
{
"input": "20 20\ntzmvhskkyugkuuxpvtbh",
"output": "-1"
},
{
"input": "30 15\nwjzolzzkfulwgioksfxmcxmnnjtoav",
"output": "-1"
},
{
"input": "40 30\nxumfrflllrrgswehqtsskefixhcxjrxbjmrpsshv",
"output": "-1"
},
{
"input": "50 31\nahbyyoxltryqdmvenemaqnbakglgqolxnaifnqtoclnnqiabpz",
"output": "-1"
},
{
"input": "10 7\niuiukrxcml",
"output": "99"
},
{
"input": "38 2\nvjzarfykmrsrvwbwfwldsulhxtykmjbnwmdufa",
"output": "5"
},
{
"input": "12 6\nfwseyrarkwcd",
"output": "61"
},
{
"input": "2 2\nac",
"output": "4"
},
{
"input": "1 1\nc",
"output": "3"
},
{
"input": "2 2\nad",
"output": "5"
},
{
"input": "2 1\nac",
"output": "1"
},
{
"input": "4 3\nadjz",
"output": "15"
},
{
"input": "3 3\naoz",
"output": "42"
},
{
"input": "3 1\nzzz",
"output": "26"
},
{
"input": "2 1\nxz",
"output": "24"
},
{
"input": "5 1\naaddd",
"output": "1"
}
] | 1,533,982,344 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 23 | 124 | 0 | n, k = [int(a) for a in input().split()]
data = sorted(list(input()))
num = 1
a = 0
result = ord(data[0]) - 96
for i in range(1, n):
if ord(data[i]) - ord(data[a]) > 1:
num += 1
result += ord(data[i]) - 96
a = i
if num == k:
break
if num == k:
print(result)
else:
print(-1)
| Title: Stages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.
There are $n$ stages available. The rocket must contain exactly $k$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.
For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' — $26$ tons.
Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once.
Input Specification:
The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket.
The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once.
Output Specification:
Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.
Demo Input:
['5 3\nxyabd\n', '7 4\nproblem\n', '2 2\nab\n', '12 1\nabaabbaaabbb\n']
Demo Output:
['29', '34', '-1', '1']
Note:
In the first example, the following rockets satisfy the condition:
- "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$).
Rocket "adx" has the minimal weight, so the answer is $29$.
In the second example, target rocket is "belo". Its weight is $2+5+12+15=34$.
In the third example, $n=k=2$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1. | ```python
n, k = [int(a) for a in input().split()]
data = sorted(list(input()))
num = 1
a = 0
result = ord(data[0]) - 96
for i in range(1, n):
if ord(data[i]) - ord(data[a]) > 1:
num += 1
result += ord(data[i]) - 96
a = i
if num == k:
break
if num == k:
print(result)
else:
print(-1)
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | An atom of element X can exist in *n* distinct states with energies *E*1<=<<=*E*2<=<<=...<=<<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states *i*, *j* and *k* are selected, where *i*<=<<=*j*<=<<=*k*. After that the following process happens:
1. initially the atom is in the state *i*,1. we spend *E**k*<=-<=*E**i* energy to put the atom in the state *k*,1. the atom emits a photon with useful energy *E**k*<=-<=*E**j* and changes its state to the state *j*,1. the atom spontaneously changes its state to the state *i*, losing energy *E**j*<=-<=*E**i*,1. the process repeats from step 1.
Let's define the energy conversion efficiency as , i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that *E**k*<=-<=*E**i*<=≤<=*U*.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints. | The first line contains two integers *n* and *U* (3<=≤<=*n*<=≤<=105, 1<=≤<=*U*<=≤<=109) — the number of states and the maximum possible difference between *E**k* and *E**i*.
The second line contains a sequence of integers *E*1,<=*E*2,<=...,<=*E**n* (1<=≤<=*E*1<=<<=*E*2...<=<<=*E**n*<=≤<=109). It is guaranteed that all *E**i* are given in increasing order. | If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number η — the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10<=-<=9.
Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if . | [
"4 4\n1 3 5 7\n",
"10 8\n10 13 15 16 17 19 20 22 24 25\n",
"3 1\n2 5 10\n"
] | [
"0.5\n",
"0.875\n",
"-1\n"
] | In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/147ae7a830722917b0aa37d064df8eb74cfefb97.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f68f268de4eb2242167e6ec64e6b8aa60a5703ae.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 0 | [
{
"input": "4 4\n1 3 5 7",
"output": "0.5"
},
{
"input": "10 8\n10 13 15 16 17 19 20 22 24 25",
"output": "0.875"
},
{
"input": "3 1\n2 5 10",
"output": "-1"
},
{
"input": "5 3\n4 6 8 9 10",
"output": "0.5"
},
{
"input": "10 128\n110 121 140 158 174 188 251 271 272 277",
"output": "0.86554621848739499157"
},
{
"input": "20 17\n104 107 121 131 138 140 143 144 178 192 193 198 201 206 238 242 245 248 255 265",
"output": "0.92857142857142860315"
},
{
"input": "30 23\n102 104 105 107 108 109 110 111 116 118 119 122 127 139 140 142 145 157 166 171 173 174 175 181 187 190 191 193 195 196",
"output": "0.95652173913043481157"
},
{
"input": "50 64\n257 258 350 375 1014 1017 1051 1097 1169 1177 1223 1836 1942 1983 2111 2131 2341 2418 2593 2902 2948 3157 3243 3523 3566 4079 4499 4754 5060 5624 6279 6976 7011 7071 7278 7366 7408 7466 7526 7837 7934 8532 8577 8680 9221 9271 9327 9411 9590 9794",
"output": "0.91891891891891896993"
},
{
"input": "5 2\n4 6 8 9 10",
"output": "0.5"
},
{
"input": "10 2\n110 121 140 158 174 188 251 271 272 277",
"output": "-1"
},
{
"input": "30 5\n102 104 105 107 108 109 110 111 116 118 119 122 127 139 140 142 145 157 166 171 173 174 175 181 187 190 191 193 195 196",
"output": "0.80000000000000004441"
},
{
"input": "10 6\n110 121 140 158 174 188 251 271 272 277",
"output": "0.83333333333333337034"
},
{
"input": "20 4\n104 107 121 131 138 140 143 144 178 192 193 198 201 206 238 242 245 248 255 265",
"output": "0.25"
},
{
"input": "3 1000000000\n1 2 1000000000",
"output": "0.99999999900000002828"
},
{
"input": "3 1\n1 2 3",
"output": "-1"
},
{
"input": "5 1000000000\n1 2 3 999999999 1000000000",
"output": "0.99999999900000002828"
},
{
"input": "10 199\n1 3 190 191 193 195 196 197 199 200",
"output": "0.98994974874371854945"
},
{
"input": "10 300\n80 100 103 140 146 159 392 393 396 398",
"output": "0.98993288590604022747"
},
{
"input": "10 92\n44 119 252 281 303 323 351 363 377 392",
"output": "0.77528089887640450062"
},
{
"input": "4 2\n1 3 5 7",
"output": "-1"
},
{
"input": "8 2\n1 3 7 9 15 17 23 25",
"output": "-1"
},
{
"input": "3 5\n1 2 10",
"output": "-1"
},
{
"input": "4 7\n1 5 8 9",
"output": "0.42857142857142854764"
}
] | 1,521,911,974 | 6,274 | Python 3 | WRONG_ANSWER | PRETESTS | 5 | 93 | 7,065,600 | import array
n, U = list(map(int,input().split()))
a = input().split()
i = 0
j = 2
mx = -1
while i<n-3 and i<j-1:
while (j<n-1) and (int(a[j+1])-int(a[i]) <= U):
j += 1
mx = max(mx,(int(a[j])-int(a[i+1]))/(int(a[j])-int(a[i])))
i+=1
print(mx)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An atom of element X can exist in *n* distinct states with energies *E*1<=<<=*E*2<=<<=...<=<<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states *i*, *j* and *k* are selected, where *i*<=<<=*j*<=<<=*k*. After that the following process happens:
1. initially the atom is in the state *i*,1. we spend *E**k*<=-<=*E**i* energy to put the atom in the state *k*,1. the atom emits a photon with useful energy *E**k*<=-<=*E**j* and changes its state to the state *j*,1. the atom spontaneously changes its state to the state *i*, losing energy *E**j*<=-<=*E**i*,1. the process repeats from step 1.
Let's define the energy conversion efficiency as , i. e. the ration between the useful energy of the photon and spent energy.
Due to some limitations, Arkady can only choose such three states that *E**k*<=-<=*E**i*<=≤<=*U*.
Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.
Input Specification:
The first line contains two integers *n* and *U* (3<=≤<=*n*<=≤<=105, 1<=≤<=*U*<=≤<=109) — the number of states and the maximum possible difference between *E**k* and *E**i*.
The second line contains a sequence of integers *E*1,<=*E*2,<=...,<=*E**n* (1<=≤<=*E*1<=<<=*E*2...<=<<=*E**n*<=≤<=109). It is guaranteed that all *E**i* are given in increasing order.
Output Specification:
If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number η — the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10<=-<=9.
Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if .
Demo Input:
['4 4\n1 3 5 7\n', '10 8\n10 13 15 16 17 19 20 22 24 25\n', '3 1\n2 5 10\n']
Demo Output:
['0.5\n', '0.875\n', '-1\n']
Note:
In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/147ae7a830722917b0aa37d064df8eb74cfefb97.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second example choose states 4, 5 and 9, so that the energy conversion efficiency becomes equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f68f268de4eb2242167e6ec64e6b8aa60a5703ae.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
import array
n, U = list(map(int,input().split()))
a = input().split()
i = 0
j = 2
mx = -1
while i<n-3 and i<j-1:
while (j<n-1) and (int(a[j+1])-int(a[i]) <= U):
j += 1
mx = max(mx,(int(a[j])-int(a[i+1]))/(int(a[j])-int(a[i])))
i+=1
print(mx)
``` | 0 |
|
127 | B | Canvas Frames | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has *n* sticks whose lengths equal *a*1,<=*a*2,<=... *a**n*. Nicholas does not want to break the sticks or glue them together. To make a *h*<=×<=*w*-sized frame, he needs two sticks whose lengths equal *h* and two sticks whose lengths equal *w*. Specifically, to make a square frame (when *h*<==<=*w*), he needs four sticks of the same length.
Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of sticks. The second line contains *n* space-separated integers. The *i*-th integer equals the length of the *i*-th stick *a**i* (1<=≤<=*a**i*<=≤<=100). | Print the single number — the maximum number of frames Nicholas can make for his future canvases. | [
"5\n2 4 3 2 3\n",
"13\n2 2 4 4 4 4 6 6 6 7 7 9 9\n",
"4\n3 3 3 5\n"
] | [
"1",
"3",
"0"
] | none | 1,000 | [
{
"input": "5\n2 4 3 2 3",
"output": "1"
},
{
"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9",
"output": "3"
},
{
"input": "4\n3 3 3 5",
"output": "0"
},
{
"input": "2\n3 5",
"output": "0"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "0"
},
{
"input": "14\n2 4 2 6 2 3 4 1 4 5 4 3 4 1",
"output": "2"
},
{
"input": "33\n1 2 2 6 10 10 33 11 17 32 25 6 7 29 11 32 33 8 13 17 17 6 11 11 11 8 10 26 29 26 32 33 36",
"output": "5"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n10",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "3\n1 2 2",
"output": "0"
},
{
"input": "3\n3 2 1",
"output": "0"
},
{
"input": "4\n1 1 1 1",
"output": "1"
},
{
"input": "4\n1 2 1 2",
"output": "1"
},
{
"input": "4\n1 100 1 100",
"output": "1"
},
{
"input": "4\n10 100 100 10",
"output": "1"
},
{
"input": "4\n1 2 3 3",
"output": "0"
},
{
"input": "4\n8 5 9 13",
"output": "0"
},
{
"input": "4\n100 100 100 100",
"output": "1"
},
{
"input": "5\n1 1 1 1 1",
"output": "1"
},
{
"input": "5\n1 4 4 1 1",
"output": "1"
},
{
"input": "5\n1 100 1 1 100",
"output": "1"
},
{
"input": "5\n100 100 1 1 100",
"output": "1"
},
{
"input": "5\n100 1 100 100 100",
"output": "1"
},
{
"input": "5\n100 100 100 100 100",
"output": "1"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "1"
},
{
"input": "6\n1 1 5 1 1 5",
"output": "1"
},
{
"input": "6\n1 100 100 1 1 1",
"output": "1"
},
{
"input": "6\n100 1 1 100 1 100",
"output": "1"
},
{
"input": "6\n1 2 3 2 3 1",
"output": "1"
},
{
"input": "6\n1 50 1 100 50 100",
"output": "1"
},
{
"input": "6\n10 10 10 12 13 14",
"output": "0"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "7\n1 2 1 1 1 1 1",
"output": "1"
},
{
"input": "7\n1 2 2 1 2 1 2",
"output": "1"
},
{
"input": "7\n1 1 2 2 1 2 3",
"output": "1"
},
{
"input": "7\n1 3 2 2 3 1 4",
"output": "1"
},
{
"input": "7\n1 3 4 3 5 4 6",
"output": "1"
},
{
"input": "7\n7 6 5 4 3 2 1",
"output": "0"
},
{
"input": "8\n1 2 1 2 2 2 2 2",
"output": "2"
},
{
"input": "8\n1 2 2 1 1 2 2 2",
"output": "1"
},
{
"input": "8\n1 2 2 2 3 1 1 3",
"output": "1"
},
{
"input": "8\n1 2 3 4 1 2 3 4",
"output": "2"
},
{
"input": "8\n1 1 1 1 2 3 2 3",
"output": "2"
},
{
"input": "8\n1 2 3 4 5 5 5 5",
"output": "1"
},
{
"input": "8\n1 2 1 3 4 1 5 6",
"output": "0"
},
{
"input": "8\n1 2 3 4 5 6 1 7",
"output": "0"
},
{
"input": "8\n8 6 3 4 5 2 1 7",
"output": "0"
},
{
"input": "8\n100 100 100 100 100 100 100 100",
"output": "2"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10\n19 9 14 14 19 5 5 18 10 17",
"output": "1"
},
{
"input": "10\n72 86 73 25 84 29 33 34 20 29",
"output": "0"
},
{
"input": "10\n93 93 99 98 91 96 92 98 94 98",
"output": "1"
},
{
"input": "13\n35 6 21 30 67 55 70 39 75 72 11 13 69",
"output": "0"
},
{
"input": "17\n90 97 12 56 94 11 49 96 22 7 15 48 71 71 94 72 100",
"output": "1"
},
{
"input": "18\n39 72 67 28 69 41 43 51 66 99 4 57 68 93 28 27 37 27",
"output": "1"
},
{
"input": "23\n88 82 2 67 4 6 67 83 77 58 48 64 86 37 96 83 35 46 13 79 72 18 35",
"output": "1"
},
{
"input": "30\n43 34 38 50 47 24 26 20 7 5 26 29 98 87 90 46 10 53 88 61 90 39 78 81 65 13 72 95 53 27",
"output": "1"
},
{
"input": "33\n1 3 34 55 38 58 64 26 66 44 50 63 46 62 62 99 73 87 35 20 30 38 39 85 49 24 93 68 8 25 86 30 51",
"output": "1"
},
{
"input": "38\n65 69 80 93 28 36 40 81 53 75 55 50 82 95 8 51 66 65 50 4 40 92 18 70 38 68 42 100 34 57 98 79 95 84 82 35 100 89",
"output": "3"
},
{
"input": "40\n4 2 62 38 76 68 19 71 44 91 76 31 3 63 56 62 93 98 10 61 52 59 81 46 23 27 36 26 24 38 37 66 15 16 78 41 95 82 73 90",
"output": "1"
},
{
"input": "43\n62 31 14 43 67 2 60 77 64 70 91 9 3 43 76 7 56 84 5 20 88 50 47 42 7 39 8 56 71 24 49 59 70 61 81 17 76 44 80 61 77 5 96",
"output": "4"
},
{
"input": "49\n75 64 7 2 1 66 31 84 78 53 34 5 40 90 7 62 86 54 99 77 8 92 30 3 18 18 61 38 38 11 79 88 84 89 50 94 72 8 54 85 100 1 19 4 97 91 13 39 91",
"output": "4"
},
{
"input": "57\n83 94 42 57 19 9 40 25 56 92 9 38 58 66 43 19 50 10 100 3 49 96 77 36 20 3 48 15 38 19 99 100 66 14 52 13 16 73 65 99 29 85 75 18 97 64 57 82 70 19 16 25 40 11 9 22 89",
"output": "6"
},
{
"input": "67\n36 22 22 86 52 53 36 68 46 82 99 37 15 43 57 35 33 99 22 96 7 8 80 93 70 70 55 51 61 74 6 28 85 72 84 42 29 1 4 71 7 40 61 95 93 36 42 61 16 40 10 85 31 86 93 19 44 20 52 66 10 22 40 53 25 29 23",
"output": "8"
},
{
"input": "74\n90 26 58 69 87 23 44 9 32 25 33 13 79 84 52 90 4 7 93 77 29 85 22 1 96 69 98 16 76 87 57 16 44 41 57 28 18 70 77 83 37 17 59 87 27 19 89 63 14 84 77 40 46 77 82 73 86 73 30 58 6 30 70 36 31 12 43 50 93 3 3 57 38 91",
"output": "7"
},
{
"input": "87\n10 19 83 58 15 48 26 58 89 46 50 34 81 40 25 51 62 85 9 80 71 44 100 22 30 48 74 69 54 40 38 81 66 42 40 90 60 20 75 24 74 98 28 62 79 65 65 6 14 23 3 59 29 24 64 13 8 38 29 85 75 81 36 42 3 63 99 24 72 92 35 8 71 19 77 77 66 3 79 65 15 18 15 69 60 77 91",
"output": "11"
},
{
"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": "25"
},
{
"input": "100\n1 9 3 5 10 10 9 8 10 1 7 6 5 6 7 9 1 5 8 3 2 3 3 10 2 3 10 7 10 3 6 3 2 10 1 10 2 3 4 3 3 1 7 5 10 2 3 8 9 2 5 4 7 2 5 9 2 1 7 9 9 8 4 4 6 1 6 6 4 7 2 3 1 1 1 6 9 1 2 9 3 7 6 10 3 6 2 5 2 5 3 9 10 6 4 2 9 9 4 5",
"output": "23"
},
{
"input": "100\n70 70 75 70 74 70 70 73 72 73 74 75 70 74 73 70 70 74 72 72 75 70 73 72 70 75 73 70 74 70 73 75 71 74 70 71 75 74 75 71 74 70 73 73 70 75 71 73 73 74 73 74 71 73 73 71 72 71 70 75 74 74 72 72 71 72 75 75 70 73 71 73 72 71 70 75 71 75 73 75 73 72 75 71 73 71 72 74 75 70 70 74 75 73 70 73 73 75 71 74",
"output": "24"
},
{
"input": "100\n99 98 98 99 98 98 98 100 98 99 99 98 99 98 98 98 99 99 98 99 99 100 98 100 98 98 98 99 98 100 100 98 100 99 100 98 99 99 99 98 100 98 100 99 99 99 98 100 98 98 98 100 100 99 98 98 100 100 100 99 98 99 99 99 100 99 99 98 99 98 99 100 100 98 98 100 100 99 99 99 98 98 98 100 99 99 100 99 100 99 98 100 98 100 98 98 99 98 99 98",
"output": "24"
},
{
"input": "100\n94 87 92 91 94 89 93 94 87 93 93 94 89 91 87 87 92 91 87 94 90 89 92 92 87 88 90 90 90 89 90 92 91 91 89 88 93 89 88 94 91 89 88 87 92 89 91 87 88 90 88 92 90 87 93 94 94 92 92 87 90 88 88 91 94 93 87 94 93 93 87 90 92 92 90 88 88 90 92 91 90 88 89 91 91 88 90 93 90 94 94 93 90 91 91 93 94 94 92 93",
"output": "24"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "25"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "7\n13 13 13 13 6 2 3",
"output": "1"
},
{
"input": "8\n1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "5\n100 100 99 99 5",
"output": "1"
},
{
"input": "8\n2 2 2 2 2 2 2 2",
"output": "2"
},
{
"input": "8\n1 2 3 4 5 6 7 7",
"output": "0"
},
{
"input": "8\n4 4 4 4 4 4 4 4",
"output": "2"
},
{
"input": "10\n1 1 1 1 1 1 1 1 2 2",
"output": "2"
},
{
"input": "4\n100 100 100 99",
"output": "0"
},
{
"input": "4\n2 2 2 2",
"output": "1"
},
{
"input": "5\n100 100 99 99 2",
"output": "1"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "5\n2 2 3 4 4",
"output": "1"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "25"
},
{
"input": "13\n1 2 3 4 5 6 7 8 9 10 11 12 13",
"output": "0"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "5"
},
{
"input": "4\n4 4 4 4",
"output": "1"
},
{
"input": "5\n1 1 2 3 3",
"output": "1"
},
{
"input": "5\n30 30 30 1 1",
"output": "1"
}
] | 1,669,039,342 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 93 | 62 | 0 | import math
n = int(input())
sticks = list(map(int,input().split()))
sticks.sort()
pair = 0
count = 1
for index in range(len(sticks)-1):
if sticks[index] == sticks[index+1]:
count = count + 1
if index == len(sticks)-2:
pair = pair + math.floor(count/2)
else:
pair = pair + math.floor(count/2)
count = 1
frames = math.floor(pair/2)
print(frames) | Title: Canvas Frames
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has *n* sticks whose lengths equal *a*1,<=*a*2,<=... *a**n*. Nicholas does not want to break the sticks or glue them together. To make a *h*<=×<=*w*-sized frame, he needs two sticks whose lengths equal *h* and two sticks whose lengths equal *w*. Specifically, to make a square frame (when *h*<==<=*w*), he needs four sticks of the same length.
Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of sticks. The second line contains *n* space-separated integers. The *i*-th integer equals the length of the *i*-th stick *a**i* (1<=≤<=*a**i*<=≤<=100).
Output Specification:
Print the single number — the maximum number of frames Nicholas can make for his future canvases.
Demo Input:
['5\n2 4 3 2 3\n', '13\n2 2 4 4 4 4 6 6 6 7 7 9 9\n', '4\n3 3 3 5\n']
Demo Output:
['1', '3', '0']
Note:
none | ```python
import math
n = int(input())
sticks = list(map(int,input().split()))
sticks.sort()
pair = 0
count = 1
for index in range(len(sticks)-1):
if sticks[index] == sticks[index+1]:
count = count + 1
if index == len(sticks)-2:
pair = pair + math.floor(count/2)
else:
pair = pair + math.floor(count/2)
count = 1
frames = math.floor(pair/2)
print(frames)
``` | 3 |
|
633 | C | Spy Syndrome 2 | PROGRAMMING | 1,900 | [
"data structures",
"dp",
"hashing",
"implementation",
"sortings",
"string suffix structures",
"strings"
] | null | null | After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentences, Yash determined a new cipher technique.
For a given sentence, the cipher is processed as:
1. Convert all letters of the sentence to lowercase. 1. Reverse each of the words of the sentence individually. 1. Remove all the spaces in the sentence.
For example, when this cipher is applied to the sentence
Kira is childish and he hates losing
the resulting string is
ariksihsidlihcdnaehsetahgnisol
Now Yash is given some ciphered string and a list of words. Help him to find out any original sentence composed using only words from the list. Note, that any of the given words could be used in the sentence multiple times. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10<=000) — the length of the ciphered text. The second line consists of *n* lowercase English letters — the ciphered text *t*.
The third line contains a single integer *m* (1<=≤<=*m*<=≤<=100<=000) — the number of words which will be considered while deciphering the text. Each of the next *m* lines contains a non-empty word *w**i* (|*w**i*|<=≤<=1<=000) consisting of uppercase and lowercase English letters only. It's guaranteed that the total length of all words doesn't exceed 1<=000<=000. | Print one line — the original sentence. It is guaranteed that at least one solution exists. If there are multiple solutions, you may output any of those. | [
"30\nariksihsidlihcdnaehsetahgnisol\n10\nKira\nhates\nis\nhe\nlosing\ndeath\nchildish\nL\nand\nNote\n",
"12\niherehtolleh\n5\nHI\nHo\nthere\nHeLLo\nhello\n"
] | [
"Kira is childish and he hates losing \n",
"HI there HeLLo \n"
] | In sample case 2 there may be multiple accepted outputs, "HI there HeLLo" and "HI there hello" you may output any of them. | 1,500 | [
{
"input": "30\nariksihsidlihcdnaehsetahgnisol\n10\nKira\nhates\nis\nhe\nlosing\ndeath\nchildish\nL\nand\nNote",
"output": "Kira is childish and he hates losing "
},
{
"input": "12\niherehtolleh\n5\nHI\nHo\nthere\nHeLLo\nhello",
"output": "HI there HeLLo "
},
{
"input": "71\nbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n8\na\naa\naaa\naaaa\naaaaa\naaaaaa\naaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab "
},
{
"input": "11\naaaaaaaaaaa\n3\naaaa\naaaaa\naaaaaa",
"output": "aaaaaa aaaaa "
},
{
"input": "5\ncbaed\n6\nbc\nea\nab\ncd\nabc\nde",
"output": "abc de "
},
{
"input": "5\nlehet\n3\nel\nhel\nte",
"output": "hel te "
},
{
"input": "3\naab\n2\na\nbaa",
"output": "baa "
},
{
"input": "3\naab\n2\naa\nbaa",
"output": "baa "
},
{
"input": "9\naaaaaaaaa\n2\naa\naaa",
"output": "aaa aa aa aa "
},
{
"input": "7\nabababc\n2\nba\ncba",
"output": "ba ba cba "
},
{
"input": "7\nkirkirk\n2\nrik\nkrik",
"output": "rik krik "
}
] | 1,564,587,198 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | qtd = int(input())
text, resposta = input(), list()
palavras, utilizado = int(input()), set()
prefixo = dict()
for i in range(qtd):
for j in range(i+1, qtd+1):
if text[i:j][::-1] not in prefixo:
prefixo[text[i:j][::-1]] = i+j
for _ in range(palavras):
palavra = input()
palavra_lower = palavra.lower()
if len(palavra) > 1 and palavra_lower in prefixo and not palavra_lower in utilizado:
resposta.append((prefixo[palavra_lower], palavra))
utilizado.add(palavra_lower)
print([palavra for indice, palavra in sorted(resposta)]) | Title: Spy Syndrome 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentences, Yash determined a new cipher technique.
For a given sentence, the cipher is processed as:
1. Convert all letters of the sentence to lowercase. 1. Reverse each of the words of the sentence individually. 1. Remove all the spaces in the sentence.
For example, when this cipher is applied to the sentence
Kira is childish and he hates losing
the resulting string is
ariksihsidlihcdnaehsetahgnisol
Now Yash is given some ciphered string and a list of words. Help him to find out any original sentence composed using only words from the list. Note, that any of the given words could be used in the sentence multiple times.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10<=000) — the length of the ciphered text. The second line consists of *n* lowercase English letters — the ciphered text *t*.
The third line contains a single integer *m* (1<=≤<=*m*<=≤<=100<=000) — the number of words which will be considered while deciphering the text. Each of the next *m* lines contains a non-empty word *w**i* (|*w**i*|<=≤<=1<=000) consisting of uppercase and lowercase English letters only. It's guaranteed that the total length of all words doesn't exceed 1<=000<=000.
Output Specification:
Print one line — the original sentence. It is guaranteed that at least one solution exists. If there are multiple solutions, you may output any of those.
Demo Input:
['30\nariksihsidlihcdnaehsetahgnisol\n10\nKira\nhates\nis\nhe\nlosing\ndeath\nchildish\nL\nand\nNote\n', '12\niherehtolleh\n5\nHI\nHo\nthere\nHeLLo\nhello\n']
Demo Output:
['Kira is childish and he hates losing \n', 'HI there HeLLo \n']
Note:
In sample case 2 there may be multiple accepted outputs, "HI there HeLLo" and "HI there hello" you may output any of them. | ```python
qtd = int(input())
text, resposta = input(), list()
palavras, utilizado = int(input()), set()
prefixo = dict()
for i in range(qtd):
for j in range(i+1, qtd+1):
if text[i:j][::-1] not in prefixo:
prefixo[text[i:j][::-1]] = i+j
for _ in range(palavras):
palavra = input()
palavra_lower = palavra.lower()
if len(palavra) > 1 and palavra_lower in prefixo and not palavra_lower in utilizado:
resposta.append((prefixo[palavra_lower], palavra))
utilizado.add(palavra_lower)
print([palavra for indice, palavra in sorted(resposta)])
``` | 0 |
|
340 | A | The Wall | PROGRAMMING | 1,200 | [
"math"
] | null | null | Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints the *x*-th one. That is, he'll paint bricks *x*, 2·*x*, 3·*x* and so on red. Similarly, Floyd skips *y*<=-<=1 consecutive bricks, then he paints the *y*-th one. Hence he'll paint bricks *y*, 2·*y*, 3·*y* and so on pink.
After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number *a* and Floyd has a lucky number *b*. Boys wonder how many bricks numbered no less than *a* and no greater than *b* are painted both red and pink. This is exactly your task: compute and print the answer to the question. | The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*). | Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink. | [
"2 3 6 18\n"
] | [
"3"
] | Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18. | 500 | [
{
"input": "2 3 6 18",
"output": "3"
},
{
"input": "4 6 20 201",
"output": "15"
},
{
"input": "15 27 100 10000",
"output": "74"
},
{
"input": "105 60 3456 78910",
"output": "179"
},
{
"input": "1 1 1000 100000",
"output": "99001"
},
{
"input": "3 2 5 5",
"output": "0"
},
{
"input": "555 777 1 1000000",
"output": "257"
},
{
"input": "1000 1000 1 32323",
"output": "32"
},
{
"input": "45 125 93451125 100000000",
"output": "5821"
},
{
"input": "101 171 1 1000000000",
"output": "57900"
},
{
"input": "165 255 69696 1000000000",
"output": "356482"
},
{
"input": "555 777 666013 1000000000",
"output": "257229"
},
{
"input": "23 46 123321 900000000",
"output": "19562537"
},
{
"input": "321 123 15 1000000",
"output": "75"
},
{
"input": "819 1000 9532 152901000",
"output": "186"
},
{
"input": "819 1000 10000 1000000",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "1 2 2 1000003",
"output": "500001"
},
{
"input": "1 1 1 1000000000",
"output": "1000000000"
},
{
"input": "10 15 69 195610342",
"output": "6520342"
},
{
"input": "2 1 1 1000000000",
"output": "500000000"
},
{
"input": "1000 1000 1 20",
"output": "0"
},
{
"input": "1 1 1 2000000000",
"output": "2000000000"
},
{
"input": "1 2 1 2000000000",
"output": "1000000000"
},
{
"input": "2 1 1 2000000000",
"output": "1000000000"
},
{
"input": "2 3 1 1000000000",
"output": "166666666"
},
{
"input": "2 3 1 2000000000",
"output": "333333333"
},
{
"input": "3 7 1 1000000000",
"output": "47619047"
},
{
"input": "1 1 1000000000 2000000000",
"output": "1000000001"
},
{
"input": "2 2 1 2000000000",
"output": "1000000000"
},
{
"input": "1 1 2 2000000000",
"output": "1999999999"
},
{
"input": "3 2 1 2000000000",
"output": "333333333"
},
{
"input": "1 1 2000000000 2000000000",
"output": "1"
},
{
"input": "2 3 7 7",
"output": "0"
},
{
"input": "3 3 3 7",
"output": "2"
}
] | 1,378,578,366 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 0 | I=[int(i) for i in input().split()]
x, y, a, b = I[0], I[1], I[2], I[3]
low=min(x,y)
high=max(x,y)
current=int(a/high)*high
if a%high!=0: current+=high
ans=0
while current<=b:
if current%low==0: ans+=1
current+=high
print(ans) | Title: The Wall
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints the *x*-th one. That is, he'll paint bricks *x*, 2·*x*, 3·*x* and so on red. Similarly, Floyd skips *y*<=-<=1 consecutive bricks, then he paints the *y*-th one. Hence he'll paint bricks *y*, 2·*y*, 3·*y* and so on pink.
After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number *a* and Floyd has a lucky number *b*. Boys wonder how many bricks numbered no less than *a* and no greater than *b* are painted both red and pink. This is exactly your task: compute and print the answer to the question.
Input Specification:
The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*).
Output Specification:
Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink.
Demo Input:
['2 3 6 18\n']
Demo Output:
['3']
Note:
Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18. | ```python
I=[int(i) for i in input().split()]
x, y, a, b = I[0], I[1], I[2], I[3]
low=min(x,y)
high=max(x,y)
current=int(a/high)*high
if a%high!=0: current+=high
ans=0
while current<=b:
if current%low==0: ans+=1
current+=high
print(ans)
``` | 0 |
|
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9).
What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel. | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels. | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change. | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
"output": "1"
},
{
"input": "1000 9",
"output": "1"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "999 9",
"output": "1"
},
{
"input": "999 8",
"output": "2"
},
{
"input": "105 6",
"output": "2"
},
{
"input": "403 9",
"output": "3"
},
{
"input": "546 4",
"output": "4"
},
{
"input": "228 9",
"output": "5"
},
{
"input": "57 2",
"output": "6"
},
{
"input": "437 9",
"output": "7"
},
{
"input": "997 6",
"output": "8"
},
{
"input": "109 1",
"output": "9"
},
{
"input": "998 9",
"output": "5"
},
{
"input": "4 2",
"output": "3"
},
{
"input": "9 3",
"output": "7"
},
{
"input": "8 2",
"output": "4"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "1 4",
"output": "4"
},
{
"input": "1 5",
"output": "5"
},
{
"input": "1 6",
"output": "6"
},
{
"input": "1 7",
"output": "7"
},
{
"input": "1 8",
"output": "8"
},
{
"input": "100 3",
"output": "1"
},
{
"input": "1000 2",
"output": "1"
},
{
"input": "1000 4",
"output": "1"
},
{
"input": "1000 5",
"output": "1"
},
{
"input": "1000 6",
"output": "1"
},
{
"input": "1000 7",
"output": "1"
},
{
"input": "1000 8",
"output": "1"
},
{
"input": "23 4",
"output": "8"
},
{
"input": "33 1",
"output": "7"
},
{
"input": "33 2",
"output": "4"
},
{
"input": "666 5",
"output": "5"
},
{
"input": "2 3",
"output": "5"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "12 4",
"output": "2"
},
{
"input": "15 5",
"output": "1"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "25 5",
"output": "1"
},
{
"input": "2 9",
"output": "5"
},
{
"input": "6 7",
"output": "5"
},
{
"input": "8 9",
"output": "5"
},
{
"input": "2 7",
"output": "5"
},
{
"input": "4 7",
"output": "5"
},
{
"input": "2 1",
"output": "5"
},
{
"input": "261 1",
"output": "1"
}
] | 1,684,598,231 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | l = input()
list1 = l.split(" ")
k = int(list1[0])
r = int(list1[1])
count =0
sum = 0
flag = 0
while flag == 0 :
sum += k
count += 1
if sum%10 ==0 :
flag = 1
print (count)
else :
sum -= r
if sum % 10 == 0:
flag = 1
print(count)
else :
sum += r
| Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9).
What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
Input Specification:
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
Output Specification:
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
Demo Input:
['117 3\n', '237 7\n', '15 2\n']
Demo Output:
['9\n', '1\n', '2\n']
Note:
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change. | ```python
l = input()
list1 = l.split(" ")
k = int(list1[0])
r = int(list1[1])
count =0
sum = 0
flag = 0
while flag == 0 :
sum += k
count += 1
if sum%10 ==0 :
flag = 1
print (count)
else :
sum -= r
if sum % 10 == 0:
flag = 1
print(count)
else :
sum += r
``` | 3 |
|
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems. | In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters. | In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReality\nSoul\nSpace\nMind"
},
{
"input": "3\nblue\norange\npurple",
"output": "3\nTime\nReality\nMind"
},
{
"input": "2\nyellow\nred",
"output": "4\nPower\nSoul\nSpace\nTime"
},
{
"input": "1\ngreen",
"output": "5\nReality\nSpace\nPower\nSoul\nMind"
},
{
"input": "2\npurple\ngreen",
"output": "4\nReality\nMind\nSpace\nSoul"
},
{
"input": "1\nblue",
"output": "5\nPower\nReality\nSoul\nTime\nMind"
},
{
"input": "2\npurple\nblue",
"output": "4\nMind\nSoul\nTime\nReality"
},
{
"input": "2\ngreen\nblue",
"output": "4\nReality\nMind\nPower\nSoul"
},
{
"input": "3\npurple\ngreen\nblue",
"output": "3\nMind\nReality\nSoul"
},
{
"input": "1\norange",
"output": "5\nReality\nTime\nPower\nSpace\nMind"
},
{
"input": "2\npurple\norange",
"output": "4\nReality\nMind\nTime\nSpace"
},
{
"input": "2\norange\ngreen",
"output": "4\nSpace\nMind\nReality\nPower"
},
{
"input": "3\norange\npurple\ngreen",
"output": "3\nReality\nSpace\nMind"
},
{
"input": "2\norange\nblue",
"output": "4\nTime\nMind\nReality\nPower"
},
{
"input": "3\nblue\ngreen\norange",
"output": "3\nPower\nMind\nReality"
},
{
"input": "4\nblue\norange\ngreen\npurple",
"output": "2\nMind\nReality"
},
{
"input": "1\nred",
"output": "5\nTime\nSoul\nMind\nPower\nSpace"
},
{
"input": "2\nred\npurple",
"output": "4\nMind\nSpace\nTime\nSoul"
},
{
"input": "2\nred\ngreen",
"output": "4\nMind\nSpace\nPower\nSoul"
},
{
"input": "3\nred\npurple\ngreen",
"output": "3\nSoul\nSpace\nMind"
},
{
"input": "2\nblue\nred",
"output": "4\nMind\nTime\nPower\nSoul"
},
{
"input": "3\nred\nblue\npurple",
"output": "3\nTime\nMind\nSoul"
},
{
"input": "3\nred\nblue\ngreen",
"output": "3\nSoul\nPower\nMind"
},
{
"input": "4\npurple\nblue\ngreen\nred",
"output": "2\nMind\nSoul"
},
{
"input": "2\norange\nred",
"output": "4\nPower\nMind\nTime\nSpace"
},
{
"input": "3\nred\norange\npurple",
"output": "3\nMind\nSpace\nTime"
},
{
"input": "3\nred\norange\ngreen",
"output": "3\nMind\nSpace\nPower"
},
{
"input": "4\nred\norange\ngreen\npurple",
"output": "2\nSpace\nMind"
},
{
"input": "3\nblue\norange\nred",
"output": "3\nPower\nMind\nTime"
},
{
"input": "4\norange\nblue\npurple\nred",
"output": "2\nTime\nMind"
},
{
"input": "4\ngreen\norange\nred\nblue",
"output": "2\nMind\nPower"
},
{
"input": "5\npurple\norange\nblue\nred\ngreen",
"output": "1\nMind"
},
{
"input": "1\nyellow",
"output": "5\nPower\nSoul\nReality\nSpace\nTime"
},
{
"input": "2\npurple\nyellow",
"output": "4\nTime\nReality\nSpace\nSoul"
},
{
"input": "2\ngreen\nyellow",
"output": "4\nSpace\nReality\nPower\nSoul"
},
{
"input": "3\npurple\nyellow\ngreen",
"output": "3\nSoul\nReality\nSpace"
},
{
"input": "2\nblue\nyellow",
"output": "4\nTime\nReality\nPower\nSoul"
},
{
"input": "3\nyellow\nblue\npurple",
"output": "3\nSoul\nReality\nTime"
},
{
"input": "3\ngreen\nyellow\nblue",
"output": "3\nSoul\nReality\nPower"
},
{
"input": "4\nyellow\nblue\ngreen\npurple",
"output": "2\nReality\nSoul"
},
{
"input": "2\nyellow\norange",
"output": "4\nTime\nSpace\nReality\nPower"
},
{
"input": "3\nyellow\npurple\norange",
"output": "3\nSpace\nReality\nTime"
},
{
"input": "3\norange\nyellow\ngreen",
"output": "3\nSpace\nReality\nPower"
},
{
"input": "4\ngreen\nyellow\norange\npurple",
"output": "2\nSpace\nReality"
},
{
"input": "3\nyellow\nblue\norange",
"output": "3\nTime\nReality\nPower"
},
{
"input": "4\norange\npurple\nblue\nyellow",
"output": "2\nReality\nTime"
},
{
"input": "4\nblue\norange\nyellow\ngreen",
"output": "2\nReality\nPower"
},
{
"input": "5\ngreen\nyellow\norange\nblue\npurple",
"output": "1\nReality"
},
{
"input": "3\nyellow\npurple\nred",
"output": "3\nTime\nSoul\nSpace"
},
{
"input": "3\nred\ngreen\nyellow",
"output": "3\nPower\nSoul\nSpace"
},
{
"input": "4\nred\npurple\ngreen\nyellow",
"output": "2\nSpace\nSoul"
},
{
"input": "3\nred\nyellow\nblue",
"output": "3\nPower\nSoul\nTime"
},
{
"input": "4\nblue\nyellow\nred\npurple",
"output": "2\nTime\nSoul"
},
{
"input": "4\nblue\nyellow\nred\ngreen",
"output": "2\nSoul\nPower"
},
{
"input": "5\nred\nyellow\ngreen\nblue\npurple",
"output": "1\nSoul"
},
{
"input": "3\nred\nyellow\norange",
"output": "3\nPower\nSpace\nTime"
},
{
"input": "4\norange\ngreen\nyellow\nred",
"output": "2\nPower\nSpace"
},
{
"input": "5\norange\nred\ngreen\nyellow\npurple",
"output": "1\nSpace"
},
{
"input": "4\nyellow\nred\norange\nblue",
"output": "2\nTime\nPower"
},
{
"input": "5\npurple\nblue\norange\nyellow\nred",
"output": "1\nTime"
},
{
"input": "5\norange\nblue\nyellow\nred\ngreen",
"output": "1\nPower"
}
] | 1,647,595,854 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 46 | 0 | a=int(input())
gr=0
pu=0
bl=0
ore=0
r=0
y=0
p=0
for i in range(a):
v=input()
if v=='purple':
pu=v
p+=1
if v=='green':
gr=v
p+=1
if v=='blue':
bl=v
p+=1
if v=='orange':
ore=v
p+=1
if v=='red':
r=v
p+=1
if v=='yellow':
y=v
p+=1
print(6-p)
if pu==0:
print('Power')
if gr==0:
print('Time')
if bl==0:
print('Space')
if ore==0:
print('Soul')
if r==0:
print('Reality')
if y==0:
print('Mind') | Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input Specification:
In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output Specification:
In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Demo Input:
['4\nred\npurple\nyellow\norange\n', '0\n']
Demo Output:
['2\nSpace\nTime\n', '6\nTime\nMind\nSoul\nPower\nReality\nSpace\n']
Note:
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | ```python
a=int(input())
gr=0
pu=0
bl=0
ore=0
r=0
y=0
p=0
for i in range(a):
v=input()
if v=='purple':
pu=v
p+=1
if v=='green':
gr=v
p+=1
if v=='blue':
bl=v
p+=1
if v=='orange':
ore=v
p+=1
if v=='red':
r=v
p+=1
if v=='yellow':
y=v
p+=1
print(6-p)
if pu==0:
print('Power')
if gr==0:
print('Time')
if bl==0:
print('Space')
if ore==0:
print('Soul')
if r==0:
print('Reality')
if y==0:
print('Mind')
``` | 3 |
|
770 | B | Maximize Sum of Digits | PROGRAMMING | 1,300 | [
"*special",
"implementation",
"math"
] | null | null | Anton has the integer *x*. He is interested what positive integer, which doesn't exceed *x*, has the maximum sum of digits.
Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them. | The first line contains the positive integer *x* (1<=≤<=*x*<=≤<=1018) — the integer which Anton has. | Print the positive integer which doesn't exceed *x* and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros. | [
"100\n",
"48\n",
"521\n"
] | [
"99\n",
"48\n",
"499\n"
] | none | 1,000 | [
{
"input": "100",
"output": "99"
},
{
"input": "48",
"output": "48"
},
{
"input": "521",
"output": "499"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "3"
},
{
"input": "39188",
"output": "38999"
},
{
"input": "5",
"output": "5"
},
{
"input": "6",
"output": "6"
},
{
"input": "7",
"output": "7"
},
{
"input": "8",
"output": "8"
},
{
"input": "9",
"output": "9"
},
{
"input": "10",
"output": "9"
},
{
"input": "59999154",
"output": "59998999"
},
{
"input": "1000",
"output": "999"
},
{
"input": "10000",
"output": "9999"
},
{
"input": "100000",
"output": "99999"
},
{
"input": "1000000",
"output": "999999"
},
{
"input": "10000000",
"output": "9999999"
},
{
"input": "100000000",
"output": "99999999"
},
{
"input": "1000000000",
"output": "999999999"
},
{
"input": "10000000000",
"output": "9999999999"
},
{
"input": "100000000000",
"output": "99999999999"
},
{
"input": "1000000000000",
"output": "999999999999"
},
{
"input": "10000000000000",
"output": "9999999999999"
},
{
"input": "100000000000000",
"output": "99999999999999"
},
{
"input": "1000000000000000",
"output": "999999999999999"
},
{
"input": "10000000000000000",
"output": "9999999999999999"
},
{
"input": "100000000000000000",
"output": "99999999999999999"
},
{
"input": "1000000000000000000",
"output": "999999999999999999"
},
{
"input": "999999990",
"output": "999999989"
},
{
"input": "666666899789879",
"output": "599999999999999"
},
{
"input": "65499992294999000",
"output": "59999999999999999"
},
{
"input": "9879100000000099",
"output": "8999999999999999"
},
{
"input": "9991919190909919",
"output": "9989999999999999"
},
{
"input": "978916546899999999",
"output": "899999999999999999"
},
{
"input": "5684945999999999",
"output": "4999999999999999"
},
{
"input": "999999999999999999",
"output": "999999999999999999"
},
{
"input": "999999999999990999",
"output": "999999999999989999"
},
{
"input": "999999999999999990",
"output": "999999999999999989"
},
{
"input": "909999999999999999",
"output": "899999999999999999"
},
{
"input": "199999999999999999",
"output": "199999999999999999"
},
{
"input": "299999999999999999",
"output": "299999999999999999"
},
{
"input": "999999990009999999",
"output": "999999989999999999"
},
{
"input": "999000000001999999",
"output": "998999999999999999"
},
{
"input": "999999999991",
"output": "999999999989"
},
{
"input": "999999999992",
"output": "999999999989"
},
{
"input": "79320",
"output": "78999"
},
{
"input": "99004",
"output": "98999"
},
{
"input": "99088",
"output": "98999"
},
{
"input": "99737",
"output": "98999"
},
{
"input": "29652",
"output": "28999"
},
{
"input": "59195",
"output": "58999"
},
{
"input": "19930",
"output": "19899"
},
{
"input": "49533",
"output": "48999"
},
{
"input": "69291",
"output": "68999"
},
{
"input": "59452",
"output": "58999"
},
{
"input": "11",
"output": "9"
},
{
"input": "110",
"output": "99"
},
{
"input": "111",
"output": "99"
},
{
"input": "119",
"output": "99"
},
{
"input": "118",
"output": "99"
},
{
"input": "1100",
"output": "999"
},
{
"input": "1199",
"output": "999"
},
{
"input": "1109",
"output": "999"
},
{
"input": "1190",
"output": "999"
},
{
"input": "12",
"output": "9"
},
{
"input": "120",
"output": "99"
},
{
"input": "121",
"output": "99"
},
{
"input": "129",
"output": "99"
},
{
"input": "128",
"output": "99"
},
{
"input": "1200",
"output": "999"
},
{
"input": "1299",
"output": "999"
},
{
"input": "1209",
"output": "999"
},
{
"input": "1290",
"output": "999"
},
{
"input": "13",
"output": "9"
},
{
"input": "130",
"output": "99"
},
{
"input": "131",
"output": "99"
},
{
"input": "139",
"output": "99"
},
{
"input": "138",
"output": "99"
},
{
"input": "1300",
"output": "999"
},
{
"input": "1399",
"output": "999"
},
{
"input": "1309",
"output": "999"
},
{
"input": "1390",
"output": "999"
},
{
"input": "14",
"output": "9"
},
{
"input": "140",
"output": "99"
},
{
"input": "141",
"output": "99"
},
{
"input": "149",
"output": "99"
},
{
"input": "148",
"output": "99"
},
{
"input": "1400",
"output": "999"
},
{
"input": "1499",
"output": "999"
},
{
"input": "1409",
"output": "999"
},
{
"input": "1490",
"output": "999"
},
{
"input": "15",
"output": "9"
},
{
"input": "150",
"output": "99"
},
{
"input": "151",
"output": "99"
},
{
"input": "159",
"output": "99"
},
{
"input": "158",
"output": "99"
},
{
"input": "1500",
"output": "999"
},
{
"input": "1599",
"output": "999"
},
{
"input": "1509",
"output": "999"
},
{
"input": "1590",
"output": "999"
},
{
"input": "16",
"output": "9"
},
{
"input": "160",
"output": "99"
},
{
"input": "161",
"output": "99"
},
{
"input": "169",
"output": "99"
},
{
"input": "168",
"output": "99"
},
{
"input": "1600",
"output": "999"
},
{
"input": "1699",
"output": "999"
},
{
"input": "1609",
"output": "999"
},
{
"input": "1690",
"output": "999"
},
{
"input": "17",
"output": "9"
},
{
"input": "170",
"output": "99"
},
{
"input": "171",
"output": "99"
},
{
"input": "179",
"output": "99"
},
{
"input": "178",
"output": "99"
},
{
"input": "1700",
"output": "999"
},
{
"input": "1799",
"output": "999"
},
{
"input": "1709",
"output": "999"
},
{
"input": "1790",
"output": "999"
},
{
"input": "18",
"output": "18"
},
{
"input": "180",
"output": "99"
},
{
"input": "181",
"output": "99"
},
{
"input": "189",
"output": "189"
},
{
"input": "188",
"output": "99"
},
{
"input": "1800",
"output": "999"
},
{
"input": "1899",
"output": "1899"
},
{
"input": "1809",
"output": "999"
},
{
"input": "1890",
"output": "999"
},
{
"input": "19",
"output": "19"
},
{
"input": "190",
"output": "189"
},
{
"input": "191",
"output": "189"
},
{
"input": "199",
"output": "199"
},
{
"input": "198",
"output": "198"
},
{
"input": "1900",
"output": "1899"
},
{
"input": "1999",
"output": "1999"
},
{
"input": "1909",
"output": "1899"
},
{
"input": "1990",
"output": "1989"
},
{
"input": "20",
"output": "19"
},
{
"input": "200",
"output": "199"
},
{
"input": "201",
"output": "199"
},
{
"input": "209",
"output": "199"
},
{
"input": "208",
"output": "199"
},
{
"input": "2000",
"output": "1999"
},
{
"input": "2099",
"output": "1999"
},
{
"input": "2009",
"output": "1999"
},
{
"input": "2090",
"output": "1999"
},
{
"input": "21",
"output": "19"
},
{
"input": "210",
"output": "199"
},
{
"input": "211",
"output": "199"
},
{
"input": "219",
"output": "199"
},
{
"input": "218",
"output": "199"
},
{
"input": "2100",
"output": "1999"
},
{
"input": "2199",
"output": "1999"
},
{
"input": "2109",
"output": "1999"
},
{
"input": "2190",
"output": "1999"
},
{
"input": "22",
"output": "19"
},
{
"input": "220",
"output": "199"
},
{
"input": "221",
"output": "199"
},
{
"input": "229",
"output": "199"
},
{
"input": "228",
"output": "199"
},
{
"input": "2200",
"output": "1999"
},
{
"input": "2299",
"output": "1999"
},
{
"input": "2209",
"output": "1999"
},
{
"input": "2290",
"output": "1999"
},
{
"input": "23",
"output": "19"
},
{
"input": "230",
"output": "199"
},
{
"input": "231",
"output": "199"
},
{
"input": "239",
"output": "199"
},
{
"input": "238",
"output": "199"
},
{
"input": "2300",
"output": "1999"
},
{
"input": "2399",
"output": "1999"
},
{
"input": "2309",
"output": "1999"
},
{
"input": "2390",
"output": "1999"
},
{
"input": "24",
"output": "19"
},
{
"input": "240",
"output": "199"
},
{
"input": "241",
"output": "199"
},
{
"input": "249",
"output": "199"
},
{
"input": "248",
"output": "199"
},
{
"input": "2400",
"output": "1999"
},
{
"input": "2499",
"output": "1999"
},
{
"input": "2409",
"output": "1999"
},
{
"input": "2490",
"output": "1999"
},
{
"input": "25",
"output": "19"
},
{
"input": "250",
"output": "199"
},
{
"input": "251",
"output": "199"
},
{
"input": "259",
"output": "199"
},
{
"input": "258",
"output": "199"
},
{
"input": "2500",
"output": "1999"
},
{
"input": "2599",
"output": "1999"
},
{
"input": "2509",
"output": "1999"
},
{
"input": "2590",
"output": "1999"
},
{
"input": "26",
"output": "19"
},
{
"input": "260",
"output": "199"
},
{
"input": "261",
"output": "199"
},
{
"input": "269",
"output": "199"
},
{
"input": "268",
"output": "199"
},
{
"input": "2600",
"output": "1999"
},
{
"input": "2699",
"output": "1999"
},
{
"input": "2609",
"output": "1999"
},
{
"input": "2690",
"output": "1999"
},
{
"input": "27",
"output": "19"
},
{
"input": "270",
"output": "199"
},
{
"input": "271",
"output": "199"
},
{
"input": "279",
"output": "199"
},
{
"input": "278",
"output": "199"
},
{
"input": "2700",
"output": "1999"
},
{
"input": "2799",
"output": "1999"
},
{
"input": "2709",
"output": "1999"
},
{
"input": "2790",
"output": "1999"
},
{
"input": "28",
"output": "28"
},
{
"input": "280",
"output": "199"
},
{
"input": "281",
"output": "199"
},
{
"input": "289",
"output": "289"
},
{
"input": "288",
"output": "199"
},
{
"input": "2800",
"output": "1999"
},
{
"input": "2899",
"output": "2899"
},
{
"input": "2809",
"output": "1999"
},
{
"input": "2890",
"output": "1999"
},
{
"input": "29",
"output": "29"
},
{
"input": "290",
"output": "289"
},
{
"input": "291",
"output": "289"
},
{
"input": "299",
"output": "299"
},
{
"input": "298",
"output": "298"
},
{
"input": "2900",
"output": "2899"
},
{
"input": "2999",
"output": "2999"
},
{
"input": "2909",
"output": "2899"
},
{
"input": "2990",
"output": "2989"
},
{
"input": "999",
"output": "999"
},
{
"input": "999",
"output": "999"
},
{
"input": "890",
"output": "889"
},
{
"input": "995",
"output": "989"
},
{
"input": "999",
"output": "999"
},
{
"input": "989",
"output": "989"
},
{
"input": "999",
"output": "999"
},
{
"input": "999",
"output": "999"
},
{
"input": "991",
"output": "989"
},
{
"input": "999",
"output": "999"
},
{
"input": "9929",
"output": "9899"
},
{
"input": "4999",
"output": "4999"
},
{
"input": "9690",
"output": "8999"
},
{
"input": "8990",
"output": "8989"
},
{
"input": "9982",
"output": "9899"
},
{
"input": "9999",
"output": "9999"
},
{
"input": "1993",
"output": "1989"
},
{
"input": "9367",
"output": "8999"
},
{
"input": "8939",
"output": "8899"
},
{
"input": "9899",
"output": "9899"
},
{
"input": "99999",
"output": "99999"
},
{
"input": "93929",
"output": "89999"
},
{
"input": "99999",
"output": "99999"
},
{
"input": "38579",
"output": "29999"
},
{
"input": "79096",
"output": "78999"
},
{
"input": "72694",
"output": "69999"
},
{
"input": "99999",
"output": "99999"
},
{
"input": "99999",
"output": "99999"
},
{
"input": "99992",
"output": "99989"
},
{
"input": "27998",
"output": "19999"
},
{
"input": "460999",
"output": "399999"
},
{
"input": "999999",
"output": "999999"
},
{
"input": "999999",
"output": "999999"
},
{
"input": "998999",
"output": "998999"
},
{
"input": "999999",
"output": "999999"
},
{
"input": "999929",
"output": "999899"
},
{
"input": "999999",
"output": "999999"
},
{
"input": "999999",
"output": "999999"
},
{
"input": "979199",
"output": "899999"
},
{
"input": "999999",
"output": "999999"
},
{
"input": "9899999",
"output": "9899999"
},
{
"input": "9699959",
"output": "8999999"
},
{
"input": "9999999",
"output": "9999999"
},
{
"input": "9997099",
"output": "9989999"
},
{
"input": "8992091",
"output": "8989999"
},
{
"input": "9599295",
"output": "8999999"
},
{
"input": "2999902",
"output": "2999899"
},
{
"input": "9999953",
"output": "9999899"
},
{
"input": "9999999",
"output": "9999999"
},
{
"input": "9590999",
"output": "8999999"
}
] | 1,652,218,187 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 1,000 | 0 | x=int(input())
max=0
val=0
for i in range(x):
test=x
temp=0
while test>0:
temp+=test%10
test=test//10
if temp>max:
max=temp
val=x
x-=1
print(val) | Title: Maximize Sum of Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton has the integer *x*. He is interested what positive integer, which doesn't exceed *x*, has the maximum sum of digits.
Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them.
Input Specification:
The first line contains the positive integer *x* (1<=≤<=*x*<=≤<=1018) — the integer which Anton has.
Output Specification:
Print the positive integer which doesn't exceed *x* and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros.
Demo Input:
['100\n', '48\n', '521\n']
Demo Output:
['99\n', '48\n', '499\n']
Note:
none | ```python
x=int(input())
max=0
val=0
for i in range(x):
test=x
temp=0
while test>0:
temp+=test%10
test=test//10
if temp>max:
max=temp
val=x
x-=1
print(val)
``` | 0 |
|
595 | A | Vitaly and Night | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats numbered from 1 to *m*, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·*m* from left to right, then the *j*-th flat of the *i*-th floor has windows 2·*j*<=-<=1 and 2·*j* in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on, then the *i*-th character of this line is '1', otherwise it is '0'. | Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off. | 500 | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 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 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "99"
},
{
"input": "1 100\n0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "6"
},
{
"input": "1 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n1 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "100"
},
{
"input": "100 1\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n1 0",
"output": "8"
},
{
"input": "100 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\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": "1 1\n0 0",
"output": "0"
},
{
"input": "1 1\n0 1",
"output": "1"
},
{
"input": "1 1\n1 0",
"output": "1"
},
{
"input": "1 1\n1 1",
"output": "1"
}
] | 1,553,883,135 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 124 | 0 | # import sys
# sys.stdin=open("input.in","r")
# sys.stdout=open("output.out","w")
l=list(map(int,input().split()))
n=l[0]
m=l[1]
count=0
for i in range(n):
p=list(map(int,input().split()))
for j in range(0,len(p)-1,2):
if(p[j]==1 or p[j+1]==1):
count+=1
print(count)
| Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats numbered from 1 to *m*, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·*m* from left to right, then the *j*-th flat of the *i*-th floor has windows 2·*j*<=-<=1 and 2·*j* in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.
Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on, then the *i*-th character of this line is '1', otherwise it is '0'.
Output Specification:
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.
Demo Input:
['2 2\n0 0 0 1\n1 0 1 1\n', '1 3\n1 1 0 1 0 0\n']
Demo Output:
['3\n', '2\n']
Note:
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off. | ```python
# import sys
# sys.stdin=open("input.in","r")
# sys.stdout=open("output.out","w")
l=list(map(int,input().split()))
n=l[0]
m=l[1]
count=0
for i in range(n):
p=list(map(int,input().split()))
for j in range(0,len(p)-1,2):
if(p[j]==1 or p[j+1]==1):
count+=1
print(count)
``` | 3 |
|
981 | C | Useful Decomposition | PROGRAMMING | 1,400 | [
"implementation",
"trees"
] | null | null | Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!
He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!
The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two paths have at least one common vertex. Each edge of the tree should be in exactly one path.
Help Remesses, find such a decomposition of the tree or derermine that there is no such decomposition. | The first line contains a single integer $n$ ($2 \leq n \leq 10^{5}$) the number of nodes in the tree.
Each of the next $n<=-<=1$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq n$, $a_i \neq b_i$) — the edges of the tree. It is guaranteed that the given edges form a tree. | If there are no decompositions, print the only line containing "No".
Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $m$.
Each of the next $m$ lines should contain two integers $u_i$, $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i \neq v_i$) denoting that one of the paths in the decomposition is the simple path between nodes $u_i$ and $v_i$.
Each pair of paths in the decomposition should have at least one common vertex, and each edge of the tree should be presented in exactly one path. You can print the paths and the ends of each path in arbitrary order.
If there are multiple decompositions, print any. | [
"4\n1 2\n2 3\n3 4\n",
"6\n1 2\n2 3\n3 4\n2 5\n3 6\n",
"5\n1 2\n1 3\n1 4\n1 5\n"
] | [
"Yes\n1\n1 4\n",
"No\n",
"Yes\n4\n1 2\n1 3\n1 4\n1 5\n"
] | The tree from the first example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/9eb4b4c143d3ad267ae05d1e43341bd368b3088b.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.
The tree from the second example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/20704b97182d9bcde3321c00a16edcae4d772d93.png" style="max-width: 100.0%;max-height: 100.0%;"/> We can show that there are no valid decompositions of this tree.
The tree from the third example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/357ff9496a4ed4746401160ee6ee63f5d57d81b9.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions. | 1,250 | [
{
"input": "4\n1 2\n2 3\n3 4",
"output": "Yes\n1\n1 4"
},
{
"input": "6\n1 2\n2 3\n3 4\n2 5\n3 6",
"output": "No"
},
{
"input": "5\n1 2\n1 3\n1 4\n1 5",
"output": "Yes\n4\n1 2\n1 3\n1 4\n1 5"
},
{
"input": "2\n1 2",
"output": "Yes\n1\n1 2"
},
{
"input": "8\n1 2\n1 3\n1 4\n1 8\n7 8\n6 8\n5 8",
"output": "No"
},
{
"input": "9\n1 2\n1 3\n1 4\n1 5\n1 6\n6 7\n7 8\n7 9",
"output": "No"
},
{
"input": "3\n2 3\n1 2",
"output": "Yes\n1\n1 3"
}
] | 1,527,435,141 | 2,541 | PyPy 3 | OK | TESTS | 47 | 936 | 9,420,800 | n = int(input())
orders = [0 for i in range(n)]
for i in range(n-1):
a, b = [int(j) -1 for j in input().split()]
orders[a] += 1
orders[b] += 1
roots = []
leafs = []
for i, x in enumerate(orders):
if x > 2:
roots.append(i)
elif x == 2:
pass
elif x == 1:
leafs.append(i)
else:
raise Exception('woww')
if len(roots) > 1:
print('No')
elif len(roots) == 0:
print('Yes')
print('1')
print(' '.join([str(l+1) for l in leafs]))
elif len(roots) == 1:
print('Yes')
print(str(len(leafs)))
root = str(roots[0] + 1)
for l in leafs:
print(root, str(l+1))
else:
raise Exception('woww')
| Title: Useful Decomposition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!
He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!
The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two paths have at least one common vertex. Each edge of the tree should be in exactly one path.
Help Remesses, find such a decomposition of the tree or derermine that there is no such decomposition.
Input Specification:
The first line contains a single integer $n$ ($2 \leq n \leq 10^{5}$) the number of nodes in the tree.
Each of the next $n<=-<=1$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq n$, $a_i \neq b_i$) — the edges of the tree. It is guaranteed that the given edges form a tree.
Output Specification:
If there are no decompositions, print the only line containing "No".
Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $m$.
Each of the next $m$ lines should contain two integers $u_i$, $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i \neq v_i$) denoting that one of the paths in the decomposition is the simple path between nodes $u_i$ and $v_i$.
Each pair of paths in the decomposition should have at least one common vertex, and each edge of the tree should be presented in exactly one path. You can print the paths and the ends of each path in arbitrary order.
If there are multiple decompositions, print any.
Demo Input:
['4\n1 2\n2 3\n3 4\n', '6\n1 2\n2 3\n3 4\n2 5\n3 6\n', '5\n1 2\n1 3\n1 4\n1 5\n']
Demo Output:
['Yes\n1\n1 4\n', 'No\n', 'Yes\n4\n1 2\n1 3\n1 4\n1 5\n']
Note:
The tree from the first example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/9eb4b4c143d3ad267ae05d1e43341bd368b3088b.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.
The tree from the second example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/20704b97182d9bcde3321c00a16edcae4d772d93.png" style="max-width: 100.0%;max-height: 100.0%;"/> We can show that there are no valid decompositions of this tree.
The tree from the third example is shown on the picture below: <img class="tex-graphics" src="https://espresso.codeforces.com/357ff9496a4ed4746401160ee6ee63f5d57d81b9.png" style="max-width: 100.0%;max-height: 100.0%;"/> The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions. | ```python
n = int(input())
orders = [0 for i in range(n)]
for i in range(n-1):
a, b = [int(j) -1 for j in input().split()]
orders[a] += 1
orders[b] += 1
roots = []
leafs = []
for i, x in enumerate(orders):
if x > 2:
roots.append(i)
elif x == 2:
pass
elif x == 1:
leafs.append(i)
else:
raise Exception('woww')
if len(roots) > 1:
print('No')
elif len(roots) == 0:
print('Yes')
print('1')
print(' '.join([str(l+1) for l in leafs]))
elif len(roots) == 1:
print('Yes')
print(str(len(leafs)))
root = str(roots[0] + 1)
for l in leafs:
print(root, str(l+1))
else:
raise Exception('woww')
``` | 3 |
|
911 | F | Tree Destruction | PROGRAMMING | 2,400 | [
"constructive algorithms",
"dfs and similar",
"graphs",
"greedy",
"trees"
] | null | null | You are given an unweighted tree with *n* vertices. Then *n*<=-<=1 following operations are applied to the tree. A single operation consists of the following steps:
1. choose two leaves; 1. add the length of the simple path between them to the answer; 1. remove one of the chosen leaves from the tree.
Initial answer (before applying operations) is 0. Obviously after *n*<=-<=1 such operations the tree will consist of a single vertex.
Calculate the maximal possible answer you can achieve, and construct a sequence of operations that allows you to achieve this answer! | The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105) — the number of vertices in the tree.
Next *n*<=-<=1 lines describe the edges of the tree in form *a**i*,<=*b**i* (1<=≤<=*a**i*, *b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). It is guaranteed that given graph is a tree. | In the first line print one integer number — maximal possible answer.
In the next *n*<=-<=1 lines print the operations in order of their applying in format *a**i*,<=*b**i*,<=*c**i*, where *a**i*,<=*b**i* — pair of the leaves that are chosen in the current operation (1<=≤<=*a**i*, *b**i*<=≤<=*n*), *c**i* (1<=≤<=*c**i*<=≤<=*n*, *c**i*<==<=*a**i* or *c**i*<==<=*b**i*) — choosen leaf that is removed from the tree in the current operation.
See the examples for better understanding. | [
"3\n1 2\n1 3\n",
"5\n1 2\n1 3\n2 4\n2 5\n"
] | [
"3\n2 3 3\n2 1 1\n",
"9\n3 5 5\n4 3 3\n4 1 1\n4 2 2\n"
] | none | 0 | [
{
"input": "3\n1 2\n1 3",
"output": "3\n2 3 3\n2 1 1"
},
{
"input": "5\n1 2\n1 3\n2 4\n2 5",
"output": "9\n3 5 5\n4 3 3\n4 1 1\n4 2 2"
},
{
"input": "2\n1 2",
"output": "1\n2 1 1"
},
{
"input": "4\n1 3\n1 4\n1 2",
"output": "5\n3 4 4\n2 3 3\n2 1 1"
},
{
"input": "4\n2 1\n1 3\n3 4",
"output": "6\n4 2 2\n4 1 1\n4 3 3"
},
{
"input": "4\n4 3\n3 2\n2 1",
"output": "6\n4 1 1\n4 2 2\n4 3 3"
},
{
"input": "5\n2 1\n2 3\n2 4\n2 5",
"output": "7\n1 4 4\n1 5 5\n3 1 1\n3 2 2"
},
{
"input": "5\n4 5\n4 1\n1 2\n2 3",
"output": "10\n3 5 5\n3 4 4\n3 1 1\n3 2 2"
},
{
"input": "5\n1 4\n4 3\n3 2\n2 5",
"output": "10\n5 1 1\n5 4 4\n5 3 3\n5 2 2"
},
{
"input": "6\n4 5\n4 1\n4 6\n4 2\n4 3",
"output": "9\n1 5 5\n1 6 6\n1 3 3\n2 1 1\n2 4 4"
},
{
"input": "6\n6 5\n6 2\n2 3\n5 4\n4 1",
"output": "15\n3 1 1\n3 4 4\n3 5 5\n3 6 6\n3 2 2"
},
{
"input": "6\n1 5\n5 4\n4 2\n2 6\n6 3",
"output": "15\n3 1 1\n3 5 5\n3 4 4\n3 2 2\n3 6 6"
},
{
"input": "7\n7 5\n7 3\n7 6\n7 4\n7 1\n7 2",
"output": "11\n1 5 5\n1 3 3\n1 6 6\n1 4 4\n2 1 1\n2 7 7"
},
{
"input": "7\n7 6\n7 5\n7 2\n7 1\n5 4\n5 3",
"output": "15\n3 6 6\n3 2 2\n1 4 4\n3 1 1\n3 7 7\n3 5 5"
},
{
"input": "7\n2 7\n7 6\n6 5\n5 4\n4 1\n1 3",
"output": "21\n2 3 3\n2 1 1\n2 4 4\n2 5 5\n2 6 6\n2 7 7"
},
{
"input": "8\n8 6\n8 7\n8 2\n8 5\n8 1\n8 4\n8 3",
"output": "13\n1 6 6\n1 7 7\n1 5 5\n1 4 4\n1 3 3\n2 1 1\n2 8 8"
},
{
"input": "8\n6 3\n3 7\n6 1\n1 2\n3 5\n5 4\n2 8",
"output": "26\n8 7 7\n4 8 8\n4 2 2\n4 1 1\n4 6 6\n4 3 3\n4 5 5"
},
{
"input": "8\n4 1\n1 3\n3 6\n6 2\n2 7\n7 5\n5 8",
"output": "28\n8 4 4\n8 1 1\n8 3 3\n8 6 6\n8 2 2\n8 7 7\n8 5 5"
},
{
"input": "9\n3 2\n3 1\n3 8\n3 5\n3 6\n3 9\n3 4\n3 7",
"output": "15\n1 8 8\n1 5 5\n1 6 6\n1 9 9\n1 4 4\n1 7 7\n2 1 1\n2 3 3"
},
{
"input": "9\n2 6\n6 1\n2 8\n6 7\n1 5\n7 3\n8 9\n5 4",
"output": "30\n4 3 3\n4 7 7\n9 4 4\n9 5 5\n9 1 1\n9 6 6\n9 2 2\n9 8 8"
},
{
"input": "9\n9 4\n4 6\n6 2\n2 1\n1 3\n3 5\n5 8\n8 7",
"output": "36\n7 9 9\n7 4 4\n7 6 6\n7 2 2\n7 1 1\n7 3 3\n7 5 5\n7 8 8"
},
{
"input": "10\n3 2\n3 7\n3 6\n3 8\n3 1\n3 5\n3 9\n3 4\n3 10",
"output": "17\n1 7 7\n1 6 6\n1 8 8\n1 5 5\n1 9 9\n1 4 4\n1 10 10\n2 1 1\n2 3 3"
},
{
"input": "10\n8 2\n8 10\n10 3\n2 4\n3 6\n8 1\n2 7\n10 9\n4 5",
"output": "35\n5 9 9\n6 1 1\n6 7 7\n5 6 6\n5 3 3\n5 10 10\n5 8 8\n5 2 2\n5 4 4"
},
{
"input": "10\n7 10\n10 6\n6 4\n4 5\n5 8\n8 2\n2 1\n1 3\n3 9",
"output": "45\n7 9 9\n7 3 3\n7 1 1\n7 2 2\n7 8 8\n7 5 5\n7 4 4\n7 6 6\n7 10 10"
},
{
"input": "4\n3 4\n4 1\n1 2",
"output": "6\n3 2 2\n3 1 1\n3 4 4"
},
{
"input": "5\n1 4\n4 2\n2 3\n3 5",
"output": "10\n5 1 1\n5 4 4\n5 2 2\n5 3 3"
},
{
"input": "6\n5 3\n3 6\n6 1\n1 4\n4 2",
"output": "15\n5 2 2\n5 4 4\n5 1 1\n5 6 6\n5 3 3"
},
{
"input": "7\n1 2\n2 3\n3 6\n6 7\n7 4\n4 5",
"output": "21\n5 1 1\n5 2 2\n5 3 3\n5 6 6\n5 7 7\n5 4 4"
},
{
"input": "8\n6 2\n2 1\n1 8\n8 5\n5 7\n7 3\n3 4",
"output": "28\n4 6 6\n4 2 2\n4 1 1\n4 8 8\n4 5 5\n4 7 7\n4 3 3"
},
{
"input": "9\n1 6\n6 4\n4 5\n5 9\n9 8\n8 7\n7 3\n3 2",
"output": "36\n2 1 1\n2 6 6\n2 4 4\n2 5 5\n2 9 9\n2 8 8\n2 7 7\n2 3 3"
},
{
"input": "10\n5 1\n1 6\n6 2\n2 8\n8 3\n3 4\n4 10\n10 9\n9 7",
"output": "45\n7 5 5\n7 1 1\n7 6 6\n7 2 2\n7 8 8\n7 3 3\n7 4 4\n7 10 10\n7 9 9"
},
{
"input": "4\n3 4\n3 1\n3 2",
"output": "5\n1 4 4\n2 1 1\n2 3 3"
},
{
"input": "5\n1 4\n1 2\n1 3\n1 5",
"output": "7\n3 4 4\n3 5 5\n2 3 3\n2 1 1"
},
{
"input": "6\n5 3\n5 6\n5 1\n5 4\n5 2",
"output": "9\n1 3 3\n1 6 6\n1 4 4\n2 1 1\n2 5 5"
},
{
"input": "7\n1 2\n1 3\n1 6\n1 7\n1 4\n1 5",
"output": "11\n3 6 6\n3 7 7\n3 4 4\n3 5 5\n2 3 3\n2 1 1"
},
{
"input": "8\n6 2\n6 1\n6 8\n6 5\n6 7\n6 3\n6 4",
"output": "13\n1 8 8\n1 5 5\n1 7 7\n1 3 3\n1 4 4\n2 1 1\n2 6 6"
},
{
"input": "9\n1 6\n1 4\n1 5\n1 9\n1 8\n1 7\n1 3\n1 2",
"output": "15\n3 6 6\n3 4 4\n3 5 5\n3 9 9\n3 8 8\n3 7 7\n2 3 3\n2 1 1"
},
{
"input": "10\n5 1\n5 6\n5 2\n5 8\n5 3\n5 4\n5 10\n5 9\n5 7",
"output": "17\n1 6 6\n1 8 8\n1 3 3\n1 4 4\n1 10 10\n1 9 9\n1 7 7\n2 1 1\n2 5 5"
},
{
"input": "10\n4 10\n10 5\n5 1\n1 6\n6 8\n8 9\n9 2\n9 3\n9 7",
"output": "42\n4 3 3\n4 7 7\n2 4 4\n2 10 10\n2 5 5\n2 1 1\n2 6 6\n2 8 8\n2 9 9"
},
{
"input": "10\n5 8\n8 4\n4 9\n9 6\n6 1\n6 2\n6 7\n6 3\n6 10",
"output": "35\n5 2 2\n5 7 7\n5 3 3\n5 10 10\n5 1 1\n5 6 6\n5 9 9\n5 4 4\n5 8 8"
},
{
"input": "10\n5 6\n6 7\n7 3\n7 8\n7 4\n7 2\n7 1\n7 10\n7 9",
"output": "24\n5 3 3\n5 8 8\n5 4 4\n5 2 2\n5 10 10\n5 9 9\n5 1 1\n5 7 7\n5 6 6"
}
] | 1,693,562,844 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1693562844.127716")# 1693562844.127733 | Title: Tree Destruction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an unweighted tree with *n* vertices. Then *n*<=-<=1 following operations are applied to the tree. A single operation consists of the following steps:
1. choose two leaves; 1. add the length of the simple path between them to the answer; 1. remove one of the chosen leaves from the tree.
Initial answer (before applying operations) is 0. Obviously after *n*<=-<=1 such operations the tree will consist of a single vertex.
Calculate the maximal possible answer you can achieve, and construct a sequence of operations that allows you to achieve this answer!
Input Specification:
The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105) — the number of vertices in the tree.
Next *n*<=-<=1 lines describe the edges of the tree in form *a**i*,<=*b**i* (1<=≤<=*a**i*, *b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). It is guaranteed that given graph is a tree.
Output Specification:
In the first line print one integer number — maximal possible answer.
In the next *n*<=-<=1 lines print the operations in order of their applying in format *a**i*,<=*b**i*,<=*c**i*, where *a**i*,<=*b**i* — pair of the leaves that are chosen in the current operation (1<=≤<=*a**i*, *b**i*<=≤<=*n*), *c**i* (1<=≤<=*c**i*<=≤<=*n*, *c**i*<==<=*a**i* or *c**i*<==<=*b**i*) — choosen leaf that is removed from the tree in the current operation.
See the examples for better understanding.
Demo Input:
['3\n1 2\n1 3\n', '5\n1 2\n1 3\n2 4\n2 5\n']
Demo Output:
['3\n2 3 3\n2 1 1\n', '9\n3 5 5\n4 3 3\n4 1 1\n4 2 2\n']
Note:
none | ```python
print("_RANDOM_GUESS_1693562844.127716")# 1693562844.127733
``` | 0 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,591,246,644 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 109 | 0 | def ultra(n,m):
ans=''
for i in range(len(n)):
if(n[i]==m[i]):
ans+='0'
else:
ans+='1'
return ans
if __name__ == "__main__":
n=input()
m=input()
print(ultra(n,m)) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
def ultra(n,m):
ans=''
for i in range(len(n)):
if(n[i]==m[i]):
ans+='0'
else:
ans+='1'
return ans
if __name__ == "__main__":
n=input()
m=input()
print(ultra(n,m))
``` | 3.97275 |
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,674,719,877 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | t = list(input())
s = input()
i=0
j=len(t)-1
while(i<j):
t[i],t[j] = t[j],t[i]
i=i+1
j=j-1
x = "".join(t)
if(x==s):
print("YES")
else:
print("NO")
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
t = list(input())
s = input()
i=0
j=len(t)-1
while(i<j):
t[i],t[j] = t[j],t[i]
i=i+1
j=j-1
x = "".join(t)
if(x==s):
print("YES")
else:
print("NO")
``` | 3.977 |
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,638,899,914 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n,k=map(int,input().split())
good=0
s=list(range(0,k+1))
for i in range(n):
lst=list(map(int,input()))
tem=list(sorted(list(set(lst))))
nums=[]
if sum(nums)==s and lst.count(0)>1:
good+=1
print(good) | 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
n,k=map(int,input().split())
good=0
s=list(range(0,k+1))
for i in range(n):
lst=list(map(int,input()))
tem=list(sorted(list(set(lst))))
nums=[]
if sum(nums)==s and lst.count(0)>1:
good+=1
print(good)
``` | 0 |
|
747 | B | Mammoth's Genome Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s* is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'.
It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal.
Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal. | The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome.
The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. | If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). | [
"8\nAG?C??CT\n",
"4\nAGCT\n",
"6\n????G?\n",
"4\nAA??\n"
] | [
"AGACGTCT\n",
"AGCT\n",
"===\n",
"===\n"
] | In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is exactly once in it.
In the third and the fourth examples it is impossible to decode the genom. | 1,000 | [
{
"input": "8\nAG?C??CT",
"output": "AGACGTCT"
},
{
"input": "4\nAGCT",
"output": "AGCT"
},
{
"input": "6\n????G?",
"output": "==="
},
{
"input": "4\nAA??",
"output": "==="
},
{
"input": "4\n????",
"output": "ACGT"
},
{
"input": "252\n???????GCG??T??TT?????T?C???C?CCG???GA???????AC??A???AAC?C?CC??CCC??A??TA?CCC??T???C??CA???CA??G????C?C?C????C??C??A???C?T????C??ACGC??CC?A?????A??CC?C??C?CCG?C??C??A??CG?A?????A?CT???CC????CCC?CATC?G??????????A???????????????TCCCC?C?CA??AC??GC????????",
"output": "AAAAAAAGCGAATAATTAAAAATACAAACACCGAAAGAAAAAAAAACAAAAAAAACACACCAACCCAAAACTACCCCCCTCCCCCGCAGGGCAGGGGGGGCGCGCGGGGCGGCGGAGGGCGTGGGGCGGACGCGGCCGAGGGGGAGGCCGCGGCGCCGGCGGCGGAGGCGGAGTTTTATCTTTTCCTTTTCCCTCATCTGTTTTTTTTTTATTTTTTTTTTTTTTTTCCCCTCTCATTACTTGCTTTTTTTT"
},
{
"input": "255\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "==="
},
{
"input": "4\n??A?",
"output": "CGAT"
},
{
"input": "4\n?C??",
"output": "ACGT"
},
{
"input": "4\nT???",
"output": "TACG"
},
{
"input": "4\n???G",
"output": "ACTG"
},
{
"input": "4\n??AC",
"output": "GTAC"
},
{
"input": "8\n?C?AA???",
"output": "CCGAAGTT"
},
{
"input": "12\n???A?G???A?T",
"output": "ACCACGGGTATT"
},
{
"input": "16\n?????C??CAG??T??",
"output": "AAACCCGGCAGGTTTT"
},
{
"input": "20\n???A?G??C?GC???????G",
"output": "AAAAAGCCCCGCGGTTTTTG"
},
{
"input": "24\n?TG???AT?A?CTTG??T?GCT??",
"output": "ATGAAAATCACCTTGCCTGGCTGG"
},
{
"input": "28\n??CTGAAG?GGT?CC?A??TT?CCACG?",
"output": "AACTGAAGAGGTCCCGAGTTTTCCACGT"
},
{
"input": "32\n??A?????CAAG?C?C?CG??A?A??AAC?A?",
"output": "CCACGGGGCAAGGCGCTCGTTATATTAACTAT"
},
{
"input": "36\n?GCC?CT?G?CGG?GCTGA?C?G?G????C??G?C?",
"output": "AGCCACTAGACGGAGCTGAACAGAGCTTTCTTGTCT"
},
{
"input": "40\nTA?AA?C?G?ACC?G?GCTCGC?TG??TG?CT?G??CC??",
"output": "TAAAAACAGAACCAGAGCTCGCCTGGGTGGCTTGTTCCTT"
},
{
"input": "44\nT?TA??A??AA???A?AGTA??TAT??ACTGAT??CT?AC?T??",
"output": "TCTACCACCAACCCAGAGTAGGTATGGACTGATGGCTGACGTTT"
},
{
"input": "48\nG?G??GC??CA?G????AG?CA?CG??GGCCCCAA??G??C?T?TCA?",
"output": "GAGAAGCAACAAGCCGGAGGCATCGTTGGCCCCAATTGTTCTTTTCAT"
},
{
"input": "52\n??G?G?CTGT??T?GCGCT?TAGGTT??C???GTCG??GC??C???????CG",
"output": "AAGAGACTGTAATAGCGCTATAGGTTAACAACGTCGCCGCCCCGGTTTTTCG"
},
{
"input": "56\n?GCCA?GC?GA??GA??T?CCGC?????TGGC?AGGCCGC?AC?TGAT??CG?A??",
"output": "AGCCAAGCAGAAAGAAATCCCGCCGGTTTGGCTAGGCCGCTACTTGATTTCGTATT"
},
{
"input": "60\nAT?T?CCGG??G?CCT?CCC?C?CGG????TCCCG?C?TG?TT?TA??A?TGT?????G?",
"output": "ATATACCGGAAGACCTACCCACACGGAAAATCCCGCCCTGGTTGTAGGAGTGTGTTTTGT"
},
{
"input": "64\n?G??C??????C??C??AG?T?GC?TT??TAGA?GA?A??T?C???TC??A?CA??C??A???C",
"output": "AGAACAAAAACCCCCCCAGCTCGCGTTGGTAGAGGAGAGGTGCGGGTCTTATCATTCTTATTTC"
},
{
"input": "68\nC?T??????C????G?T??TTT?T?T?G?CG??GCC??CT??????C??T?CC?T?T????CTT?T??",
"output": "CATAAAAAACAAAAGATAATTTATATAGCCGCCGCCCCCTCCGGGGCGGTGCCGTGTGGGGCTTTTTT"
},
{
"input": "72\nA?GTA??A?TG?TA???AAAGG?A?T?TTAAT??GGA?T??G?T?T????TTATAAA?AA?T?G?TGT??TG",
"output": "AAGTACCACTGCTACCCAAAGGCACTCTTAATCCGGACTCCGCTCTCGGGTTATAAAGAAGTGGGTGTGTTG"
},
{
"input": "76\nG?GTAC?CG?AG?AGC???A??T?TC?G??C?G?A???TC???GTG?C?AC???A??????TCA??TT?A?T?ATG",
"output": "GAGTACACGAAGAAGCAAAAAATCTCCGCCCCGCACCCTCCGGGTGGCGACGGGAGGTTTTTCATTTTTATTTATG"
},
{
"input": "80\nGG???TAATT?A?AAG?G?TT???G??TTA?GAT?????GT?AA?TT?G?AG???G?T?A??GT??TTT?TTG??AT?T?",
"output": "GGAAATAATTAAAAAGAGATTACCGCCTTACGATCCCCCGTCAACTTCGCAGCCCGCTCACGGTGGTTTGTTGGGATGTG"
},
{
"input": "84\n?C??G??CGGC????CA?GCGG???G?CG??GA??C???C???GC???CG?G?A?C?CC?AC?C?GGAG???C??????G???C",
"output": "ACAAGAACGGCAAAACAAGCGGAAAGACGAAGACCCCCGCGGGGCGTTCGTGTATCTCCTACTCTGGAGTTTCTTTTTTGTTTC"
},
{
"input": "88\nGTTC?TCTGCGCGG??CATC?GTGCTCG?A?G?TGCAGCAG??A?CAG???GGTG?ATCAGG?TCTACTC?CG?GGT?A?TCC??AT?",
"output": "GTTCATCTGCGCGGAACATCAGTGCTCGAAAGATGCAGCAGAAAACAGACCGGTGCATCAGGCTCTACTCGCGTGGTTATTCCTTATT"
},
{
"input": "92\n??TT????AT?T????A???TC????A?C????AT???T?T???T??A???T??TTA?AT?AA?C????C??????????????TAA?T???",
"output": "AATTAAAAATATAAAAAACCTCCCCCACCCCCCATCCCTCTCCCTCGAGGGTGGTTAGATGAAGCGGGGCGGGGGGGGGGTTTTTAATTTTT"
},
{
"input": "96\nT?????C?CT?T??GGG??G??C???A?CC??????G???TCCCT??C?G??GC?CT?CGT?GGG??TCTC?C?CCGT?CCTCTT??CC?C?????",
"output": "TAAAAACACTATAAGGGAAGAACAAAAACCAAAAAAGCGGTCCCTGGCGGGGGCGCTGCGTGGGGGGTCTCTCTCCGTTCCTCTTTTCCTCTTTTT"
},
{
"input": "100\n???GGA?C?A?A??A?G??GT?GG??G????A?ATGGAA???A?A?A?AGAGGT?GA?????AA???G???GA???TAGAG?ACGGA?AA?G???GGGAT",
"output": "ACCGGACCCACACCACGCCGTCGGCCGCCCCACATGGAACCCACACAGAGAGGTGGATTTTTAATTTGTTTGATTTTAGAGTACGGATAATGTTTGGGAT"
},
{
"input": "104\n???TTG?C???G?G??G??????G?T??TC???CCC????TG?GGT??GG?????T?CG???GGG??GTC?G??TC??GG??CTGGCT??G????C??????TG",
"output": "AAATTGACAAAGAGAAGAAAAAAGATAATCAAACCCAAAATGCGGTCCGGCCCCCTCCGCCCGGGCCGTCCGGGTCGGGGTTCTGGCTTTGTTTTCTTTTTTTG"
},
{
"input": "108\n??CAC?A?ACCA??A?CA??AA?TA?AT?????CCC????A??T?C?CATA??CAA?TACT??A?TA?AC?T??G???GG?G??CCC??AA?CG????T?CT?A??AA",
"output": "AACACAACACCACCACCACCAACTACATCGGGGCCCGGGGAGGTGCGCATAGGCAAGTACTGGAGTAGACGTGGGTTTGGTGTTCCCTTAATCGTTTTTTCTTATTAA"
},
{
"input": "112\n???T?TC?C?AC???TC?C???CCC??C????C?CCGC???TG?C?T??????C?C?????G?C????A????????G?C?A?C?A?C?C??C????CC?TC??C??C?A??",
"output": "AAATATCACAACAAATCACAAACCCAACAAAACACCGCAAATGCCGTGGGGGGCGCGGGGGGGCGGGGAGGGGGGTTGTCTATCTATCTCTTCTTTTCCTTCTTCTTCTATT"
},
{
"input": "116\n????C??A?A??AAC???????C???CCCTC??A????ATA?T??AT???C?TCCC???????C????CTC??T?A???C??A???CCA?TAC?AT?????C??CA???C?????C",
"output": "AAAACAAAAAAAAACAAAAAACCCCCCCCTCCCACGGGATAGTGGATGGGCGTCCCGGGGGGGCGGGGCTCGGTGAGGGCGGATTTCCATTACTATTTTTTCTTCATTTCTTTTTC"
},
{
"input": "120\nTC?AGATG?GAT??G????C?C??GA?GT?TATAC?AGA?TCG?TCT???A?AAA??C?T?A???AA?TAC?ATTT???T?AA?G???TG?AT???TA??GCGG?AC?A??AT??T???C",
"output": "TCAAGATGAGATAAGAACCCCCCCGACGTCTATACCAGACTCGCTCTCCCACAAACCCCTCACGGAAGTACGATTTGGGTGAAGGGGGTGGATGGGTAGTGCGGTACTATTATTTTTTTC"
},
{
"input": "124\n???C?????C?AGG??A?A?CA????A??A?AA??A????????G?A?????????AG?A??G?C??A??C???G??CG??C???????A????C???AG?AA???AC????????????C??G",
"output": "AAACAAAAACAAGGAAAAAACACCCCACCACAACCACCCCCCCCGCACCCGGGGGGAGGAGGGGCGGAGGCGGGGGGCGGGCGTTTTTTATTTTCTTTAGTAATTTACTTTTTTTTTTTTCTTG"
},
{
"input": "128\nAT?GC?T?C?GATTTG??ATTGG?AC?GGCCA?T?GG?CCGG??AGT?TGT?G??A?AAGGCGG?T??TCT?CT??C?TTGTTG??????CCGG?TGATAT?T?TTGTCCCT??CTGTGTAATA??G?",
"output": "ATAGCATACAGATTTGAAATTGGAACAGGCCAATAGGACCGGAAAGTATGTAGAAAAAAGGCGGCTCCTCTCCTCCCCTTGTTGCCCCCCCCGGCTGATATCTGTTGTCCCTGGCTGTGTAATAGGGT"
},
{
"input": "132\nAC???AA??T???T??G??ACG?C??AA?GA?C???CGAGTA?T??TTGTC???GCTGATCA????C??TA???ATTTA?C??GT??GTCTCTCGT?AAGGACTG?TC????T???C?T???ATTTT?T?AT",
"output": "ACAAAAAAATAAATAAGAAACGACACAACGACCCCCCGAGTACTCCTTGTCCCCGCTGATCACCCCCCGTAGGGATTTAGCGGGTGGGTCTCTCGTGAAGGACTGGTCGGGGTGGGCGTTTTATTTTTTTAT"
},
{
"input": "136\n?A?C???????C??????????????C?????C???????????CCCC?????????C??????C??C??????CC??C??C?C???C??????C??C?C??????????C?????????GC????C???????C?",
"output": "AAACAAAAAAACAAAAAAAAAAAAAACAAAAACAAAAACCCCCCCCCCCCCCGGGGGCGGGGGGCGGCGGGGGGCCGGCGGCGCGGGCGGGGGGCTTCTCTTTTTTTTTTCTTTTTTTTTGCTTTTCTTTTTTTCT"
},
{
"input": "140\nTTG??G?GG?G??C??CTC?CGG?TTCGC????GGCG?G??TTGCCCC?TCC??A??CG?GCCTTT?G??G??CT??TG?G?TTC?TGC?GG?TGT??CTGGAT??TGGTTG??TTGGTTTTTTGGTCGATCGG???C??",
"output": "TTGAAGAGGAGAACAACTCACGGATTCGCAAAAGGCGAGAATTGCCCCATCCAAAAACGAGCCTTTAGAAGAACTAATGAGATTCCTGCCGGCTGTCCCTGGATCCTGGTTGCCTTGGTTTTTTGGTCGATCGGCCCCTT"
},
{
"input": "144\n?????A?C?A?A???TTT?GAATA?G??T?T?????AT?AA??TT???TT??A?T????AT??TA??AA???T??A??TT???A????T???T????A??T?G???A?C?T????A?AA??A?T?C??A??A???AA????ATA",
"output": "AAAAAAACAAAACCCTTTCGAATACGCCTCTCCCCCATCAACCTTCCCTTCCACTCCCCATCCTACCAACCCTGGAGGTTGGGAGGGGTGGGTGGGGAGGTGGGGGAGCGTGGGGAGAAGGATTTCTTATTATTTAATTTTATA"
},
{
"input": "148\nACG?GGGT?A??C????TCTTGCTG?GTA?C?C?TG?GT??GGGG??TTG?CA????GT???G?TT?T?CT?C??C???CTTCATTA?G?G???GC?AAT??T???AT??GGATT????TC?C???????T??TATCG???T?T?CG?",
"output": "ACGAGGGTAAAACAAAATCTTGCTGAGTAACACATGAGTAAGGGGAATTGACAAAAAGTAAAGATTCTCCTCCCCCCCCCTTCATTACGCGCCCGCCAATCCTCCCATCGGGATTGGGGTCGCGGGGGGGTGTTATCGTTTTTTTCGT"
},
{
"input": "152\n??CTA??G?GTC?G??TTCC?TG??????T??C?G???G?CC???C?GT?G?G??C?CGGT?CC????G?T?T?C?T??G?TCGT??????A??TCC?G?C???GTT?GC?T?CTT?GT?C??C?TCGTTG?TTG?G????CG?GC??G??G",
"output": "AACTAAAGAGTCAGAATTCCATGAAAAAATAACAGAAAGACCAAACAGTAGAGAACACGGTACCAAAAGCTCTCCCTCCGCTCGTCCCCCCACGTCCGGGCGGGGTTGGCGTGCTTGGTGCGTCTTCGTTGTTTGTGTTTTCGTGCTTGTTG"
},
{
"input": "156\nGCA????A???AAT?C??????GAG?CCA?A?CG??ACG??????GCAAAC??GCGGTCC??GT???C???????CC???????ACGCA????C??A??CC??A?GAATAC?C?CA?CCCT?TCACA?A???????C??TAG?C??T??A??A?CA",
"output": "GCAAAAAAAAAAATACAAAAACGAGCCCACACCGCCACGCCCGGGGCAAACGGGCGGTCCGGGTGGGCGGGGGGGCCGGGGGGGACGCAGGTTCTTATTCCTTATGAATACTCTCATCCCTTTCACATATTTTTTTCTTTAGTCTTTTTATTATCA"
},
{
"input": "160\nGCACC????T?TGATAC??CATATCC?GT?AGT?ATGGATA?CC?????GCTCG?A?GG?A?GCCAG??C?CGGATC?GCAA?AAGCCCCC?CAT?GA?GC?CAC?TAA?G?CACAACGG?AAA??CA?ACTCGA?CAC?GAGCAAC??A?G?AAA?TC?",
"output": "GCACCACCCTGTGATACGGCATATCCGGTGAGTGATGGATAGCCGGGGGGCTCGGAGGGGATGCCAGTTCTCGGATCTGCAATAAGCCCCCTCATTGATGCTCACTTAATGTCACAACGGTAAATTCATACTCGATCACTGAGCAACTTATGTAAATTCT"
},
{
"input": "164\nGA?AGGT???T?G?A?G??TTA?TGTG?GTAGT?????T??TTTG?A?T??T?TA?G?T?GGT?????TGTGG?A?A?T?A?T?T?????TT?AAGAG?????T??TATATG?TATT??G?????GGGTATTTT?GG?A??TG??T?GAATGTG?AG?T???A?",
"output": "GAAAGGTAAATAGAAAGAATTAATGTGAGTAGTAAAAATAATTTGAACTCCTCTACGCTCGGTCCCCCTGTGGCACACTCACTCTCCCCCTTCAAGAGCCCCCTCCTATATGCTATTCCGCCCCCGGGTATTTTCGGCAGGTGGGTGGAATGTGGAGGTGGGAG"
},
{
"input": "168\n?C?CAGTCCGT?TCC?GCG?T??T?TA?GG?GCTTGTTTTGT??GC???CTGT??T?T?C?ACG?GTGG??C??TC?GT??CTT?GGT??TGGC??G?TTTCTT?G??C?CTC??CT?G?TT?CG?C?A???GCCGTGAG?CTTC???TTCTCGG?C?CC??GTGCTT",
"output": "ACACAGTCCGTATCCAGCGATAATATAAGGAGCTTGTTTTGTAAGCAAACTGTAATATACAACGAGTGGAACAATCAGTAACTTAGGTAATGGCAAGATTTCTTAGAACCCTCCCCTCGCTTCCGCCCACGGGCCGTGAGGCTTCGGGTTCTCGGGCGCCGGGTGCTT"
},
{
"input": "172\nG?ATG??G?TTT?ATA?GAAGCACTTGCT?AGC??AG??GTTCG?T?G??G?AC?TAGGGCT?TA?TTCTA?TTCAGGAA?GGAAATTGAAG?A?CT?GGTGAGTCTCT?AAACAGT??T??TCAGG?AGTG?TT?TAAT??GG?G?GCA???G?GGA?GACGAATACTCAA",
"output": "GAATGAAGATTTAATACGAAGCACTTGCTCAGCCCAGCCGTTCGCTCGCCGCACCTAGGGCTCTACTTCTACTTCAGGAACGGAAATTGAAGCACCTCGGTGAGTCTCTCAAACAGTCCTCCTCAGGCAGTGGTTGTAATGGGGTGTGCATTTGTGGATGACGAATACTCAA"
},
{
"input": "176\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "180\n?GTTACA?A?A?G??????GGGA?A??T?????C?AC??GG???G????T??CC??T?CGG?AG???GAAGG?????A?GT?G?????CTAA?A??C?A???A?T??C?A???AAA???G?GG?C?A??C???????GTCC?G??GT??G?C?G?C????TT??G????A???A???A?G",
"output": "AGTTACAAAAAAGAAAAAAGGGAAAAATAAAAACAACAAGGCCCGCCCCTCCCCCCTCCGGCAGCCCGAAGGCCCCCACGTCGCCCCCCTAACACGCGAGGGAGTGGCGAGGGAAAGGGGGGGGCGAGTCTTTTTTTGTCCTGTTGTTTGTCTGTCTTTTTTTTGTTTTATTTATTTATG"
},
{
"input": "184\n?CTC?A??????C?T?TG??AC??????G???CCT????CT?C?TT???C???AT????????????T??T?A?AGT?C?C?C?C?CG??CAT?C??C???T??T?TCCTC????C??A???CG?C???C??TC??C?G?C????CTT????C??A?AT??C????T?TCT?T???C?CT??C?",
"output": "ACTCAAAAAAAACATATGAAACAAAAAAGAAACCTAAAACTACATTAAACAAAATAAAACCCCCCCCTCCTCACAGTGCGCGCGCGCGGGCATGCGGCGGGTGGTGTCCTCGGGGCGGAGGGCGGCGGGCGGTCGGCGGGCGGGGCTTGTTTCTTATATTTCTTTTTTTCTTTTTTCTCTTTCT"
},
{
"input": "188\n????TG??A?G?GG?AGA??T??G?TA?ATTT?TTGA??TTA??T?G???GA?G?A??GG??ACTTGT?T?T?TCT?TG?TGAG??GT?A???TT?G???????TA???G?G?GTAG?G?T????????A?TT?TT?T??GGTGT??TTT?T?T?TT???GAGA??G?GGG?G??TG?GT?GT?A??T",
"output": "AAAATGAAAAGAGGAAGAAATAAGATAAATTTATTGAAATTAAATAGAAAGAAGAAAAGGACACTTGTCTCTCTCTCTGCTGAGCCGTCACCCTTCGCCCCCCCTACCCGCGCGTAGCGCTCCCCCCCCACTTCTTCTCCGGTGTCCTTTCTCTCTTGGGGAGAGGGGGGGGGGGTGGGTGGTTATTT"
},
{
"input": "192\nTT???TA?A?TTCTCA?ATCCCC?TA?T??A?A?TGT?TT??TAA?C?C?TA?CTAAAT???AA?TT???T?AATAG?AC??AC?A??A?TT?A?TT?AA?TCTTTC??A?AAA?AA??T?AG?C??AT?T?TATCT?CTTCAA?ACAAAT???AT?TT??????C?CTC???TT?ACACACTGCA?AC??T",
"output": "TTAACTACACTTCTCACATCCCCCTACTCCACACTGTCTTCCTAACCCCCTACCTAAATCCCAACTTCGGTGAATAGGACGGACGAGGAGTTGAGTTGAAGTCTTTCGGAGAAAGAAGGTGAGGCGGATGTGTATCTGCTTCAAGACAAATGGGATGTTGGGGGGCGCTCGGGTTGACACACTGCAGACTTT"
},
{
"input": "196\n??ACATCC??TGA?C?AAA?A???T????A??ACAC????T???????CCC?AAT?T?AT?A?A??TATC??CC?CCACACA?CC?A?AGC??AAA??A???A?CA??A?AT??G???CA?ACATTCG??CACAT?AC???A?A?C?CTTT?AAG??A?TAC???C?GCAA?T??C??AA???GAC?ATTAT????",
"output": "ACACATCCCCTGACCCAAACACCCTCCCCACCACACCGGGTGGGGGGGCCCGAATGTGATGAGAGGTATCGGCCGCCACACAGCCGAGAGCGGAAAGGAGGGAGCAGGAGATGGGGGGCAGACATTCGGGCACATTACTTTATATCTCTTTTAAGTTATTACTTTCTGCAATTTTCTTAATTTGACTATTATTTTT"
},
{
"input": "200\n?CT?T?C???AC?G?CAC?C?T??T?G?AGAGTA?CT????A?CCCAT?GCT?TTC?CAG???TCCATAAC?GACT?TC??C?AG?AA?A?C??ATC?CTAT?AC??????ACCGA??A????C?AA???CGCTTCGC?A????A??GCC?AG?T?????T?A?C?A?CTTC?????T?T?????GC?GTACTC??TG??",
"output": "ACTATACAAAACAGACACACATAATAGAAGAGTAACTAAAAAACCCATCGCTCTTCCCAGCCCTCCATAACCGACTCTCCCCCAGCAAGAGCGGATCGCTATGACGGGGGGACCGAGGAGGGGCGAAGGGCGCTTCGCGAGGGGAGGGCCGAGGTGGGTTTTATCTATCTTCTTTTTTTTTTTTTGCTGTACTCTTTGTT"
},
{
"input": "204\n??????T???T?GC?TC???TA?TC?????A??C?C??G??????G?CTC????A?CTTT?T???T??CTTA???????T??C??G????A?????TTTA??AT?A??C?C?T?C???C?????T???????GT????T????AT?CT????C??C??T???C????C?GCTTCCC?G?????T???C?T??????????TT??",
"output": "AAAAAATAAATAGCATCAAATAATCAAAAAAAACACAAGAAAAAAGACTCAAAAAACTTTATAAATACCTTACCCCCCCTCCCCCGCCCCACCCCCTTTACCATCACCCCCGTGCGGGCGGGGGTGGGGGGGGTGGGGTGGGGATGCTGGGGCGGCGGTGGGCGGGGCGGCTTCCCGGGTTTTTTTTCTTTTTTTTTTTTTTTT"
},
{
"input": "208\nA?GGT?G??A???????G??A?A?GA?T?G???A?AAG?AT????GG?????AT??A?A???T?A??????A????AGGCGT???A???TA????TGGT???GA????GGTG???TA??GA??TA?GGG?????G?????AT?GGGG??TG?T?AA??A??AG?AA?TGA???A?A?GG???GAAT?G?T??T?A??G?CAGT?T?A?",
"output": "AAGGTAGAAAAAAAAAAGAAAAAAGAATCGCCCACAAGCATCCCCGGCCCCCATCCACACCCTCACCCCCCACCCCAGGCGTCCCACCCTACCCCTGGTCCCGACCCCGGTGCGGTAGGGAGGTAGGGGGGGGGGGGGGTATTGGGGTTTGTTTAATTATTAGTAATTGATTTATATGGTTTGAATTGTTTTTTATTGTCAGTTTTAT"
},
{
"input": "212\nT?TTT?A??TC?????A?T??T????T????????C??T??AT????????T???TT????T?TTT??????????TTC???T?T?C??T?TA?C??TTT????T???????C????????A?TT???T??TTT??AT?T????T????T?????A??C????T??T???TA???A?????????T???C????????C???T?TA???TTT",
"output": "TATTTAAAATCAAAAAAATAATAAAATAAAAAAAACAATAAATAAAAAAAATAAATTAAAATCTTTCCCCCCCCCCTTCCCCTCTCCCCTCTACCCCTTTCCCCTCCCCCCCCCCCCCCCCACTTCCGTGGTTTGGATGTGGGGTGGGGTGGGGGAGGCGGGGTGGTGGGTAGGGAGGGGGGGGGTGGGCGGGGGGGGCTTTTTTATTTTTT"
},
{
"input": "216\n?CT?A?CC?GCC?C?AT?A???C???TA????ATGTCCG??CCG?CGG?TCC?TTC??CCT????????G?GGC?TACCCGACCGAG?C???C?G?G??C??CGTCCTG??AGG??CT?G???TC?CT????A?GTA??C?C?CTGTTAC??C?TCT?C?T???T??GTGGA?AG?CGCT?CGTC???T?C?T?C?GTT???C??GCC?T??C?T?",
"output": "ACTAAACCAGCCACAATAAAAACAAATAAAAAATGTCCGAACCGACGGATCCATTCAACCTAAAAAAAAGAGGCATACCCGACCGAGACAAACAGAGCCCCCCGTCCTGCGAGGGGCTGGGGGTCGCTGGGGAGGTAGGCGCGCTGTTACGGCGTCTGCGTGGGTTTGTGGATAGTCGCTTCGTCTTTTTCTTTCTGTTTTTCTTGCCTTTTCTTT"
},
{
"input": "220\n?GCC??????T????G?CTC???CC?C????GC??????C???TCCC???????GCC????????C?C??C?T?C?CC????CC??C???????CC??C?G?A?T???CC??C????????C????CTA?GC?????CC??C?C?????T?????G?????????G???AC????C?CG?????C?G?C?CG?????????G?C????C?G??????C??",
"output": "AGCCAAAAAATAAAAGACTCAAACCACAAAAGCAAAAAACAAATCCCAAAAAAAGCCAAAAAAAACACAACATACACCAACCCCCCCCCCCCCGCCGGCGGGAGTGGGCCGGCGGGGGGGGCGGGGCTAGGCGGGGGCCGGCGCGGGGGTGGGGGGTTTTTTTTTGTTTACTTTTCTCGTTTTTCTGTCTCGTTTTTTTTTGTCTTTTCTGTTTTTTCTT"
},
{
"input": "224\nTTGC?G??A?ATCA??CA???T?TG?C?CGA?CTTA?C??C?TTC?AC?CTCA?A?AT?C?T?CT?CATGT???A??T?CT????C?AACT?TTCCC??C?AAC???AC?TTTC?TTAAA??????TGT????CGCT????GCCC?GCCCA?????TCGA??C?TATACA??C?CC?CATAC?GGACG??GC??GTT?TT?T???GCT??T?C?T?C??T?CC?",
"output": "TTGCAGAAAAATCAAACAAAATATGACACGAACTTAACAACATTCAACACTCAAAAATACATACTACATGTAAAACCTCCTCCCCCCAACTGTTCCCGGCGAACGGGACGTTTCGTTAAAGGGGGGTGTGGGGCGCTGGGGGCCCGGCCCAGGGGGTCGAGGCGTATACAGGCGCCGCATACGGGACGGGGCGTGTTTTTTTTTTGCTTTTTCTTTCTTTTCCT"
},
{
"input": "228\nA??A?C???AG?C?AC???A?T?????AA??????C?A??A?AC?????C?C???A??????A???AC?C????T?C?AA?C??A???CC??????????????????A???CC????A?????C??TC???A???????????A??A????????????????CC?????CCA??????????????C??????C????T?CT???C???A???T?CC?G??C??A?",
"output": "AAAAACAAAAGACAACAAAAATAAAAAAAAAAAAACAAAAAAACAAAAACACCCCACCCCCCACCCACCCCCCCTCCCAACCCCACCCCCCCCCGGGGGGGGGGGGGGAGGGCCGGGGAGGGGGCGGTCGGGAGGGGGGGGGGGAGGAGGGGGGGGGGGTTTTTCCTTTTTCCATTTTTTTTTTTTTTCTTTTTTCTTTTTTCTTTTCTTTATTTTTCCTGTTCTTAT"
},
{
"input": "232\nA??AAGC?GCG?AG???GGGCG?C?A?GCAAC?AG?C?GC??CA??A??CC?AA?A????G?AGA?ACACA?C?G?G?G?CGC??G???????GAGC?CAA??????G?A???AGGG?????AAC?AG?A?A??AG?CG?G???G????GGGA?C?G?A?A??GC????C??A?ACG?AA?G?ACG????AC?C?GA??GGCAG?GAA??ACA??A?AGGAGG???CGGA?C",
"output": "AAAAAGCAGCGAAGAAAGGGCGACAAAGCAACCAGCCCGCCCCACCACCCCCAACACCCCGCAGACACACACCCGCGCGCCGCCCGCCCGGGGGAGCGCAAGGGGGTGTATTTAGGGTTTTTAACTAGTATATTAGTCGTGTTTGTTTTGGGATCTGTATATTGCTTTTCTTATACGTAATGTACGTTTTACTCTGATTGGCAGTGAATTACATTATAGGAGGTTTCGGATC"
},
{
"input": "236\nAAGCCC?A?TT??C?AATGC?A?GC?GACGT?CTT?TA??CCG?T?CAA?AGT?CTG???GCGATG?TG?A?A?ACT?AT?GGG?GC?C?CGCCCTT?GT??G?T?????GACTT??????CT?GA?GG?C?T?G??CTG??G??TG?TCA?TCGTT?GC?A?G?GGGT?CG?CGAG??CG?TC?TAT?A???T??GAGTC?CGGC?CG??CT?TAAT??GGAA?G??GG?GCGAC",
"output": "AAGCCCAAATTAACAAATGCAAAGCAGACGTACTTATAAACCGATACAAAAGTACTGAAAGCGATGATGAAAAAACTAATAGGGAGCACACGCCCTTAGTACGCTCCCCCGACTTCCCCCCCTCGACGGCCCTCGCCCTGCGGGGTGGTCAGTCGTTGGCGAGGGGGGTGCGTCGAGTTCGTTCTTATTATTTTTTGAGTCTCGGCTCGTTCTTTAATTTGGAATGTTGGTGCGAC"
},
{
"input": "240\n?T?A?A??G????G????AGGAGTAA?AGGCT??C????AT?GAA?ATGCT???GA?G?A??G?TC??TATT???AG?G?G?A?A??TTGT??GGTCAG?GA?G?AAT?G?GG??CAG?T?GT?G?GC???GC??????GA?A?AAATGGGC??G??????TTA??GTCG?TC?GCCG?GGGA??T?A????T?G?T???G?GG?ATG???A?ATGAC?GGT?CTG?AGGG??TAGT?AG",
"output": "ATAAAAAAGAAAAGAAAAAGGAGTAAAAGGCTAACAAAAATAGAAAATGCTACCGACGCACCGCTCCCTATTCCCAGCGCGCACACCTTGTCCGGTCAGCGACGCAATCGCGGCCCAGCTCGTCGCGCCCCGCCCCCCCGACACAAATGGGCCCGCGGGGGTTATTGTCGTTCTGCCGTGGGATTTTATTTTTTGTTTTTGTGGTATGTTTATATGACTGGTTCTGTAGGGTTTAGTTAG"
},
{
"input": "244\nC?GT???T??TA?CC??TACT???TC?C?A???G??G?TCC?AC??AA???C?CCACC????A?AGCC??T?CT??CCGG?CC?T?C??GCCCTGGCCAAAC???GC?C???AT?CC?CT?TAG??CG?C?T?C??A?AC?GC????A??C?C?A??TC?T????GCCCT??GG???CC?A?CC?G?A?CA?G??CCCG??CG?T?TAC?G???C?AC??G??CCA???G????C??G?CT?C?",
"output": "CAGTAAATAATAACCAATACTAAATCACAAAAAGAAGATCCAACAAAAAAACACCACCAAAAAAAGCCAATACTAACCGGGCCGTGCGGGCCCTGGCCAAACGGGGCGCGGGATGCCGCTGTAGGGCGGCGTGCGGAGACGGCGGGGAGGCGCGAGGTCGTGGTTGCCCTTTGGTTTCCTATCCTGTATCATGTTCCCGTTCGTTTTACTGTTTCTACTTGTTCCATTTGTTTTCTTGTCTTCT"
},
{
"input": "248\n??TC???TG??G??T????CC???C?G?????G?????GT?A?CT?AAT?GG?AGA?????????G???????G???CG??AA?A????T???????TG?CA????C?TT?G?GC???AA?G????G????T??G??A??????TT???G???CG?????A??A??T?GA??G??T?CC?TA??GCTG?A????G?CG??GGTG??CA???????TA??G?????????A???????GC?GG????GC",
"output": "AATCAAATGAAGAATAAAACCAAACAGAAAAAGAAAAAGTAAACTAAATAGGAAGAAAAAAAAAAGACCCCCCGCCCCGCCAACACCCCTCCCCCCCTGCCACCCCCCTTCGCGCCCCAACGCCCCGCCCCTCCGGGAGGGGGGTTGGGGGGGCGGGGGGAGGAGGTGGAGGGGGTGCCTTATTGCTGTATTTTGTCGTTGGTGTTCATTTTTTTTATTGTTTTTTTTTATTTTTTTGCTGGTTTTGC"
},
{
"input": "8\n???AAA??",
"output": "==="
},
{
"input": "12\nC??CC??????C",
"output": "==="
},
{
"input": "4\nG??G",
"output": "==="
},
{
"input": "4\nTT??",
"output": "==="
},
{
"input": "4\nACAC",
"output": "==="
},
{
"input": "8\nACGT???T",
"output": "ACGTACGT"
},
{
"input": "252\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "252\n??????????????????????????????????????????????????????????????????????????????A?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????C????????????????????????????????????????????????????????????????",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGCGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????G",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTG"
},
{
"input": "252\nT???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????",
"output": "TAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
},
{
"input": "4\nAA?T",
"output": "==="
},
{
"input": "4\nAAAA",
"output": "==="
},
{
"input": "8\nAAA?????",
"output": "==="
},
{
"input": "10\nACGT??????",
"output": "==="
},
{
"input": "6\nACGACG",
"output": "==="
},
{
"input": "5\nAAAAA",
"output": "==="
},
{
"input": "8\nGGGGAA??",
"output": "==="
},
{
"input": "5\nATGCA",
"output": "==="
},
{
"input": "4\nTTTT",
"output": "==="
},
{
"input": "4\nACCG",
"output": "==="
},
{
"input": "8\nACGTA?GT",
"output": "ACGTACGT"
}
] | 1,641,066,755 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 4 | 92 | 2,252,800 | n = int(input())
s = input()
l = len(s)
count = 0
count1, count2, count3, count4 = 0, 0, 0, 0
for i in range(0, l):
if s[i] == 'A':
count1 = count1+1
if s[i] == 'C':
count2 = count2+1
if s[i] == 'G':
count3 = count3+1
if s[i] == 'T':
count4 = count4+1
if s[i] == '?':
count = count+1
max1 = max(count1, max(count2, max(count3, count4)))
# print("the value of max is "+str(max1)+" "+str(count1)+" "+str(count2)+" "+str(count3)+" "+str(count4))
flag = 0
for i in range(0, l):
if s[i] == '?':
if count1 != max1:
s=s.replace('?','A',1)
count = count-1
count1 = count1+1
elif count2 != max1:
s=s.replace('?','C',1)
count = count-1
count2 = count2+1
elif count3 != max1:
s=s.replace('?','G',1)
count = count-1
count3 = count3+1
elif count4 != max1:
s=s.replace('?','T',1)
count = count-1
count4 = count4+1
else:
if count % 4 == 0 and count1==count2==count3==count4:
flag = 1
if count == 0 and count1==count2==count3==count4:
print(s)
flag = 1
if flag == 1:
break
if flag == 0:
print("===")
elif flag == 1 and count != 0:
m = count/4
s=s.replace('?','A',m)
s=s.replace('?','C',m)
s=s.replace('?','G',m)
s=s.replace('?','T',m)
print(s)
| Title: Mammoth's Genome Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s* is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'.
It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal.
Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal.
Input Specification:
The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome.
The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'.
Output Specification:
If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes).
Demo Input:
['8\nAG?C??CT\n', '4\nAGCT\n', '6\n????G?\n', '4\nAA??\n']
Demo Output:
['AGACGTCT\n', 'AGCT\n', '===\n', '===\n']
Note:
In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is exactly once in it.
In the third and the fourth examples it is impossible to decode the genom. | ```python
n = int(input())
s = input()
l = len(s)
count = 0
count1, count2, count3, count4 = 0, 0, 0, 0
for i in range(0, l):
if s[i] == 'A':
count1 = count1+1
if s[i] == 'C':
count2 = count2+1
if s[i] == 'G':
count3 = count3+1
if s[i] == 'T':
count4 = count4+1
if s[i] == '?':
count = count+1
max1 = max(count1, max(count2, max(count3, count4)))
# print("the value of max is "+str(max1)+" "+str(count1)+" "+str(count2)+" "+str(count3)+" "+str(count4))
flag = 0
for i in range(0, l):
if s[i] == '?':
if count1 != max1:
s=s.replace('?','A',1)
count = count-1
count1 = count1+1
elif count2 != max1:
s=s.replace('?','C',1)
count = count-1
count2 = count2+1
elif count3 != max1:
s=s.replace('?','G',1)
count = count-1
count3 = count3+1
elif count4 != max1:
s=s.replace('?','T',1)
count = count-1
count4 = count4+1
else:
if count % 4 == 0 and count1==count2==count3==count4:
flag = 1
if count == 0 and count1==count2==count3==count4:
print(s)
flag = 1
if flag == 1:
break
if flag == 0:
print("===")
elif flag == 1 and count != 0:
m = count/4
s=s.replace('?','A',m)
s=s.replace('?','C',m)
s=s.replace('?','G',m)
s=s.replace('?','T',m)
print(s)
``` | -1 |
|
932 | B | Recursive Queries | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"dfs and similar"
] | null | null | Let us define two functions *f* and *g* on positive integer numbers.
You need to process *Q* queries. In each query, you will be given three integers *l*, *r* and *k*. You need to print the number of integers *x* between *l* and *r* inclusive, such that *g*(*x*)<==<=*k*. | The first line of the input contains an integer *Q* (1<=≤<=*Q*<=≤<=2<=×<=105) representing the number of queries.
*Q* lines follow, each of which contains 3 integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=106,<=1<=≤<=*k*<=≤<=9). | For each query, print a single line containing the answer for that query. | [
"4\n22 73 9\n45 64 6\n47 55 7\n2 62 4\n",
"4\n82 94 6\n56 67 4\n28 59 9\n39 74 4\n"
] | [
"1\n4\n0\n8\n",
"3\n1\n1\n5\n"
] | In the first example:
- *g*(33) = 9 as *g*(33) = *g*(3 × 3) = *g*(9) = 9 - *g*(47) = *g*(48) = *g*(60) = *g*(61) = 6 - There are no such integers between 47 and 55. - *g*(4) = *g*(14) = *g*(22) = *g*(27) = *g*(39) = *g*(40) = *g*(41) = *g*(58) = 4 | 1,000 | [
{
"input": "4\n22 73 9\n45 64 6\n47 55 7\n2 62 4",
"output": "1\n4\n0\n8"
},
{
"input": "4\n82 94 6\n56 67 4\n28 59 9\n39 74 4",
"output": "3\n1\n1\n5"
}
] | 1,600,851,586 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 2,000 | 21,094,400 | from collections import defaultdict
def product_of_digits(x):
pr = 1
while x:
t = x%10
pr = pr*max(t,1)
x = x//10
return pr
d = defaultdict(list)
Q = int(input())
for i in range(1,10**6+1):
s = product_of_digits(i)
d[s].append(i)
# print(d)
def Binary_Search_l(array,x):
l = 0
r = len(array)-1
while r >= l:
if array[(r+l)//2] >= x:
r = (l+r)//2-1
else:
l = (l+r)//2+1
return l
def Binary_Search_r(array,x):
l = 0
r = len(array)-1
while r > l:
if array[(r+l)//2] <= x:
l = (l+r)//2+1
else:
r = (l+r)//2-1
return r
def DFS(d,x,l,r):
ans = []
visited = set()
stack = [x]
while len(stack):
temp = stack.pop()
visited.add(temp)
if l <= temp and r >= temp:
ans.append(temp)
for j in d[temp]:
if j not in visited:
stack.append(j)
return ans
for i in range(Q):
l,r,k = map(int,input().split())
visited = list(DFS(d,k,l,r))
visited.sort()
print(len(visited)) | Title: Recursive Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let us define two functions *f* and *g* on positive integer numbers.
You need to process *Q* queries. In each query, you will be given three integers *l*, *r* and *k*. You need to print the number of integers *x* between *l* and *r* inclusive, such that *g*(*x*)<==<=*k*.
Input Specification:
The first line of the input contains an integer *Q* (1<=≤<=*Q*<=≤<=2<=×<=105) representing the number of queries.
*Q* lines follow, each of which contains 3 integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=106,<=1<=≤<=*k*<=≤<=9).
Output Specification:
For each query, print a single line containing the answer for that query.
Demo Input:
['4\n22 73 9\n45 64 6\n47 55 7\n2 62 4\n', '4\n82 94 6\n56 67 4\n28 59 9\n39 74 4\n']
Demo Output:
['1\n4\n0\n8\n', '3\n1\n1\n5\n']
Note:
In the first example:
- *g*(33) = 9 as *g*(33) = *g*(3 × 3) = *g*(9) = 9 - *g*(47) = *g*(48) = *g*(60) = *g*(61) = 6 - There are no such integers between 47 and 55. - *g*(4) = *g*(14) = *g*(22) = *g*(27) = *g*(39) = *g*(40) = *g*(41) = *g*(58) = 4 | ```python
from collections import defaultdict
def product_of_digits(x):
pr = 1
while x:
t = x%10
pr = pr*max(t,1)
x = x//10
return pr
d = defaultdict(list)
Q = int(input())
for i in range(1,10**6+1):
s = product_of_digits(i)
d[s].append(i)
# print(d)
def Binary_Search_l(array,x):
l = 0
r = len(array)-1
while r >= l:
if array[(r+l)//2] >= x:
r = (l+r)//2-1
else:
l = (l+r)//2+1
return l
def Binary_Search_r(array,x):
l = 0
r = len(array)-1
while r > l:
if array[(r+l)//2] <= x:
l = (l+r)//2+1
else:
r = (l+r)//2-1
return r
def DFS(d,x,l,r):
ans = []
visited = set()
stack = [x]
while len(stack):
temp = stack.pop()
visited.add(temp)
if l <= temp and r >= temp:
ans.append(temp)
for j in d[temp]:
if j not in visited:
stack.append(j)
return ans
for i in range(Q):
l,r,k = map(int,input().split())
visited = list(DFS(d,k,l,r))
visited.sort()
print(len(visited))
``` | 0 |
|
785 | C | Anton and Fairy Tale | PROGRAMMING | 1,600 | [
"binary search",
"math"
] | null | null | Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale:
"Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that barn for three days and three nights. But they overlooked and there remained a little hole in the barn, from which every day sparrows came through. Here flew a sparrow, took a grain and flew away..."
More formally, the following takes place in the fairy tale. At the beginning of the first day the barn with the capacity of *n* grains was full. Then, every day (starting with the first day) the following happens:
- *m* grains are brought to the barn. If *m* grains doesn't fit to the barn, the barn becomes full and the grains that doesn't fit are brought back (in this problem we can assume that the grains that doesn't fit to the barn are not taken into account). - Sparrows come and eat grain. In the *i*-th day *i* sparrows come, that is on the first day one sparrow come, on the second day two sparrows come and so on. Every sparrow eats one grain. If the barn is empty, a sparrow eats nothing.
Anton is tired of listening how Danik describes every sparrow that eats grain from the barn. Anton doesn't know when the fairy tale ends, so he asked you to determine, by the end of which day the barn will become empty for the first time. Help Anton and write a program that will determine the number of that day! | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018) — the capacity of the barn and the number of grains that are brought every day. | Output one integer — the number of the day when the barn will become empty for the first time. Days are numbered starting with one. | [
"5 2\n",
"8 1\n"
] | [
"4\n",
"5\n"
] | In the first sample the capacity of the barn is five grains and two grains are brought every day. The following happens:
- At the beginning of the first day grain is brought to the barn. It's full, so nothing happens. - At the end of the first day one sparrow comes and eats one grain, so 5 - 1 = 4 grains remain. - At the beginning of the second day two grains are brought. The barn becomes full and one grain doesn't fit to it. - At the end of the second day two sparrows come. 5 - 2 = 3 grains remain. - At the beginning of the third day two grains are brought. The barn becomes full again. - At the end of the third day three sparrows come and eat grain. 5 - 3 = 2 grains remain. - At the beginning of the fourth day grain is brought again. 2 + 2 = 4 grains remain. - At the end of the fourth day four sparrows come and eat grain. 4 - 4 = 0 grains remain. The barn is empty.
So the answer is 4, because by the end of the fourth day the barn becomes empty. | 1,500 | [
{
"input": "5 2",
"output": "4"
},
{
"input": "8 1",
"output": "5"
},
{
"input": "32 5",
"output": "12"
},
{
"input": "1024 1024",
"output": "1024"
},
{
"input": "58044 52909",
"output": "53010"
},
{
"input": "996478063 658866858",
"output": "658892843"
},
{
"input": "570441179141911871 511467058318039545",
"output": "511467058661475480"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "1000000000000000000 999999999999997145",
"output": "999999999999997221"
},
{
"input": "1 1000000000000000000",
"output": "1"
},
{
"input": "1000000000000000000 1",
"output": "1414213563"
},
{
"input": "999999998765257149 10",
"output": "1414213571"
},
{
"input": "999999998765257150 10",
"output": "1414213571"
},
{
"input": "999999998765257151 10",
"output": "1414213571"
},
{
"input": "999999998765257152 10",
"output": "1414213572"
},
{
"input": "999999998765257153 10",
"output": "1414213572"
},
{
"input": "762078938126917521 107528",
"output": "1234675418"
},
{
"input": "762078938126917522 107528",
"output": "1234675418"
},
{
"input": "762078938126917523 107528",
"output": "1234675418"
},
{
"input": "762078938126917524 107528",
"output": "1234675419"
},
{
"input": "762078938126917525 107528",
"output": "1234675419"
},
{
"input": "443233170968441395 1048576",
"output": "942571991"
},
{
"input": "443233170968441396 1048576",
"output": "942571991"
},
{
"input": "443233170968441397 1048576",
"output": "942571992"
},
{
"input": "1833551251625340 1359260576251",
"output": "1359321110406"
},
{
"input": "1835002539467264 2810548418174",
"output": "2810608952329"
},
{
"input": "1840276176082280 8084185033189",
"output": "8084245567345"
},
{
"input": "262133107905 256256256256",
"output": "256256364670"
},
{
"input": "262133108160 256256256256",
"output": "256256364670"
},
{
"input": "262133108161 256256256256",
"output": "256256364670"
},
{
"input": "262133108162 256256256256",
"output": "256256364671"
},
{
"input": "399823373917798976 326385530977846185",
"output": "326385531361089823"
},
{
"input": "836052329491347820 327211774155929609",
"output": "327211775164731428"
},
{
"input": "870979176282270170 16",
"output": "1319832715"
},
{
"input": "930580173005562081 4",
"output": "1364243511"
},
{
"input": "831613653237860272 154",
"output": "1289661856"
},
{
"input": "867842613106376421 178",
"output": "1317454248"
},
{
"input": "939156247712499033 1902",
"output": "1370517314"
},
{
"input": "975385203286047886 1326",
"output": "1396701153"
},
{
"input": "953065701826839766 4023",
"output": "1380631201"
},
{
"input": "989294657400388618 7447",
"output": "1406630820"
},
{
"input": "885695753008586140 42775",
"output": "1330979102"
},
{
"input": "921924708582134992 158903",
"output": "1358043072"
},
{
"input": "802352815201515314 183504",
"output": "1266953266"
},
{
"input": "861953807629839929 1299632",
"output": "1314276256"
},
{
"input": "925155772916259712 1929889",
"output": "1362191462"
},
{
"input": "961384732784775860 5046017",
"output": "1391685648"
},
{
"input": "910494856396204496 39891744",
"output": "1389332262"
},
{
"input": "946723811969753348 17975168",
"output": "1394001194"
},
{
"input": "992316381103677158 1849603453",
"output": "3258373398"
},
{
"input": "828545340972193305 1027686877",
"output": "2314967219"
},
{
"input": "946697532222325132 16179805162",
"output": "17555812078"
},
{
"input": "982926487795873985 19357888587",
"output": "20759977363"
},
{
"input": "892753091050063317 2037020896",
"output": "3373249237"
},
{
"input": "928982046623612170 45215104320",
"output": "46578175853"
},
{
"input": "845950022554437217 1553155668877",
"output": "1554456398264"
},
{
"input": "882178982422953366 1792038785005",
"output": "1793367075026"
},
{
"input": "847407611288100389 9111983407070",
"output": "9113285250762"
},
{
"input": "883636566861649242 15350866523198",
"output": "15352195899906"
},
{
"input": "988545172809612094 126043487780965",
"output": "126044893781768"
},
{
"input": "824774128383160945 152286665864389",
"output": "152287950093217"
},
{
"input": "889067279135046636 783632221444127",
"output": "783633554323452"
},
{
"input": "925296230413628192 1609871104560255",
"output": "1609872463741155"
},
{
"input": "892888041747308306 15921193742955831",
"output": "15921195067317449"
},
{
"input": "929116997320857159 16747432626071959",
"output": "16747433976901012"
},
{
"input": "810365749050428005 176443295773423092",
"output": "176443296899409285"
},
{
"input": "846594708918944153 177269538951506516",
"output": "177269540108507095"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "3 2",
"output": "3"
},
{
"input": "3 3",
"output": "3"
},
{
"input": "4 1",
"output": "3"
},
{
"input": "4 2",
"output": "4"
},
{
"input": "256 20",
"output": "42"
},
{
"input": "78520 8",
"output": "404"
},
{
"input": "1367064836 777314907868410435",
"output": "1367064836"
},
{
"input": "658866858 996478063",
"output": "658866858"
},
{
"input": "10 648271718824741275",
"output": "10"
},
{
"input": "326385530977846185 399823373917798976",
"output": "326385530977846185"
},
{
"input": "327211774155929609 836052329491347820",
"output": "327211774155929609"
},
{
"input": "2570 566042149577952145",
"output": "2570"
},
{
"input": "512486308421983105 512486308421983105",
"output": "512486308421983105"
},
{
"input": "262144 262144",
"output": "262144"
},
{
"input": "314159265358979323 314159265358979323",
"output": "314159265358979323"
},
{
"input": "16 5",
"output": "10"
},
{
"input": "29 16",
"output": "21"
},
{
"input": "24 14",
"output": "18"
},
{
"input": "28 18",
"output": "22"
},
{
"input": "8 11",
"output": "8"
},
{
"input": "500000000500004239 4242",
"output": "1000004242"
},
{
"input": "500000000500004240 4242",
"output": "1000004242"
},
{
"input": "500000000500004241 4242",
"output": "1000004242"
},
{
"input": "500000000500004242 4242",
"output": "1000004242"
},
{
"input": "500000000500004243 4242",
"output": "1000004243"
},
{
"input": "500000000500004244 4242",
"output": "1000004243"
},
{
"input": "500000000500004245 4242",
"output": "1000004243"
},
{
"input": "163162808800191208 163162808800191206",
"output": "163162808800191208"
},
{
"input": "328584130811799021 328584130811799020",
"output": "328584130811799021"
},
{
"input": "89633000579612779 89633000579612778",
"output": "89633000579612779"
},
{
"input": "924211674273037668 924211674273037666",
"output": "924211674273037668"
},
{
"input": "758790352261429854 758790352261429851",
"output": "758790352261429853"
},
{
"input": "39154349371830603 39154349371830597",
"output": "39154349371830600"
},
{
"input": "313727604417502165 313727604417502155",
"output": "313727604417502159"
},
{
"input": "1000000000000000000 999999999999999999",
"output": "1000000000000000000"
},
{
"input": "1000000000000000000 999999999999999998",
"output": "1000000000000000000"
},
{
"input": "1000000000000000000 999999999999999997",
"output": "999999999999999999"
},
{
"input": "1000000000000000000 999999999999999996",
"output": "999999999999999999"
},
{
"input": "1000000000000000000 999999999999999995",
"output": "999999999999999998"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "6 9",
"output": "6"
},
{
"input": "1000000000000000000 2",
"output": "1414213564"
},
{
"input": "1 10",
"output": "1"
},
{
"input": "5 15",
"output": "5"
},
{
"input": "12 1",
"output": "6"
},
{
"input": "1000000000000000000 100000000000000000",
"output": "100000001341640786"
},
{
"input": "100 200",
"output": "100"
},
{
"input": "1 1000000000000000",
"output": "1"
},
{
"input": "100000000000000000 1",
"output": "447213596"
},
{
"input": "1000000000000000000 1000000000000000",
"output": "1000001413506279"
},
{
"input": "1 9",
"output": "1"
},
{
"input": "1000000000000000000 4",
"output": "1414213566"
},
{
"input": "1000000000000 10000000000000",
"output": "1000000000000"
},
{
"input": "1 100000",
"output": "1"
},
{
"input": "3 7",
"output": "3"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "1 8",
"output": "1"
},
{
"input": "5 10",
"output": "5"
},
{
"input": "10 11",
"output": "10"
},
{
"input": "10 100",
"output": "10"
},
{
"input": "5 16",
"output": "5"
},
{
"input": "2 10",
"output": "2"
},
{
"input": "10836 16097",
"output": "10836"
},
{
"input": "16808 75250",
"output": "16808"
},
{
"input": "900000000000169293 1",
"output": "1341640788"
},
{
"input": "1 10000000",
"output": "1"
},
{
"input": "2 100",
"output": "2"
},
{
"input": "10 20",
"output": "10"
},
{
"input": "10 10000",
"output": "10"
},
{
"input": "4 5",
"output": "4"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1000000000000000000 5",
"output": "1414213567"
},
{
"input": "2 5",
"output": "2"
},
{
"input": "4 6",
"output": "4"
},
{
"input": "999999998765257147 1",
"output": "1414213563"
},
{
"input": "3 10",
"output": "3"
},
{
"input": "997270248313594436 707405570208615798",
"output": "707405570970015402"
},
{
"input": "1 100000000000",
"output": "1"
},
{
"input": "6 1000000",
"output": "6"
},
{
"input": "16808 282475250",
"output": "16808"
},
{
"input": "1000000007 100000000000007",
"output": "1000000007"
},
{
"input": "1 1000",
"output": "1"
},
{
"input": "1000000000000000 10000000000000000",
"output": "1000000000000000"
},
{
"input": "1000000000000000000 100",
"output": "1414213662"
},
{
"input": "1000000000000000000 9",
"output": "1414213571"
},
{
"input": "900000000000169293 171",
"output": "1341640957"
},
{
"input": "1 999999999999",
"output": "1"
},
{
"input": "10000 10000000000000",
"output": "10000"
},
{
"input": "1 9999999999999",
"output": "1"
},
{
"input": "695968090125646936 429718492544794353",
"output": "429718493274519777"
},
{
"input": "2 5000",
"output": "2"
},
{
"input": "8 100",
"output": "8"
},
{
"input": "2 7",
"output": "2"
},
{
"input": "999999999999999999 1",
"output": "1414213563"
},
{
"input": "5 8",
"output": "5"
},
{
"input": "1000000000000000000 99999999999999999",
"output": "100000001341640785"
},
{
"input": "100000000000000000 100000000000000000",
"output": "100000000000000000"
},
{
"input": "5 6",
"output": "5"
},
{
"input": "1000000000000000000 1000000000",
"output": "2414213562"
},
{
"input": "1 10000",
"output": "1"
},
{
"input": "22 11",
"output": "16"
},
{
"input": "10 10000000",
"output": "10"
},
{
"input": "3 8",
"output": "3"
},
{
"input": "10 123123",
"output": "10"
},
{
"input": "3 5",
"output": "3"
},
{
"input": "1000000000000000000 10",
"output": "1414213572"
},
{
"input": "10000000000000 45687987897897",
"output": "10000000000000"
},
{
"input": "5 4",
"output": "5"
},
{
"input": "5000 123456789",
"output": "5000"
},
{
"input": "7 100",
"output": "7"
},
{
"input": "1000000000000000000 500000000000",
"output": "501414213209"
},
{
"input": "8 7",
"output": "8"
},
{
"input": "1 10000000000",
"output": "1"
},
{
"input": "1000000000000000000 15",
"output": "1414213577"
},
{
"input": "1 123456789",
"output": "1"
},
{
"input": "2 1000",
"output": "2"
},
{
"input": "5 11",
"output": "5"
},
{
"input": "1 1000000000",
"output": "1"
},
{
"input": "1000000000000000000 499999999999999999",
"output": "500000000999999999"
},
{
"input": "1 100000000",
"output": "1"
},
{
"input": "619768314833382029 108339531052386197",
"output": "108339532063750408"
},
{
"input": "5 100",
"output": "5"
},
{
"input": "2 10000",
"output": "2"
},
{
"input": "1000000000000000000 500000000000000000",
"output": "500000001000000000"
},
{
"input": "143 3",
"output": "20"
},
{
"input": "2 6",
"output": "2"
},
{
"input": "100 1000000000",
"output": "100"
},
{
"input": "2 100000000000000000",
"output": "2"
},
{
"input": "100000000000000000 1000000000000000000",
"output": "100000000000000000"
},
{
"input": "999999999999999999 123456789",
"output": "1537670351"
},
{
"input": "1 99999",
"output": "1"
},
{
"input": "1000000000000000000 9999999999",
"output": "11414213554"
},
{
"input": "5 100000000000000000",
"output": "5"
},
{
"input": "6 999999",
"output": "6"
},
{
"input": "100 10000000",
"output": "100"
},
{
"input": "4 100",
"output": "4"
},
{
"input": "1000000000 1000000000000000",
"output": "1000000000"
},
{
"input": "10 100000",
"output": "10"
},
{
"input": "5 15555555",
"output": "5"
},
{
"input": "5 155555",
"output": "5"
},
{
"input": "200 9999999999",
"output": "200"
},
{
"input": "3 200",
"output": "3"
},
{
"input": "1000000000000000000 490000000000000000",
"output": "490000001009950494"
},
{
"input": "2 4",
"output": "2"
},
{
"input": "5 15555",
"output": "5"
},
{
"input": "5 7",
"output": "5"
},
{
"input": "10040 200000",
"output": "10040"
},
{
"input": "1000000000000000000 60000000000000000",
"output": "60000001371130920"
},
{
"input": "10 1000000000000",
"output": "10"
},
{
"input": "1 45",
"output": "1"
}
] | 1,688,032,821 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 514 | 25,600,000 | import os
import sys
import math
import random
import datetime
import json
import re
import sqlite3
import time
import csv
import smtplib
import hashlib
import threading
import logging
import tkinter as tk
def find_empty_day(n, m):
day = 1 # Начинаем с первого дня
grains = n # Изначальное количество зерна в амбаре
while grains > 0:
grains -= day # Вычитаем количество зерна, которое съели воробьи в текущий день
if grains <= 0:
break # Если зерна больше нет, прерываем цикл
grains += m # Добавляем новое зерно в амбар
day += 1 # Переходим к следующему дню
return day - 1 # Вычитаем 1, чтобы получить номер дня, когда амбар стал пустым
# Вводим вместимость амбара и количество зерна, подвозимое ежедневно
n, m = map(int, input().split())
# Находим номер дня, когда амбар станет пустым
empty_day = find_empty_day(n, m)
# Выводим результат
print(empty_day)
| Title: Anton and Fairy Tale
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale:
"Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that barn for three days and three nights. But they overlooked and there remained a little hole in the barn, from which every day sparrows came through. Here flew a sparrow, took a grain and flew away..."
More formally, the following takes place in the fairy tale. At the beginning of the first day the barn with the capacity of *n* grains was full. Then, every day (starting with the first day) the following happens:
- *m* grains are brought to the barn. If *m* grains doesn't fit to the barn, the barn becomes full and the grains that doesn't fit are brought back (in this problem we can assume that the grains that doesn't fit to the barn are not taken into account). - Sparrows come and eat grain. In the *i*-th day *i* sparrows come, that is on the first day one sparrow come, on the second day two sparrows come and so on. Every sparrow eats one grain. If the barn is empty, a sparrow eats nothing.
Anton is tired of listening how Danik describes every sparrow that eats grain from the barn. Anton doesn't know when the fairy tale ends, so he asked you to determine, by the end of which day the barn will become empty for the first time. Help Anton and write a program that will determine the number of that day!
Input Specification:
The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018) — the capacity of the barn and the number of grains that are brought every day.
Output Specification:
Output one integer — the number of the day when the barn will become empty for the first time. Days are numbered starting with one.
Demo Input:
['5 2\n', '8 1\n']
Demo Output:
['4\n', '5\n']
Note:
In the first sample the capacity of the barn is five grains and two grains are brought every day. The following happens:
- At the beginning of the first day grain is brought to the barn. It's full, so nothing happens. - At the end of the first day one sparrow comes and eats one grain, so 5 - 1 = 4 grains remain. - At the beginning of the second day two grains are brought. The barn becomes full and one grain doesn't fit to it. - At the end of the second day two sparrows come. 5 - 2 = 3 grains remain. - At the beginning of the third day two grains are brought. The barn becomes full again. - At the end of the third day three sparrows come and eat grain. 5 - 3 = 2 grains remain. - At the beginning of the fourth day grain is brought again. 2 + 2 = 4 grains remain. - At the end of the fourth day four sparrows come and eat grain. 4 - 4 = 0 grains remain. The barn is empty.
So the answer is 4, because by the end of the fourth day the barn becomes empty. | ```python
import os
import sys
import math
import random
import datetime
import json
import re
import sqlite3
import time
import csv
import smtplib
import hashlib
import threading
import logging
import tkinter as tk
def find_empty_day(n, m):
day = 1 # Начинаем с первого дня
grains = n # Изначальное количество зерна в амбаре
while grains > 0:
grains -= day # Вычитаем количество зерна, которое съели воробьи в текущий день
if grains <= 0:
break # Если зерна больше нет, прерываем цикл
grains += m # Добавляем новое зерно в амбар
day += 1 # Переходим к следующему дню
return day - 1 # Вычитаем 1, чтобы получить номер дня, когда амбар стал пустым
# Вводим вместимость амбара и количество зерна, подвозимое ежедневно
n, m = map(int, input().split())
# Находим номер дня, когда амбар станет пустым
empty_day = find_empty_day(n, m)
# Выводим результат
print(empty_day)
``` | 0 |
|
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "6"
},
{
"input": "5 1\n998 997 985 937 998",
"output": "0"
},
{
"input": "2 2\n-742 -187",
"output": "929"
},
{
"input": "3 3\n522 597 384",
"output": "0"
},
{
"input": "4 2\n-215 -620 192 647",
"output": "835"
},
{
"input": "10 6\n557 605 685 231 910 633 130 838 -564 -85",
"output": "649"
},
{
"input": "20 14\n932 442 960 943 624 624 955 998 631 910 850 517 715 123 1000 155 -10 961 966 59",
"output": "10"
},
{
"input": "30 5\n991 997 996 967 977 999 991 986 1000 965 984 997 998 1000 958 983 974 1000 991 999 1000 978 961 992 990 998 998 978 998 1000",
"output": "0"
},
{
"input": "50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -799 -886",
"output": "19441"
},
{
"input": "88 64\n999 999 1000 1000 999 996 995 1000 1000 999 1000 997 998 1000 999 1000 997 1000 993 998 994 999 998 996 1000 997 1000 1000 1000 997 1000 998 997 1000 1000 998 1000 998 999 1000 996 999 999 999 996 995 999 1000 998 999 1000 999 999 1000 1000 1000 996 1000 1000 1000 997 1000 1000 997 999 1000 1000 1000 1000 1000 999 999 1000 1000 996 999 1000 1000 995 999 1000 996 1000 998 999 999 1000 999",
"output": "0"
},
{
"input": "99 17\n-993 -994 -959 -989 -991 -995 -976 -997 -990 -1000 -996 -994 -999 -995 -1000 -983 -979 -1000 -989 -968 -994 -992 -962 -993 -999 -983 -991 -979 -995 -993 -973 -999 -995 -995 -999 -993 -995 -992 -947 -1000 -999 -998 -982 -988 -979 -993 -963 -988 -980 -990 -979 -976 -995 -999 -981 -988 -998 -999 -970 -1000 -983 -994 -943 -975 -998 -977 -973 -997 -959 -999 -983 -985 -950 -977 -977 -991 -998 -973 -987 -985 -985 -986 -984 -994 -978 -998 -989 -989 -988 -970 -985 -974 -997 -981 -962 -972 -995 -988 -993",
"output": "16984"
},
{
"input": "100 37\n205 19 -501 404 912 -435 -322 -469 -655 880 -804 -470 793 312 -108 586 -642 -928 906 605 -353 -800 745 -440 -207 752 -50 -28 498 -800 -62 -195 602 -833 489 352 536 404 -775 23 145 -512 524 759 651 -461 -427 -557 684 -366 62 592 -563 -811 64 418 -881 -308 591 -318 -145 -261 -321 -216 -18 595 -202 960 -4 219 226 -238 -882 -963 425 970 -434 -160 243 -672 -4 873 8 -633 904 -298 -151 -377 -61 -72 -677 -66 197 -716 3 -870 -30 152 -469 981",
"output": "21743"
},
{
"input": "100 99\n-931 -806 -830 -828 -916 -962 -660 -867 -952 -966 -820 -906 -724 -982 -680 -717 -488 -741 -897 -613 -986 -797 -964 -939 -808 -932 -810 -860 -641 -916 -858 -628 -821 -929 -917 -976 -664 -985 -778 -665 -624 -928 -940 -958 -884 -757 -878 -896 -634 -526 -514 -873 -990 -919 -988 -878 -650 -973 -774 -783 -733 -648 -756 -895 -833 -974 -832 -725 -841 -748 -806 -613 -924 -867 -881 -943 -864 -991 -809 -926 -777 -817 -998 -682 -910 -996 -241 -722 -964 -904 -821 -920 -835 -699 -805 -632 -779 -317 -915 -654",
"output": "81283"
},
{
"input": "100 14\n995 994 745 684 510 737 984 690 979 977 542 933 871 603 758 653 962 997 747 974 773 766 975 770 527 960 841 989 963 865 974 967 950 984 757 685 986 809 982 959 931 880 978 867 805 562 970 900 834 782 616 885 910 608 974 918 576 700 871 980 656 941 978 759 767 840 573 859 841 928 693 853 716 927 976 851 962 962 627 797 707 873 869 988 993 533 665 887 962 880 929 980 877 887 572 790 721 883 848 782",
"output": "0"
},
{
"input": "100 84\n768 946 998 752 931 912 826 1000 991 910 875 962 901 952 958 733 959 908 872 840 923 826 952 980 974 980 947 955 959 822 997 963 966 933 829 923 971 999 926 932 865 984 974 858 994 855 949 941 992 861 951 949 991 711 763 728 935 485 716 907 869 952 960 859 909 963 978 942 968 933 923 909 997 962 687 764 924 774 875 1000 961 951 987 974 848 921 966 859 995 997 974 931 886 941 974 986 906 978 998 823",
"output": "0"
},
{
"input": "100 80\n-795 -994 -833 -930 -974 -980 -950 -940 -788 -927 -583 -956 -945 -949 -809 -974 -957 -736 -967 -908 -975 -961 -986 -983 -963 -771 -952 -847 -751 -741 -982 -959 -925 -931 -839 -937 -880 -914 -858 -998 -812 -911 -862 -965 -943 -984 -738 -920 -950 -998 -909 -998 -781 -901 -677 -940 -985 -951 -675 -952 -967 -949 -882 -641 -969 -937 -975 -993 -913 -941 -807 -851 -832 -960 -939 -943 -895 -929 -528 -880 -823 -930 -888 -862 -948 -966 -962 -857 -799 -969 -833 -998 -952 -878 -946 -971 -976 -974 -723 -992",
"output": "75068"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 1\n555",
"output": "0"
},
{
"input": "1 1\n-1",
"output": "1"
},
{
"input": "1 1\n-24",
"output": "24"
}
] | 1,663,424,934 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | n,m=list(map(int,input().split()))
lis=list(map(int,input().split()))
lis.sort()
sum=0
for i in range(m):
if(lis[i]<0):
sum=sum+lis[i]
print(abs(sum)) | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output Specification:
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
Demo Input:
['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n']
Demo Output:
['8\n', '7\n']
Note:
none | ```python
n,m=list(map(int,input().split()))
lis=list(map(int,input().split()))
lis.sort()
sum=0
for i in range(m):
if(lis[i]<0):
sum=sum+lis[i]
print(abs(sum))
``` | 3.977 |
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,682,051,234 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 62 | 0 | T = int(input())
i=0
while i<T:
word = input()
if(len(word)>10):
print(word[0],len(word)-2,word[-1],sep="")
else:
print(word)
i+=1
| Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
T = int(input())
i=0
while i<T:
word = input()
if(len(word)>10):
print(word[0],len(word)-2,word[-1],sep="")
else:
print(word)
i+=1
``` | 3.969 |
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,585,640,870 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 109 | 0 | a,b=map(int,input().split());k=[]
for i in range(1,a+1):
c,*d=map(int,input().split())
if min(d)<b:k+=[i]
print(len(k),"\n",*k)
| 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
a,b=map(int,input().split());k=[]
for i in range(1,a+1):
c,*d=map(int,input().split())
if min(d)<b:k+=[i]
print(len(k),"\n",*k)
``` | 3 |
|
10 | A | Power Consumption Calculation | PROGRAMMING | 900 | [
"implementation"
] | A. Power Consumption Calculation | 1 | 256 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T*2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes *P*3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into *n* time periods [*l*1,<=*r*1],<=[*l*2,<=*r*2],<=...,<=[*l**n*,<=*r**n*]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [*l*1,<=*r**n*]. | The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=1440, *r**i*<=<<=*l**i*<=+<=1 for *i*<=<<=*n*), which stand for the start and the end of the *i*-th period of work. | Output the answer to the problem. | [
"1 3 2 1 5 10\n0 10\n",
"2 8 4 2 5 10\n20 30\n50 100\n"
] | [
"30",
"570"
] | none | 0 | [
{
"input": "1 3 2 1 5 10\n0 10",
"output": "30"
},
{
"input": "2 8 4 2 5 10\n20 30\n50 100",
"output": "570"
},
{
"input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436",
"output": "8445"
},
{
"input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945",
"output": "52870"
},
{
"input": "5 41 20 33 43 4\n46 465\n598 875\n967 980\n1135 1151\n1194 1245",
"output": "46995"
},
{
"input": "6 88 28 100 53 36\n440 445\n525 614\n644 844\n1238 1261\n1305 1307\n1425 1434",
"output": "85540"
},
{
"input": "7 46 61 55 28 59\n24 26\n31 61\n66 133\n161 612\n741 746\n771 849\n1345 1357",
"output": "67147"
},
{
"input": "8 83 18 30 28 5\n196 249\n313 544\n585 630\n718 843\n1040 1194\n1207 1246\n1268 1370\n1414 1422",
"output": "85876"
},
{
"input": "9 31 65 27 53 54\n164 176\n194 210\n485 538\n617 690\n875 886\n888 902\n955 957\n1020 1200\n1205 1282",
"output": "38570"
},
{
"input": "30 3 1 58 44 7\n11 13\n14 32\n37 50\n70 74\n101 106\n113 129\n184 195\n197 205\n213 228\n370 394\n443 446\n457 460\n461 492\n499 585\n602 627\n709 776\n812 818\n859 864\n910 913\n918 964\n1000 1010\n1051 1056\n1063 1075\n1106 1145\n1152 1189\n1211 1212\n1251 1259\n1272 1375\n1412 1417\n1430 1431",
"output": "11134"
},
{
"input": "30 42 3 76 28 26\n38 44\n55 66\n80 81\n84 283\n298 314\n331 345\n491 531\n569 579\n597 606\n612 617\n623 701\n723 740\n747 752\n766 791\n801 827\n842 846\n853 891\n915 934\n945 949\n955 964\n991 1026\n1051 1059\n1067 1179\n1181 1191\n1214 1226\n1228 1233\n1294 1306\n1321 1340\n1371 1374\n1375 1424",
"output": "59043"
},
{
"input": "30 46 5 93 20 46\n12 34\n40 41\n54 58\n100 121\n162 182\n220 349\n358 383\n390 398\n401 403\n408 409\n431 444\n466 470\n471 535\n556 568\n641 671\n699 709\n767 777\n786 859\n862 885\n912 978\n985 997\n1013 1017\n1032 1038\n1047 1048\n1062 1080\n1094 1097\n1102 1113\n1122 1181\n1239 1280\n1320 1369",
"output": "53608"
},
{
"input": "30 50 74 77 4 57\n17 23\n24 61\n67 68\n79 87\n93 101\n104 123\n150 192\n375 377\n398 414\n461 566\n600 633\n642 646\n657 701\n771 808\n812 819\n823 826\n827 833\n862 875\n880 891\n919 920\n928 959\n970 1038\n1057 1072\n1074 1130\n1165 1169\n1171 1230\n1265 1276\n1279 1302\n1313 1353\n1354 1438",
"output": "84067"
},
{
"input": "30 54 76 95 48 16\n9 11\n23 97\n112 116\n126 185\n214 223\n224 271\n278 282\n283 348\n359 368\n373 376\n452 463\n488 512\n532 552\n646 665\n681 685\n699 718\n735 736\n750 777\n791 810\n828 838\n841 858\n874 1079\n1136 1171\n1197 1203\n1210 1219\n1230 1248\n1280 1292\n1324 1374\n1397 1435\n1438 1439",
"output": "79844"
},
{
"input": "30 58 78 12 41 28\n20 26\n27 31\n35 36\n38 99\n103 104\n106 112\n133 143\n181 246\n248 251\n265 323\n350 357\n378 426\n430 443\n466 476\n510 515\n517 540\n542 554\n562 603\n664 810\n819 823\n826 845\n869 895\n921 973\n1002 1023\n1102 1136\n1143 1148\n1155 1288\n1316 1388\n1394 1403\n1434 1437",
"output": "82686"
},
{
"input": "30 62 80 97 25 47\n19 20\n43 75\n185 188\n199 242\n252 258\n277 310\n316 322\n336 357\n398 399\n404 436\n443 520\n549 617\n637 649\n679 694\n705 715\n725 730\n731 756\n768 793\n806 833\n834 967\n1003 1079\n1088 1097\n1100 1104\n1108 1121\n1127 1164\n1240 1263\n1274 1307\n1367 1407\n1419 1425\n1433 1437",
"output": "92356"
},
{
"input": "30 100 48 14 9 7\n26 55\n75 107\n145 146\n158 167\n197 199\n201 213\n222 238\n257 265\n271 338\n357 439\n454 462\n463 562\n633 660\n670 691\n696 829\n844 864\n880 888\n891 894\n895 900\n950 973\n1004 1007\n1018 1021\n1045 1049\n1062 1073\n1138 1184\n1240 1272\n1278 1315\n1403 1410\n1412 1418\n1426 1434",
"output": "107490"
},
{
"input": "30 3 50 32 1 18\n46 60\n66 94\n99 141\n162 239\n309 334\n400 550\n594 630\n659 663\n664 701\n735 736\n741 755\n756 801\n823 854\n865 915\n937 964\n984 986\n990 1007\n1008 1031\n1052 1064\n1073 1080\n1190 1191\n1192 1254\n1265 1266\n1272 1273\n1274 1277\n1284 1302\n1308 1312\n1358 1383\n1388 1389\n1390 1401",
"output": "25258"
},
{
"input": "30 7 52 49 46 37\n2 73\n129 130\n131 140\n143 150\n187 190\n217 238\n248 271\n375 426\n465 470\n475 503\n506 541\n569 571\n578 585\n680 683\n690 738\n742 761\n868 877\n890 892\n904 915\n935 961\n1076 1100\n1103 1114\n1232 1244\n1246 1247\n1257 1261\n1271 1276\n1280 1298\n1346 1360\n1373 1382\n1407 1419",
"output": "23992"
}
] | 1,674,683,181 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 124 | 0 | n, P1, P2, P3, T1, T2=map(int,input().split())
s=0
for i in range(n):
l,r=map(int,input().split())
if i==0:
t=l
if T1>=(l-t):
s+=(l-t)*P1
else:
s+=T1*P1
if T2>=(l-T1-t):
s+=(l-T1-t)*P2
else:
s+=T2*P2
s+=(l-T1-T2-t)*P3
s+=(r-l)*P1
t=r
print(s) | Title: Power Consumption Calculation
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T*2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes *P*3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into *n* time periods [*l*1,<=*r*1],<=[*l*2,<=*r*2],<=...,<=[*l**n*,<=*r**n*]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [*l*1,<=*r**n*].
Input Specification:
The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=1440, *r**i*<=<<=*l**i*<=+<=1 for *i*<=<<=*n*), which stand for the start and the end of the *i*-th period of work.
Output Specification:
Output the answer to the problem.
Demo Input:
['1 3 2 1 5 10\n0 10\n', '2 8 4 2 5 10\n20 30\n50 100\n']
Demo Output:
['30', '570']
Note:
none | ```python
n, P1, P2, P3, T1, T2=map(int,input().split())
s=0
for i in range(n):
l,r=map(int,input().split())
if i==0:
t=l
if T1>=(l-t):
s+=(l-t)*P1
else:
s+=T1*P1
if T2>=(l-T1-t):
s+=(l-T1-t)*P2
else:
s+=T2*P2
s+=(l-T1-T2-t)*P3
s+=(r-l)*P1
t=r
print(s)
``` | 3.938 |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.
One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.
Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.
Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=><=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix? | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
"output": "YES"
},
{
"input": "5 7",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "11 13",
"output": "YES"
},
{
"input": "13 17",
"output": "YES"
},
{
"input": "17 19",
"output": "YES"
},
{
"input": "19 23",
"output": "YES"
},
{
"input": "23 29",
"output": "YES"
},
{
"input": "29 31",
"output": "YES"
},
{
"input": "31 37",
"output": "YES"
},
{
"input": "37 41",
"output": "YES"
},
{
"input": "41 43",
"output": "YES"
},
{
"input": "43 47",
"output": "YES"
},
{
"input": "2 5",
"output": "NO"
},
{
"input": "2 7",
"output": "NO"
},
{
"input": "2 6",
"output": "NO"
},
{
"input": "2 11",
"output": "NO"
},
{
"input": "3 6",
"output": "NO"
},
{
"input": "3 7",
"output": "NO"
},
{
"input": "3 9",
"output": "NO"
},
{
"input": "5 6",
"output": "NO"
},
{
"input": "5 9",
"output": "NO"
},
{
"input": "5 11",
"output": "NO"
},
{
"input": "5 13",
"output": "NO"
},
{
"input": "5 15",
"output": "NO"
},
{
"input": "7 8",
"output": "NO"
},
{
"input": "7 13",
"output": "NO"
},
{
"input": "13 15",
"output": "NO"
},
{
"input": "13 17",
"output": "YES"
},
{
"input": "19 21",
"output": "NO"
},
{
"input": "13 20",
"output": "NO"
},
{
"input": "41 49",
"output": "NO"
},
{
"input": "43 49",
"output": "NO"
},
{
"input": "47 50",
"output": "NO"
},
{
"input": "47 49",
"output": "NO"
},
{
"input": "47 48",
"output": "NO"
},
{
"input": "23 25",
"output": "NO"
},
{
"input": "2 50",
"output": "NO"
},
{
"input": "31 33",
"output": "NO"
}
] | 1,683,212,844 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 39 | 154 | 0 | a=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
n,m=map(int,input().split())
for i in range(len(a)-1):
if n==a[i]:
if m==a[i+1]:
print('YES')
else:
print('NO') | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.
One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.
Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.
Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=><=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
Input Specification:
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4.
Output Specification:
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
Demo Input:
['3 5\n', '7 11\n', '7 9\n']
Demo Output:
['YES', 'YES', 'NO']
Note:
none | ```python
a=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
n,m=map(int,input().split())
for i in range(len(a)-1):
if n==a[i]:
if m==a[i+1]:
print('YES')
else:
print('NO')
``` | 0 |
587 | A | Duff and Weight Lifting | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of *i*-th of them is 2*w**i* pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2*a*1,<=...,<=2*a**k* if and only if there exists a non-negative integer *x* such that 2*a*1<=+<=2*a*2<=+<=...<=+<=2*a**k*<==<=2*x*, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps. | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=106), the number of weights.
The second line contains *n* integers *w*1,<=...,<=*w**n* separated by spaces (0<=≤<=*w**i*<=≤<=106 for each 1<=≤<=*i*<=≤<=*n*), the powers of two forming the weights values. | Print the minimum number of steps in a single line. | [
"5\n1 1 2 3 3\n",
"4\n0 1 2 3\n"
] | [
"2\n",
"4\n"
] | In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two. | 500 | [
{
"input": "5\n1 1 2 3 3",
"output": "2"
},
{
"input": "4\n0 1 2 3",
"output": "4"
},
{
"input": "1\n120287",
"output": "1"
},
{
"input": "2\n28288 0",
"output": "2"
},
{
"input": "2\n95745 95745",
"output": "1"
},
{
"input": "13\n92 194 580495 0 10855 41704 13 96429 33 213 0 92 140599",
"output": "11"
},
{
"input": "13\n688743 688743 1975 688743 688743 688743 688743 688743 688743 0 0 688743 688743",
"output": "4"
},
{
"input": "35\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",
"output": "3"
},
{
"input": "35\n130212 3176 77075 8071 18 1369 7539 1683 80757 1847 0 1374 122 8524 4 2 21333 270264 4 9254 151921 0 1 33596 73002 54382 0 1 29233 75952 15 38892 1877 6167 4",
"output": "31"
},
{
"input": "35\n0 0 298 0 0 0 0 0 689063 65442 0 984598 2054 43668 0 369 0 2054 0 996220 0 16327 369 0 996220 0 0 0 4693 2054 348 0 118 0 0",
"output": "16"
},
{
"input": "100\n196 1681 196 0 61 93 196 196 196 196 196 0 0 96 18 1576 0 93 666463 18 93 1 1278 8939 93 196 196 1278 3 0 67416 869956 10 56489 196 745 39 783 196 8939 196 81 69634 4552 39 3 14 20 25 8 10 4 7302 0 19579 20 1140 15990 7302 0 19579 4142 11 1354 75252 93 311 1278 0 79475 10 75252 93 7302 0 81 408441 19579 10 39 19 37748 4364 31135 47700 105818 47700 10 4142 543356 3 30647 45917 60714 8939 18 22925 7302 93 75252",
"output": "59"
}
] | 1,500,585,400 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 4,608,000 | # Description of the problem can be found at http://codeforces.com/problemset/problem/581/C
n, k = map(int, input().split())
l_s = list(map(int, input().split()))
l_s.sort(key = lambda x: x % 10 if x != 100 else x, reverse = True)
t = 0
r = 0
index = 0
for i in l_s:
n_i = i
if i != 100:
n_i += min(k, 10 - i % 10)
k -= n_i - i
r += 100 - n_i
t += n_i // 10
t += min(r // 10, k // 10)
print(t) | Title: Duff and Weight Lifting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of *i*-th of them is 2*w**i* pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2*a*1,<=...,<=2*a**k* if and only if there exists a non-negative integer *x* such that 2*a*1<=+<=2*a*2<=+<=...<=+<=2*a**k*<==<=2*x*, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input Specification:
The first line of input contains integer *n* (1<=≤<=*n*<=≤<=106), the number of weights.
The second line contains *n* integers *w*1,<=...,<=*w**n* separated by spaces (0<=≤<=*w**i*<=≤<=106 for each 1<=≤<=*i*<=≤<=*n*), the powers of two forming the weights values.
Output Specification:
Print the minimum number of steps in a single line.
Demo Input:
['5\n1 1 2 3 3\n', '4\n0 1 2 3\n']
Demo Output:
['2\n', '4\n']
Note:
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two. | ```python
# Description of the problem can be found at http://codeforces.com/problemset/problem/581/C
n, k = map(int, input().split())
l_s = list(map(int, input().split()))
l_s.sort(key = lambda x: x % 10 if x != 100 else x, reverse = True)
t = 0
r = 0
index = 0
for i in l_s:
n_i = i
if i != 100:
n_i += min(k, 10 - i % 10)
k -= n_i - i
r += 100 - n_i
t += n_i // 10
t += min(r // 10, k // 10)
print(t)
``` | -1 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of *m* points *p*1,<=*p*2,<=...,<=*p**m* with integer coordinates, do the following: denote its initial location by *p*0. First, the robot will move from *p*0 to *p*1 along one of the shortest paths between them (please notice that since the robot moves only along the grid lines, there can be several shortest paths). Then, after it reaches *p*1, it'll move to *p*2, again, choosing one of the shortest ways, then to *p*3, and so on, until he has visited all points in the given order. Some of the points in the sequence may coincide, in that case Robot will visit that point several times according to the sequence order.
While Santa was away, someone gave a sequence of points to Robot. This sequence is now lost, but Robot saved the protocol of its unit movements. Please, find the minimum possible length of the sequence. | The first line of input contains the only positive integer *n* (1<=≤<=*n*<=≤<=2·105) which equals the number of unit segments the robot traveled. The second line contains the movements protocol, which consists of *n* letters, each being equal either L, or R, or U, or D. *k*-th letter stands for the direction which Robot traveled the *k*-th unit segment in: L means that it moved to the left, R — to the right, U — to the top and D — to the bottom. Have a look at the illustrations for better explanation. | The only line of input should contain the minimum possible length of the sequence. | [
"4\nRURD\n",
"6\nRRULDD\n",
"26\nRRRULURURUULULLLDLDDRDRDLD\n",
"3\nRLL\n",
"4\nLRLR\n"
] | [
"2\n",
"2\n",
"7\n",
"2\n",
"4\n"
] | The illustrations to the first three tests are given below.
<img class="tex-graphics" src="https://espresso.codeforces.com/832fb8f97a482be815e0f87edde26c9791a0d330.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/119a8ba68772b2c2bf76f2acdc58027f6c5cde1f.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/c7b4534f24cbad48148bcba24bc44f37bf7a2dbf.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The last example illustrates that each point in the sequence should be counted as many times as it is presented in the sequence. | 0 | [
{
"input": "4\nRURD",
"output": "2"
},
{
"input": "6\nRRULDD",
"output": "2"
},
{
"input": "26\nRRRULURURUULULLLDLDDRDRDLD",
"output": "7"
},
{
"input": "3\nRLL",
"output": "2"
},
{
"input": "4\nLRLR",
"output": "4"
},
{
"input": "5\nLRDLR",
"output": "4"
},
{
"input": "10\nDDRDUULUDD",
"output": "3"
},
{
"input": "1\nD",
"output": "1"
}
] | 1,482,659,473 | 2,773 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 2,000 | 5,222,400 | n=int(input())
s=input()
L,R,U,D=False,False,False,False
c=0
for i in range(n):
exec(s[i]+'=True')
if (L and R) or (U and D):
c+=1
L,R,U,D=False,False,False,False
exec(s[i]+'=True')
c+=1
print(c)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of *m* points *p*1,<=*p*2,<=...,<=*p**m* with integer coordinates, do the following: denote its initial location by *p*0. First, the robot will move from *p*0 to *p*1 along one of the shortest paths between them (please notice that since the robot moves only along the grid lines, there can be several shortest paths). Then, after it reaches *p*1, it'll move to *p*2, again, choosing one of the shortest ways, then to *p*3, and so on, until he has visited all points in the given order. Some of the points in the sequence may coincide, in that case Robot will visit that point several times according to the sequence order.
While Santa was away, someone gave a sequence of points to Robot. This sequence is now lost, but Robot saved the protocol of its unit movements. Please, find the minimum possible length of the sequence.
Input Specification:
The first line of input contains the only positive integer *n* (1<=≤<=*n*<=≤<=2·105) which equals the number of unit segments the robot traveled. The second line contains the movements protocol, which consists of *n* letters, each being equal either L, or R, or U, or D. *k*-th letter stands for the direction which Robot traveled the *k*-th unit segment in: L means that it moved to the left, R — to the right, U — to the top and D — to the bottom. Have a look at the illustrations for better explanation.
Output Specification:
The only line of input should contain the minimum possible length of the sequence.
Demo Input:
['4\nRURD\n', '6\nRRULDD\n', '26\nRRRULURURUULULLLDLDDRDRDLD\n', '3\nRLL\n', '4\nLRLR\n']
Demo Output:
['2\n', '2\n', '7\n', '2\n', '4\n']
Note:
The illustrations to the first three tests are given below.
<img class="tex-graphics" src="https://espresso.codeforces.com/832fb8f97a482be815e0f87edde26c9791a0d330.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/119a8ba68772b2c2bf76f2acdc58027f6c5cde1f.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/c7b4534f24cbad48148bcba24bc44f37bf7a2dbf.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The last example illustrates that each point in the sequence should be counted as many times as it is presented in the sequence. | ```python
n=int(input())
s=input()
L,R,U,D=False,False,False,False
c=0
for i in range(n):
exec(s[i]+'=True')
if (L and R) or (U and D):
c+=1
L,R,U,D=False,False,False,False
exec(s[i]+'=True')
c+=1
print(c)
``` | 0 |
|
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "".
You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings.
Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal. | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es".
In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty.
In the fourth example, the first character of the second string should be deleted. | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
"output": "18"
},
{
"input": "z\na",
"output": "2"
},
{
"input": "ama\nsama",
"output": "1"
},
{
"input": "aaabc\nbc",
"output": "3"
},
{
"input": "lxuyspmieeuyxluv\ndfwxqvavzxctblaa",
"output": "32"
},
{
"input": "ahmedaly\naly",
"output": "5"
},
{
"input": "aa\na",
"output": "1"
},
{
"input": "aa\nba",
"output": "2"
},
{
"input": "cccba\nba",
"output": "3"
},
{
"input": "a\nab",
"output": "3"
},
{
"input": "dadc\ndddc",
"output": "4"
},
{
"input": "aacaaab\nb",
"output": "6"
},
{
"input": "dddc\ncdcde",
"output": "9"
},
{
"input": "bbdab\ndab",
"output": "2"
},
{
"input": "a\naa",
"output": "1"
},
{
"input": "aa\nab",
"output": "4"
},
{
"input": "codeforces\nces",
"output": "7"
}
] | 1,693,768,633 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 921,600 | word_1, word_2 = input(), input()
total = 0
l1, l2 = len(word_1), len(word_2)
if l1 > l2:
word_1 = word_1[l1 - l2:]
total += l1 - l2
elif l2 > l1:
word_2 = word_2[l2 - l1:]
total += l2 - l1
while word_1 != "":
if word_1 == word_2 :
break
else:
word_1, word_2 = word_1[1:], word_2[1:]
total += 2
print(total)
# Sun Sep 03 2023 22:17:12 GMT+0300 (Moscow Standard Time)
| Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "".
You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings.
Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal.
Input Specification:
The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive.
Output Specification:
Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.
Demo Input:
['test\nwest\n', 'codeforces\nyes\n', 'test\nyes\n', 'b\nab\n']
Demo Output:
['2\n', '9\n', '7\n', '1\n']
Note:
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es".
In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty.
In the fourth example, the first character of the second string should be deleted. | ```python
word_1, word_2 = input(), input()
total = 0
l1, l2 = len(word_1), len(word_2)
if l1 > l2:
word_1 = word_1[l1 - l2:]
total += l1 - l2
elif l2 > l1:
word_2 = word_2[l2 - l1:]
total += l2 - l1
while word_1 != "":
if word_1 == word_2 :
break
else:
word_1, word_2 = word_1[1:], word_2[1:]
total += 2
print(total)
# Sun Sep 03 2023 22:17:12 GMT+0300 (Moscow Standard Time)
``` | 0 |
|
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct.
Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions. | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters.
In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it.
Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests. | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcdefghijklm"
},
{
"input": "100 2",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababab"
},
{
"input": "100 10",
"output": "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij"
},
{
"input": "3 3",
"output": "abc"
},
{
"input": "6 3",
"output": "abcabc"
},
{
"input": "10 3",
"output": "abcabcabca"
},
{
"input": "50 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab"
},
{
"input": "90 2",
"output": "ababababababababababababababababababababababababababababababababababababababababababababab"
},
{
"input": "6 2",
"output": "ababab"
},
{
"input": "99 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc"
},
{
"input": "4 2",
"output": "abab"
},
{
"input": "100 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca"
},
{
"input": "40 22",
"output": "abcdefghijklmnopqrstuvabcdefghijklmnopqr"
},
{
"input": "13 8",
"output": "abcdefghabcde"
},
{
"input": "16 15",
"output": "abcdefghijklmnoa"
},
{
"input": "17 17",
"output": "abcdefghijklmnopq"
},
{
"input": "19 4",
"output": "abcdabcdabcdabcdabc"
},
{
"input": "100 26",
"output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv"
},
{
"input": "100 25",
"output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy"
},
{
"input": "26 26",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "27 26",
"output": "abcdefghijklmnopqrstuvwxyza"
},
{
"input": "2 2",
"output": "ab"
},
{
"input": "26 25",
"output": "abcdefghijklmnopqrstuvwxya"
},
{
"input": "99 2",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababa"
},
{
"input": "99 26",
"output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu"
},
{
"input": "4 4",
"output": "abcd"
},
{
"input": "5 3",
"output": "abcab"
},
{
"input": "5 4",
"output": "abcda"
},
{
"input": "5 5",
"output": "abcde"
},
{
"input": "24 22",
"output": "abcdefghijklmnopqrstuvab"
},
{
"input": "26 14",
"output": "abcdefghijklmnabcdefghijkl"
},
{
"input": "26 15",
"output": "abcdefghijklmnoabcdefghijk"
},
{
"input": "30 12",
"output": "abcdefghijklabcdefghijklabcdef"
},
{
"input": "35 4",
"output": "abcdabcdabcdabcdabcdabcdabcdabcdabc"
},
{
"input": "79 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca"
},
{
"input": "79 14",
"output": "abcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghi"
},
{
"input": "85 13",
"output": "abcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefg"
},
{
"input": "90 25",
"output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmno"
},
{
"input": "90 19",
"output": "abcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmn"
},
{
"input": "26 24",
"output": "abcdefghijklmnopqrstuvwxab"
},
{
"input": "100 17",
"output": "abcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmno"
},
{
"input": "26 2",
"output": "ababababababababababababab"
}
] | 1,632,321,387 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import string
alpha = string.ascii_lowercase
size, rng = map(int,input().split())
req = alpha[:rng]
pwd = ''
ct = 0a
for i in range(size):
if ct >= rng:
ct = 0
pwd += req[ct]
ct+=1
print(pwd) | Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct.
Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions.
Input Specification:
The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists.
Output Specification:
Print any password which satisfies all conditions given by Innokentiy.
Demo Input:
['4 3\n', '6 6\n', '5 2\n']
Demo Output:
['java\n', 'python\n', 'phphp\n']
Note:
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters.
In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it.
Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests. | ```python
import string
alpha = string.ascii_lowercase
size, rng = map(int,input().split())
req = alpha[:rng]
pwd = ''
ct = 0a
for i in range(size):
if ct >= rng:
ct = 0
pwd += req[ct]
ct+=1
print(pwd)
``` | -1 |
|
864 | A | Fair Game | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written.
The game is considered fair if Petya and Vasya can take all *n* cards, and the number of cards each player gets is the same.
Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number.
The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards. | If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more.
In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them. | [
"4\n11\n27\n27\n11\n",
"2\n6\n6\n",
"6\n10\n20\n30\n20\n10\n20\n",
"6\n1\n1\n2\n2\n3\n3\n"
] | [
"YES\n11 27\n",
"NO\n",
"NO\n",
"NO\n"
] | In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.
In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct.
In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards — for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards. | 500 | [
{
"input": "4\n11\n27\n27\n11",
"output": "YES\n11 27"
},
{
"input": "2\n6\n6",
"output": "NO"
},
{
"input": "6\n10\n20\n30\n20\n10\n20",
"output": "NO"
},
{
"input": "6\n1\n1\n2\n2\n3\n3",
"output": "NO"
},
{
"input": "2\n1\n100",
"output": "YES\n1 100"
},
{
"input": "2\n1\n1",
"output": "NO"
},
{
"input": "2\n100\n100",
"output": "NO"
},
{
"input": "14\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43",
"output": "NO"
},
{
"input": "100\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32",
"output": "YES\n14 32"
},
{
"input": "2\n50\n100",
"output": "YES\n50 100"
},
{
"input": "2\n99\n100",
"output": "YES\n99 100"
},
{
"input": "4\n4\n4\n5\n5",
"output": "YES\n4 5"
},
{
"input": "10\n10\n10\n10\n10\n10\n23\n23\n23\n23\n23",
"output": "YES\n10 23"
},
{
"input": "20\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n11\n11\n11\n11\n11\n11\n11\n11\n11\n11",
"output": "YES\n11 34"
},
{
"input": "40\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30",
"output": "YES\n20 30"
},
{
"input": "58\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "YES\n1 100"
},
{
"input": "98\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99",
"output": "YES\n2 99"
},
{
"input": "100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "YES\n1 100"
},
{
"input": "100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2",
"output": "YES\n1 2"
},
{
"input": "100\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12",
"output": "YES\n12 49"
},
{
"input": "100\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94",
"output": "YES\n15 94"
},
{
"input": "100\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42",
"output": "YES\n33 42"
},
{
"input": "100\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35",
"output": "YES\n16 35"
},
{
"input": "100\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44",
"output": "YES\n33 44"
},
{
"input": "100\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98",
"output": "YES\n54 98"
},
{
"input": "100\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12",
"output": "YES\n12 81"
},
{
"input": "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "NO"
},
{
"input": "100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "NO"
},
{
"input": "40\n20\n20\n30\n30\n20\n20\n20\n30\n30\n20\n20\n30\n30\n30\n30\n20\n30\n30\n30\n30\n20\n20\n30\n30\n30\n20\n30\n20\n30\n20\n30\n20\n20\n20\n30\n20\n20\n20\n30\n30",
"output": "NO"
},
{
"input": "58\n100\n100\n100\n100\n100\n1\n1\n1\n1\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n100\n1\n100\n100\n100\n100\n100\n1\n1\n100\n100\n100\n100\n1\n100\n1\n1\n1\n1\n1",
"output": "NO"
},
{
"input": "98\n2\n99\n99\n99\n99\n2\n99\n99\n99\n2\n2\n99\n2\n2\n2\n2\n99\n99\n2\n99\n2\n2\n99\n99\n99\n99\n2\n2\n99\n2\n99\n99\n2\n2\n99\n2\n99\n2\n99\n2\n2\n2\n99\n2\n2\n2\n2\n99\n99\n99\n99\n2\n2\n2\n2\n2\n2\n2\n2\n99\n2\n99\n99\n2\n2\n99\n99\n99\n99\n99\n99\n99\n99\n2\n99\n2\n99\n2\n2\n2\n99\n99\n99\n99\n99\n99\n2\n99\n99\n2\n2\n2\n2\n2\n99\n99\n99\n2",
"output": "NO"
},
{
"input": "100\n100\n1\n100\n1\n1\n100\n1\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n1\n100\n1\n100\n1\n100\n100\n1\n100\n1\n100\n1\n1\n1\n1\n1\n100\n1\n100\n100\n100\n1\n100\n100\n1\n100\n1\n1\n100\n100\n100\n1\n100\n100\n1\n1\n100\n100\n1\n100\n1\n100\n1\n1\n100\n100\n100\n100\n100\n100\n1\n100\n100\n1\n100\n100\n1\n100\n1\n1\n1\n100\n100\n1\n100\n1\n100\n1\n1\n1\n1\n100\n1\n1\n100\n1\n100\n100\n1\n100\n1\n100",
"output": "NO"
},
{
"input": "100\n100\n100\n100\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n100\n1\n100\n1\n100\n1\n100\n100\n100\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n1\n100\n100\n1\n100\n1\n1\n100\n1\n1\n100\n1\n100\n100\n100\n1\n100\n100\n100\n1\n100\n1\n100\n100\n100\n1\n1\n100\n100\n100\n100\n1\n100\n36\n100\n1\n100\n1\n100\n100\n100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n100\n1\n1\n100\n100\n100\n100\n100\n1\n100\n1\n100\n1\n1\n100\n100\n1\n100",
"output": "NO"
},
{
"input": "100\n2\n1\n1\n2\n2\n1\n1\n1\n1\n2\n1\n1\n1\n2\n2\n2\n1\n1\n1\n2\n1\n2\n2\n2\n2\n1\n1\n2\n1\n1\n2\n1\n27\n1\n1\n1\n2\n2\n2\n1\n2\n1\n2\n1\n1\n2\n2\n2\n2\n2\n2\n2\n2\n1\n2\n2\n2\n2\n1\n2\n1\n1\n1\n1\n1\n2\n1\n1\n1\n2\n2\n2\n2\n2\n2\n1\n1\n1\n1\n2\n2\n1\n2\n2\n1\n1\n1\n2\n1\n2\n2\n1\n1\n2\n1\n1\n1\n2\n2\n1",
"output": "NO"
},
{
"input": "100\n99\n99\n100\n99\n99\n100\n100\n100\n99\n100\n99\n99\n100\n99\n99\n99\n99\n99\n99\n100\n100\n100\n99\n100\n100\n99\n100\n99\n100\n100\n99\n100\n99\n99\n99\n100\n99\n10\n99\n100\n100\n100\n99\n100\n100\n100\n100\n100\n100\n100\n99\n100\n100\n100\n99\n99\n100\n99\n100\n99\n100\n100\n99\n99\n99\n99\n100\n99\n100\n100\n100\n100\n100\n100\n99\n99\n100\n100\n99\n99\n99\n99\n99\n99\n100\n99\n99\n100\n100\n99\n100\n99\n99\n100\n99\n99\n99\n99\n100\n100",
"output": "NO"
},
{
"input": "100\n29\n43\n43\n29\n43\n29\n29\n29\n43\n29\n29\n29\n29\n43\n29\n29\n29\n29\n43\n29\n29\n29\n43\n29\n29\n29\n43\n43\n43\n43\n43\n43\n29\n29\n43\n43\n43\n29\n43\n43\n43\n29\n29\n29\n43\n29\n29\n29\n43\n43\n43\n43\n29\n29\n29\n29\n43\n29\n43\n43\n29\n29\n43\n43\n29\n29\n95\n29\n29\n29\n43\n43\n29\n29\n29\n29\n29\n43\n43\n43\n43\n29\n29\n43\n43\n43\n43\n43\n43\n29\n43\n43\n43\n43\n43\n43\n29\n43\n29\n43",
"output": "NO"
},
{
"input": "100\n98\n98\n98\n88\n88\n88\n88\n98\n98\n88\n98\n88\n98\n88\n88\n88\n88\n88\n98\n98\n88\n98\n98\n98\n88\n88\n88\n98\n98\n88\n88\n88\n98\n88\n98\n88\n98\n88\n88\n98\n98\n98\n88\n88\n98\n98\n88\n88\n88\n88\n88\n98\n98\n98\n88\n98\n88\n88\n98\n98\n88\n98\n88\n88\n98\n88\n88\n98\n27\n88\n88\n88\n98\n98\n88\n88\n98\n98\n98\n98\n98\n88\n98\n88\n98\n98\n98\n98\n88\n88\n98\n88\n98\n88\n98\n98\n88\n98\n98\n88",
"output": "NO"
},
{
"input": "100\n50\n1\n1\n50\n50\n50\n50\n1\n50\n100\n50\n50\n50\n100\n1\n100\n1\n100\n50\n50\n50\n50\n50\n1\n50\n1\n100\n1\n1\n50\n100\n50\n50\n100\n50\n50\n100\n1\n50\n50\n100\n1\n1\n50\n1\n100\n50\n50\n100\n100\n1\n100\n1\n50\n100\n50\n50\n1\n1\n50\n100\n50\n100\n100\n100\n50\n50\n1\n1\n50\n100\n1\n50\n100\n100\n1\n50\n50\n50\n100\n50\n50\n100\n1\n50\n50\n50\n50\n1\n50\n50\n50\n50\n1\n50\n50\n100\n1\n50\n100",
"output": "NO"
},
{
"input": "100\n45\n45\n45\n45\n45\n45\n44\n44\n44\n43\n45\n44\n44\n45\n44\n44\n45\n44\n43\n44\n43\n43\n43\n45\n43\n45\n44\n45\n43\n44\n45\n45\n45\n45\n45\n45\n45\n45\n43\n45\n43\n43\n45\n44\n45\n45\n45\n44\n45\n45\n45\n45\n45\n45\n44\n43\n45\n45\n43\n44\n45\n45\n45\n45\n44\n45\n45\n45\n43\n43\n44\n44\n43\n45\n43\n45\n45\n45\n44\n44\n43\n43\n44\n44\n44\n43\n45\n43\n44\n43\n45\n43\n43\n45\n45\n44\n45\n43\n43\n45",
"output": "NO"
},
{
"input": "100\n12\n12\n97\n15\n97\n12\n15\n97\n12\n97\n12\n12\n97\n12\n15\n12\n12\n15\n12\n12\n97\n12\n12\n15\n15\n12\n97\n15\n12\n97\n15\n12\n12\n15\n15\n15\n97\n15\n97\n12\n12\n12\n12\n12\n97\n12\n97\n12\n15\n15\n12\n15\n12\n15\n12\n12\n12\n12\n12\n12\n12\n12\n97\n97\n12\n12\n97\n12\n97\n97\n15\n97\n12\n97\n97\n12\n12\n12\n97\n97\n15\n12\n12\n15\n12\n15\n97\n97\n12\n15\n12\n12\n97\n12\n15\n15\n15\n15\n12\n12",
"output": "NO"
},
{
"input": "12\n2\n3\n1\n3\n3\n1\n2\n1\n2\n1\n3\n2",
"output": "NO"
},
{
"input": "48\n99\n98\n100\n100\n99\n100\n99\n100\n100\n98\n99\n98\n98\n99\n98\n99\n98\n100\n100\n98\n100\n98\n99\n100\n98\n99\n98\n99\n99\n100\n98\n99\n99\n98\n100\n99\n98\n99\n98\n100\n100\n100\n99\n98\n99\n98\n100\n100",
"output": "NO"
},
{
"input": "4\n1\n3\n3\n3",
"output": "NO"
},
{
"input": "6\n1\n1\n1\n1\n2\n2",
"output": "NO"
},
{
"input": "4\n1\n1\n1\n2",
"output": "NO"
},
{
"input": "4\n1\n2\n2\n2",
"output": "NO"
},
{
"input": "4\n1\n2\n3\n4",
"output": "NO"
},
{
"input": "8\n1\n1\n2\n2\n3\n3\n4\n4",
"output": "NO"
},
{
"input": "4\n1\n3\n2\n4",
"output": "NO"
},
{
"input": "4\n10\n10\n10\n20",
"output": "NO"
},
{
"input": "4\n11\n12\n13\n13",
"output": "NO"
},
{
"input": "4\n1\n1\n1\n3",
"output": "NO"
},
{
"input": "6\n1\n1\n2\n2\n2\n2",
"output": "NO"
},
{
"input": "10\n1\n1\n2\n2\n2\n3\n3\n4\n4\n4",
"output": "NO"
}
] | 1,507,734,911 | 911 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | read = lambda: tuple(map(int, input().split()))
n = read()[0]
arr = sorted([read()[0] for i in range(n)])
arrN = []
c = -1
k = 0
for el in arr:
if el != c:
arrN += [[k, c]]
c = el
k = 0
k += 1
arrN += [[k, c]]
arrN = arrN[1:]
if len(arrN) != 2: print("NO")
elif arrN[0][0] == arrN[1][0]: print("YES")
else: print("NO")
| Title: Fair Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written.
The game is considered fair if Petya and Vasya can take all *n* cards, and the number of cards each player gets is the same.
Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number.
The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards.
Output Specification:
If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more.
In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them.
Demo Input:
['4\n11\n27\n27\n11\n', '2\n6\n6\n', '6\n10\n20\n30\n20\n10\n20\n', '6\n1\n1\n2\n2\n3\n3\n']
Demo Output:
['YES\n11 27\n', 'NO\n', 'NO\n', 'NO\n']
Note:
In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.
In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct.
In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards — for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards. | ```python
read = lambda: tuple(map(int, input().split()))
n = read()[0]
arr = sorted([read()[0] for i in range(n)])
arrN = []
c = -1
k = 0
for el in arr:
if el != c:
arrN += [[k, c]]
c = el
k = 0
k += 1
arrN += [[k, c]]
arrN = arrN[1:]
if len(arrN) != 2: print("NO")
elif arrN[0][0] == arrN[1][0]: print("YES")
else: print("NO")
``` | 0 |
|
725 | B | Food on the Plane | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle.
It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on.
Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one — in seat 'c'. Assume that all seats are occupied.
Vasya has seat *s* in row *n* and wants to know how many seconds will pass before he gets his lunch. | The only line of input contains a description of Vasya's seat in the format *ns*, where *n* (1<=≤<=*n*<=≤<=1018) is the index of the row and *s* is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. | Print one integer — the number of seconds Vasya has to wait until he gets his lunch. | [
"1f\n",
"2d\n",
"4a\n",
"5e\n"
] | [
"1\n",
"10\n",
"11\n",
"18\n"
] | In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.
In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10. | 1,000 | [
{
"input": "1f",
"output": "1"
},
{
"input": "2d",
"output": "10"
},
{
"input": "4a",
"output": "11"
},
{
"input": "5e",
"output": "18"
},
{
"input": "2c",
"output": "13"
},
{
"input": "1b",
"output": "5"
},
{
"input": "1000000000000000000d",
"output": "3999999999999999994"
},
{
"input": "999999999999999997a",
"output": "3999999999999999988"
},
{
"input": "1c",
"output": "6"
},
{
"input": "1d",
"output": "3"
},
{
"input": "1e",
"output": "2"
},
{
"input": "1a",
"output": "4"
},
{
"input": "2a",
"output": "11"
},
{
"input": "2b",
"output": "12"
},
{
"input": "2e",
"output": "9"
},
{
"input": "2f",
"output": "8"
},
{
"input": "3a",
"output": "4"
},
{
"input": "3b",
"output": "5"
},
{
"input": "3c",
"output": "6"
},
{
"input": "3d",
"output": "3"
},
{
"input": "3e",
"output": "2"
},
{
"input": "3f",
"output": "1"
},
{
"input": "4b",
"output": "12"
},
{
"input": "4c",
"output": "13"
},
{
"input": "4d",
"output": "10"
},
{
"input": "4e",
"output": "9"
},
{
"input": "4f",
"output": "8"
},
{
"input": "999999997a",
"output": "3999999988"
},
{
"input": "999999997b",
"output": "3999999989"
},
{
"input": "999999997c",
"output": "3999999990"
},
{
"input": "999999997d",
"output": "3999999987"
},
{
"input": "999999997e",
"output": "3999999986"
},
{
"input": "999999997f",
"output": "3999999985"
},
{
"input": "999999998a",
"output": "3999999995"
},
{
"input": "999999998b",
"output": "3999999996"
},
{
"input": "999999998c",
"output": "3999999997"
},
{
"input": "999999998d",
"output": "3999999994"
},
{
"input": "999999998e",
"output": "3999999993"
},
{
"input": "999999998f",
"output": "3999999992"
},
{
"input": "999999999a",
"output": "3999999988"
},
{
"input": "999999999b",
"output": "3999999989"
},
{
"input": "999999999c",
"output": "3999999990"
},
{
"input": "999999999d",
"output": "3999999987"
},
{
"input": "999999999e",
"output": "3999999986"
},
{
"input": "999999999f",
"output": "3999999985"
},
{
"input": "1000000000a",
"output": "3999999995"
},
{
"input": "1000000000b",
"output": "3999999996"
},
{
"input": "1000000000c",
"output": "3999999997"
},
{
"input": "1000000000d",
"output": "3999999994"
},
{
"input": "1000000000e",
"output": "3999999993"
},
{
"input": "1000000000f",
"output": "3999999992"
},
{
"input": "100000b",
"output": "399996"
},
{
"input": "100000f",
"output": "399992"
},
{
"input": "100001d",
"output": "400003"
},
{
"input": "100001e",
"output": "400002"
},
{
"input": "100001f",
"output": "400001"
},
{
"input": "100002a",
"output": "400011"
},
{
"input": "100002b",
"output": "400012"
},
{
"input": "100002d",
"output": "400010"
},
{
"input": "1231273a",
"output": "4925092"
},
{
"input": "82784f",
"output": "331128"
},
{
"input": "88312c",
"output": "353245"
},
{
"input": "891237e",
"output": "3564946"
},
{
"input": "999999999999999997b",
"output": "3999999999999999989"
},
{
"input": "999999999999999997c",
"output": "3999999999999999990"
},
{
"input": "999999999999999997d",
"output": "3999999999999999987"
},
{
"input": "999999999999999997e",
"output": "3999999999999999986"
},
{
"input": "999999999999999997f",
"output": "3999999999999999985"
},
{
"input": "999999999999999998a",
"output": "3999999999999999995"
},
{
"input": "999999999999999998b",
"output": "3999999999999999996"
},
{
"input": "999999999999999998c",
"output": "3999999999999999997"
},
{
"input": "999999999999999998d",
"output": "3999999999999999994"
},
{
"input": "999999999999999998e",
"output": "3999999999999999993"
},
{
"input": "999999999999999998f",
"output": "3999999999999999992"
},
{
"input": "999999999999999999a",
"output": "3999999999999999988"
},
{
"input": "999999999999999999b",
"output": "3999999999999999989"
},
{
"input": "999999999999999999c",
"output": "3999999999999999990"
},
{
"input": "999999999999999999d",
"output": "3999999999999999987"
},
{
"input": "1000000000000000000a",
"output": "3999999999999999995"
},
{
"input": "1000000000000000000e",
"output": "3999999999999999993"
},
{
"input": "1000000000000000000f",
"output": "3999999999999999992"
},
{
"input": "1000000000000000000c",
"output": "3999999999999999997"
},
{
"input": "97a",
"output": "388"
},
{
"input": "6f",
"output": "24"
},
{
"input": "7f",
"output": "17"
},
{
"input": "7e",
"output": "18"
},
{
"input": "999999999999999992c",
"output": "3999999999999999965"
},
{
"input": "7a",
"output": "20"
},
{
"input": "8f",
"output": "24"
},
{
"input": "999999999999999992a",
"output": "3999999999999999963"
},
{
"input": "999999999999999992b",
"output": "3999999999999999964"
},
{
"input": "999999999999999992c",
"output": "3999999999999999965"
},
{
"input": "999999999999999992d",
"output": "3999999999999999962"
},
{
"input": "999999999999999992e",
"output": "3999999999999999961"
},
{
"input": "999999999999999992f",
"output": "3999999999999999960"
},
{
"input": "999999999999999993a",
"output": "3999999999999999972"
},
{
"input": "999999999999999993b",
"output": "3999999999999999973"
},
{
"input": "999999999999999993c",
"output": "3999999999999999974"
},
{
"input": "999999999999999993d",
"output": "3999999999999999971"
},
{
"input": "999999999999999993e",
"output": "3999999999999999970"
},
{
"input": "999999999999999993f",
"output": "3999999999999999969"
},
{
"input": "999999999999999994a",
"output": "3999999999999999979"
},
{
"input": "999999999999999994b",
"output": "3999999999999999980"
},
{
"input": "999999999999999994c",
"output": "3999999999999999981"
},
{
"input": "999999999999999994d",
"output": "3999999999999999978"
},
{
"input": "999999999999999994e",
"output": "3999999999999999977"
},
{
"input": "999999999999999994f",
"output": "3999999999999999976"
},
{
"input": "999999999999999995a",
"output": "3999999999999999972"
},
{
"input": "999999999999999995b",
"output": "3999999999999999973"
},
{
"input": "999999999999999995c",
"output": "3999999999999999974"
},
{
"input": "999999999999999995d",
"output": "3999999999999999971"
},
{
"input": "999999999999999995e",
"output": "3999999999999999970"
},
{
"input": "999999999999999995f",
"output": "3999999999999999969"
},
{
"input": "10a",
"output": "43"
},
{
"input": "11f",
"output": "33"
},
{
"input": "681572647b",
"output": "2726290581"
},
{
"input": "23f",
"output": "81"
},
{
"input": "123a",
"output": "484"
},
{
"input": "999999888888777777a",
"output": "3999999555555111108"
}
] | 1,610,378,357 | 2,147,483,647 | Python 3 | OK | TESTS | 119 | 77 | 0 | c=input();n,s,d=int(c[:-1]),c[-1],{'a':4,'b':5,'c':6,'d':3,'e':2,'f':1}
x=(n//4*2+(n-1)%2-2*(n%4==0))*6+d[s]+n
print(x-1 if (n-1)%4<2 else x-3) | Title: Food on the Plane
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle.
It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on.
Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one — in seat 'c'. Assume that all seats are occupied.
Vasya has seat *s* in row *n* and wants to know how many seconds will pass before he gets his lunch.
Input Specification:
The only line of input contains a description of Vasya's seat in the format *ns*, where *n* (1<=≤<=*n*<=≤<=1018) is the index of the row and *s* is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space.
Output Specification:
Print one integer — the number of seconds Vasya has to wait until he gets his lunch.
Demo Input:
['1f\n', '2d\n', '4a\n', '5e\n']
Demo Output:
['1\n', '10\n', '11\n', '18\n']
Note:
In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.
In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10. | ```python
c=input();n,s,d=int(c[:-1]),c[-1],{'a':4,'b':5,'c':6,'d':3,'e':2,'f':1}
x=(n//4*2+(n-1)%2-2*(n%4==0))*6+d[s]+n
print(x-1 if (n-1)%4<2 else x-3)
``` | 3 |
|
574 | A | Bear and Elections | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.
There are *n* candidates, including Limak. We know how many citizens are going to vote for each candidate. Now *i*-th candidate would get *a**i* votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate.
Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? | The first line contains single integer *n* (2<=≤<=*n*<=≤<=100) - number of candidates.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) - number of votes for each candidate. Limak is candidate number 1.
Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. | Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. | [
"5\n5 1 11 2 8\n",
"4\n1 8 8 8\n",
"2\n7 6\n"
] | [
"4\n",
"6\n",
"0\n"
] | In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8.
In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6.
In the third sample Limak is a winner without bribing any citizen. | 500 | [
{
"input": "5\n5 1 11 2 8",
"output": "4"
},
{
"input": "4\n1 8 8 8",
"output": "6"
},
{
"input": "2\n7 6",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "10\n100 200 57 99 1 1000 200 200 200 500",
"output": "451"
},
{
"input": "16\n7 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "932"
},
{
"input": "100\n47 64 68 61 68 66 69 61 69 65 69 63 62 60 68 65 64 65 65 62 63 68 60 70 63 63 65 67 70 69 68 69 61 65 63 60 60 65 61 60 70 66 66 65 62 60 65 68 61 62 67 64 66 65 67 68 60 69 70 63 65 62 64 65 67 67 69 68 66 69 70 67 65 70 60 66 70 67 67 64 69 69 66 68 60 64 62 62 68 69 67 69 60 70 69 68 62 63 68 66",
"output": "23"
},
{
"input": "2\n96 97",
"output": "1"
},
{
"input": "2\n1000 1000",
"output": "1"
},
{
"input": "3\n999 1000 1000",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "2"
},
{
"input": "7\n10 940 926 990 946 980 985",
"output": "817"
},
{
"input": "10\n5 3 4 5 5 2 1 8 4 1",
"output": "2"
},
{
"input": "15\n17 15 17 16 13 17 13 16 14 14 17 17 13 15 17",
"output": "1"
},
{
"input": "20\n90 5 62 9 50 7 14 43 44 44 56 13 71 22 43 35 52 60 73 54",
"output": "0"
},
{
"input": "30\n27 85 49 7 77 38 4 68 23 28 81 100 40 9 78 38 1 60 60 49 98 44 45 92 46 39 98 24 37 39",
"output": "58"
},
{
"input": "51\n90 47 100 12 21 96 2 68 84 60 2 9 33 8 45 13 59 50 100 93 22 97 4 81 51 2 3 78 19 16 25 63 52 34 79 32 34 87 7 42 96 93 30 33 33 43 69 8 63 58 57",
"output": "8"
},
{
"input": "77\n1000 2 2 3 1 1 1 3 3 2 1 1 3 2 2 2 3 2 3 1 3 1 1 2 2 2 3 1 1 2 2 2 3 2 1 3 3 1 2 3 3 3 2 1 3 2 1 3 3 2 3 3 2 1 3 1 1 1 2 3 2 3 1 3 1 2 1 2 2 2 1 2 2 3 2 2 2",
"output": "0"
},
{
"input": "91\n3 92 89 83 85 80 91 94 95 82 92 95 80 88 90 85 81 90 87 86 94 88 90 87 88 82 95 84 84 93 83 95 91 85 89 88 88 85 87 90 93 80 89 95 94 92 93 86 83 82 86 84 91 80 90 95 84 86 84 85 84 92 82 84 83 91 87 95 94 95 90 95 86 92 86 80 95 86 88 80 82 87 84 83 91 93 81 81 91 89 88",
"output": "89"
},
{
"input": "100\n1 3 71 47 64 82 58 61 61 35 52 36 57 62 63 54 52 21 78 100 24 94 4 80 99 62 43 72 21 70 90 4 23 14 72 4 76 49 71 96 96 99 78 7 32 11 14 61 19 69 1 68 100 77 86 54 14 86 47 53 30 88 67 66 61 70 17 63 40 5 99 53 38 31 91 18 41 5 77 61 53 30 87 21 23 54 52 17 23 75 58 99 99 63 20 1 78 72 28 11",
"output": "90"
},
{
"input": "100\n1 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "99"
},
{
"input": "94\n3 100 100 99 99 99 100 99 99 99 99 99 100 99 100 100 99 100 99 99 100 99 100 99 100 100 100 99 100 99 100 99 100 99 99 99 100 99 99 99 99 99 100 99 100 100 99 100 99 99 99 99 100 99 100 99 99 99 100 100 99 100 100 99 99 100 100 100 99 100 99 99 99 99 99 100 100 100 100 100 100 100 100 100 99 99 99 99 100 99 100 99 100 100",
"output": "97"
},
{
"input": "97\n99 99 98 98 100 98 99 99 98 100 100 100 99 99 100 99 99 98 99 99 98 98 98 100 100 99 98 99 100 98 99 98 98 100 98 99 100 98 98 99 98 98 99 98 100 99 99 99 99 98 98 98 100 99 100 100 99 99 100 99 99 98 98 98 100 100 98 100 100 99 98 99 100 98 98 98 98 99 99 98 98 99 100 100 98 98 99 98 99 100 98 99 100 98 99 99 100",
"output": "2"
},
{
"input": "100\n100 55 70 81 73 51 6 75 45 85 33 61 98 63 11 59 1 8 14 28 78 74 44 80 7 69 7 5 90 73 43 78 64 64 43 92 59 70 80 19 33 39 31 70 38 85 24 23 86 79 98 56 92 63 92 4 36 8 79 74 2 81 54 13 69 44 49 63 17 76 78 99 42 36 47 71 19 90 9 58 83 53 27 2 35 51 65 59 90 51 74 87 84 48 98 44 84 100 84 93",
"output": "1"
},
{
"input": "100\n100 637 498 246 615 901 724 673 793 33 282 908 477 185 185 969 34 859 90 70 107 492 227 918 919 131 620 182 802 703 779 184 403 891 448 499 628 553 905 392 70 396 8 575 66 908 992 496 792 174 667 355 836 610 855 377 244 827 836 808 667 354 800 114 746 556 75 894 162 367 99 718 394 273 833 776 151 433 315 470 759 12 552 613 85 793 775 649 225 86 296 624 557 201 209 595 697 527 282 168",
"output": "749"
},
{
"input": "100\n107 172 549 883 564 56 399 970 173 990 224 217 601 381 948 631 159 958 512 136 61 584 633 202 652 355 26 723 663 237 410 721 688 552 699 24 748 186 461 88 34 243 872 205 471 298 654 693 244 33 359 533 471 116 386 653 654 887 531 303 335 829 319 340 827 89 602 191 422 289 361 200 593 421 592 402 256 813 606 589 741 9 148 893 3 142 50 169 219 360 642 45 810 818 507 624 561 743 303 111",
"output": "729"
},
{
"input": "90\n670 694 651 729 579 539 568 551 707 638 604 544 502 531 775 805 558 655 506 729 802 778 653 737 591 770 594 535 588 604 658 713 779 705 504 563 513 651 529 572 505 553 515 750 621 574 727 774 714 725 665 798 670 747 751 635 755 798 635 717 583 682 517 546 740 802 743 507 658 700 645 671 533 594 506 633 768 584 672 666 703 522 530 501 592 528 678 708 619 786",
"output": "111"
},
{
"input": "90\n10 265 429 431 343 305 806 746 284 313 503 221 594 351 83 653 232 431 427 610 458 88 255 215 529 205 492 549 55 694 535 104 45 327 816 432 595 549 454 141 216 557 250 415 531 494 190 749 718 380 78 447 784 347 196 814 16 780 262 462 776 315 160 307 593 694 692 41 528 725 376 777 337 44 438 630 345 502 384 184 742 429 570 361 394 267 820 778 662 377",
"output": "714"
},
{
"input": "95\n800 280 176 472 587 763 588 838 760 378 667 231 566 278 713 305 354 815 140 220 188 409 109 180 251 268 474 590 853 143 235 691 313 785 386 92 783 471 43 342 718 592 678 404 256 362 239 504 163 85 521 81 356 73 754 589 380 159 196 862 838 509 149 42 366 630 467 292 698 123 187 796 576 37 689 800 186 518 488 432 159 860 349 799 282 304 880 283 23 312 55 507 734 370 490",
"output": "52"
},
{
"input": "100\n95 88 84 85 74 97 100 52 91 94 62 66 90 56 86 66 95 73 79 68 54 67 99 52 82 62 81 71 93 85 72 72 95 52 72 63 57 90 92 89 88 77 84 78 95 59 72 86 98 64 89 64 80 70 54 93 88 86 79 78 94 64 89 66 50 90 54 82 52 96 99 54 81 66 83 79 69 80 51 73 81 69 93 82 76 52 58 87 93 92 52 67 78 63 63 87 77 95 58 78",
"output": "4"
},
{
"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": "1"
},
{
"input": "100\n999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 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": "2"
},
{
"input": "100\n901 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 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": "99"
},
{
"input": "4\n8 5 11 3",
"output": "2"
},
{
"input": "3\n3 10 1",
"output": "4"
}
] | 1,665,167,303 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 62 | 1,740,800 | n=int(input())
arr=list(map(int,input().split()))
t=ans=arr.pop(0)
mx=max(arr)
i=1
while (ans)<=mx:
ans+=1
arr.remove(mx)
arr.append(mx-1)
mx=max(arr)
print(ans-t) | Title: Bear and Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.
There are *n* candidates, including Limak. We know how many citizens are going to vote for each candidate. Now *i*-th candidate would get *a**i* votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate.
Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe?
Input Specification:
The first line contains single integer *n* (2<=≤<=*n*<=≤<=100) - number of candidates.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) - number of votes for each candidate. Limak is candidate number 1.
Note that after bribing number of votes for some candidate might be zero or might be greater than 1000.
Output Specification:
Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate.
Demo Input:
['5\n5 1 11 2 8\n', '4\n1 8 8 8\n', '2\n7 6\n']
Demo Output:
['4\n', '6\n', '0\n']
Note:
In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8.
In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6.
In the third sample Limak is a winner without bribing any citizen. | ```python
n=int(input())
arr=list(map(int,input().split()))
t=ans=arr.pop(0)
mx=max(arr)
i=1
while (ans)<=mx:
ans+=1
arr.remove(mx)
arr.append(mx-1)
mx=max(arr)
print(ans-t)
``` | 3 |
|
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,682,919,323 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | liV = int(input())
ChaList = []
liIn = 0
while liIn < liV:
ChaList.append(input())
liIn = liIn+1
for j in ChaList:
if len(j) <= 10:
print (j)
else:
jl = len(j)-2
print(print (j[0] + str(jl)+j[-1])) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
liV = int(input())
ChaList = []
liIn = 0
while liIn < liV:
ChaList.append(input())
liIn = liIn+1
for j in ChaList:
if len(j) <= 10:
print (j)
else:
jl = len(j)-2
print(print (j[0] + str(jl)+j[-1]))
``` | 0 |
233 | A | Perfect Permutation | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*. | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. | If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. | [
"1\n",
"2\n",
"4\n"
] | [
"-1\n",
"2 1 \n",
"2 1 4 3 \n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "7",
"output": "-1"
},
{
"input": "20",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 "
},
{
"input": "8",
"output": "2 1 4 3 6 5 8 7 "
},
{
"input": "9",
"output": "-1"
},
{
"input": "10",
"output": "2 1 4 3 6 5 8 7 10 9 "
},
{
"input": "11",
"output": "-1"
},
{
"input": "21",
"output": "-1"
},
{
"input": "50",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 "
},
{
"input": "51",
"output": "-1"
},
{
"input": "52",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 "
},
{
"input": "84",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 "
},
{
"input": "86",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 "
},
{
"input": "100",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 "
},
{
"input": "98",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 "
},
{
"input": "96",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 "
},
{
"input": "33",
"output": "-1"
},
{
"input": "34",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 "
},
{
"input": "36",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 "
},
{
"input": "38",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 "
},
{
"input": "40",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 "
},
{
"input": "42",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 "
},
{
"input": "44",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 "
},
{
"input": "46",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 "
},
{
"input": "48",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 "
}
] | 1,651,080,682 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | #PAR-> 2,1,4,3,6,5,...
#IMPAR-> ...,5,4,3,2,1
N=int(input())
if(N==1):
print(-1)
elif(N%2==0):
Cad=""
for K in range(2,N+1,2):
Cad=Cad+str(K)+" "+str(K-1)+" "
print(Cad[:len(Cad)-1])
else:
Cad=""
for K in range(N,0,-1):
Cad=Cad+str(K)+" "
print(Cad[:len(Cad)-1])
| Title: Perfect Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≤<=*i*<=≤<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=≠<=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*.
Input Specification:
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
Output Specification:
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
Demo Input:
['1\n', '2\n', '4\n']
Demo Output:
['-1\n', '2 1 \n', '2 1 4 3 \n']
Note:
none | ```python
#PAR-> 2,1,4,3,6,5,...
#IMPAR-> ...,5,4,3,2,1
N=int(input())
if(N==1):
print(-1)
elif(N%2==0):
Cad=""
for K in range(2,N+1,2):
Cad=Cad+str(K)+" "+str(K-1)+" "
print(Cad[:len(Cad)-1])
else:
Cad=""
for K in range(N,0,-1):
Cad=Cad+str(K)+" "
print(Cad[:len(Cad)-1])
``` | 0 |
|
192 | A | Funky Numbers | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"implementation"
] | null | null | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)! | The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). | Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). | [
"256\n",
"512\n"
] | [
"YES\n",
"NO\n"
] | In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | 500 | [
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "NO"
},
{
"input": "80",
"output": "NO"
},
{
"input": "828",
"output": "YES"
},
{
"input": "6035",
"output": "NO"
},
{
"input": "39210",
"output": "YES"
},
{
"input": "79712",
"output": "NO"
},
{
"input": "190492",
"output": "YES"
},
{
"input": "5722367",
"output": "NO"
},
{
"input": "816761542",
"output": "YES"
},
{
"input": "1",
"output": "NO"
},
{
"input": "2",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "YES"
},
{
"input": "8",
"output": "NO"
},
{
"input": "9",
"output": "YES"
},
{
"input": "10",
"output": "NO"
},
{
"input": "12",
"output": "YES"
},
{
"input": "13",
"output": "YES"
},
{
"input": "14",
"output": "NO"
},
{
"input": "15",
"output": "NO"
},
{
"input": "16",
"output": "YES"
},
{
"input": "17",
"output": "NO"
},
{
"input": "18",
"output": "YES"
},
{
"input": "19",
"output": "NO"
},
{
"input": "20",
"output": "YES"
},
{
"input": "41",
"output": "NO"
},
{
"input": "11",
"output": "YES"
},
{
"input": "69",
"output": "YES"
},
{
"input": "82",
"output": "NO"
},
{
"input": "85",
"output": "NO"
},
{
"input": "736",
"output": "NO"
},
{
"input": "895",
"output": "YES"
},
{
"input": "934",
"output": "YES"
},
{
"input": "6213",
"output": "YES"
},
{
"input": "7405",
"output": "NO"
},
{
"input": "9919",
"output": "NO"
},
{
"input": "40942",
"output": "YES"
},
{
"input": "41992",
"output": "NO"
},
{
"input": "68535",
"output": "NO"
},
{
"input": "405718",
"output": "NO"
},
{
"input": "1046146",
"output": "YES"
},
{
"input": "3761248",
"output": "YES"
},
{
"input": "6195181",
"output": "YES"
},
{
"input": "35354345",
"output": "NO"
},
{
"input": "81282830",
"output": "NO"
},
{
"input": "187719774",
"output": "NO"
},
{
"input": "296798673",
"output": "NO"
},
{
"input": "938938476",
"output": "NO"
},
{
"input": "1000000000",
"output": "NO"
},
{
"input": "999887464",
"output": "YES"
},
{
"input": "999111944",
"output": "NO"
},
{
"input": "999966520",
"output": "YES"
},
{
"input": "999912080",
"output": "NO"
},
{
"input": "999992017",
"output": "YES"
},
{
"input": "999990474",
"output": "NO"
},
{
"input": "999999190",
"output": "YES"
},
{
"input": "999999125",
"output": "NO"
},
{
"input": "999999940",
"output": "YES"
},
{
"input": "999999995",
"output": "NO"
},
{
"input": "1000000000",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "999999999",
"output": "YES"
},
{
"input": "83495494",
"output": "NO"
},
{
"input": "968022000",
"output": "YES"
},
{
"input": "399980000",
"output": "YES"
},
{
"input": "4",
"output": "YES"
},
{
"input": "999999998",
"output": "NO"
}
] | 1,698,518,325 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | v=input()
v1=int(v)
vv=[]
v2=int(v[-1])
for i in range(2,v2):
if v2%i==0 and v2//i != 0:
vv.append(i)
if len(vv) >= 2:
q1, q2 = vv[0], vv[1]
x1 = (q1 * q2) // 2
x2 = ((q1 * 11) * (q1 * 11 + 1)) // 2
if x1 + x2 == v1:
print("YES")
else:
print("NO")
else:
print("NO")
| Title: Funky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
Input Specification:
The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109).
Output Specification:
Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
Demo Input:
['256\n', '512\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | ```python
v=input()
v1=int(v)
vv=[]
v2=int(v[-1])
for i in range(2,v2):
if v2%i==0 and v2//i != 0:
vv.append(i)
if len(vv) >= 2:
q1, q2 = vv[0], vv[1]
x1 = (q1 * q2) // 2
x2 = ((q1 * 11) * (q1 * 11 + 1)) // 2
if x1 + x2 == v1:
print("YES")
else:
print("NO")
else:
print("NO")
``` | 0 |
|
266 | A | Stones on the Table | PROGRAMMING | 800 | [
"implementation"
] | null | null | There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue. | Print a single integer — the answer to the problem. | [
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] | [
"1\n",
"4\n",
"0\n"
] | none | 500 | [
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "4\nRBBR",
"output": "1"
},
{
"input": "5\nRGGBG",
"output": "1"
},
{
"input": "10\nGGBRBRGGRB",
"output": "2"
},
{
"input": "50\nGRBGGRBRGRBGGBBBBBGGGBBBBRBRGBRRBRGBBBRBBRRGBGGGRB",
"output": "18"
},
{
"input": "15\nBRRBRGGBBRRRRGR",
"output": "6"
},
{
"input": "20\nRRGBBRBRGRGBBGGRGRRR",
"output": "6"
},
{
"input": "25\nBBGBGRBGGBRRBGRRBGGBBRBRB",
"output": "6"
},
{
"input": "30\nGRGGGBGGRGBGGRGRBGBGBRRRRRRGRB",
"output": "9"
},
{
"input": "35\nGBBGBRGBBGGRBBGBRRGGRRRRRRRBRBBRRGB",
"output": "14"
},
{
"input": "40\nGBBRRGBGGGRGGGRRRRBRBGGBBGGGBGBBBBBRGGGG",
"output": "20"
},
{
"input": "45\nGGGBBRBBRRGRBBGGBGRBRGGBRBRGBRRGBGRRBGRGRBRRG",
"output": "11"
},
{
"input": "50\nRBGGBGGRBGRBBBGBBGRBBBGGGRBBBGBBBGRGGBGGBRBGBGRRGG",
"output": "17"
},
{
"input": "50\nGGGBBRGGGGGRRGGRBGGRGBBRBRRBGRGBBBGBRBGRGBBGRGGBRB",
"output": "16"
},
{
"input": "50\nGBGRGRRBRRRRRGGBBGBRRRBBBRBBBRRGRBBRGBRBGGRGRBBGGG",
"output": "19"
},
{
"input": "10\nGRRBRBRBGR",
"output": "1"
},
{
"input": "10\nBRBGBGRRBR",
"output": "1"
},
{
"input": "20\nGBGBGGRRRRGRBBGRGRGR",
"output": "5"
},
{
"input": "20\nRRGGRBBGBBRBGRRBRRBG",
"output": "6"
},
{
"input": "30\nBGBRGBBBGRGBBRGBGRBBBRGGRRGRRB",
"output": "8"
},
{
"input": "30\nBBBBGGBRBGBBGBGBGBGGGRGRRGGBBB",
"output": "11"
},
{
"input": "40\nGBRRGRBGBRRGBRGGGBRGBGBRGBBRRGRGGBBGBGBB",
"output": "9"
},
{
"input": "40\nBRGRGGRGGRBBRRRBRBBGGGRRGBGBBGRBBRGBRRGG",
"output": "13"
},
{
"input": "50\nRBGBGGRRGGRGGBGBGRRBGGBGBRRBBGBBGBBBGBBRBBRBRBRGRG",
"output": "13"
},
{
"input": "50\nRBRRGBGRRRBGRRBGRRGRBBRBBRRBRGGBRBRRBGGRBGGBRBRGRB",
"output": "12"
},
{
"input": "2\nBB",
"output": "1"
},
{
"input": "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "49"
},
{
"input": "50\nRRRRRRRRGRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "47"
},
{
"input": "50\nRRRRRRRRRRRRGGRRRRRRRRRBRRRRRRRRRRRRRRBBRRRRRRRRRR",
"output": "43"
}
] | 1,695,229,318 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | n = input()
n = int(n)
stones = input()
ans = 0
for i in range(1, n):
if stones[i] == stones[i-1]:
ans = ans + 1
print(ans)
| Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['3\nRRG\n', '5\nRRRRR\n', '4\nBRBG\n']
Demo Output:
['1\n', '4\n', '0\n']
Note:
none | ```python
n = input()
n = int(n)
stones = input()
ans = 0
for i in range(1, n):
if stones[i] == stones[i-1]:
ans = ans + 1
print(ans)
``` | 3 |
|
792 | B | Counting-out Rhyme | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | *n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In the *i*-th step the leader counts out *a**i* people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader.
For example, if there are children with numbers [8,<=10,<=13,<=14,<=16] currently in the circle, the leader is child 13 and *a**i*<==<=12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader.
You have to write a program which prints the number of the child to be eliminated on every step. | The first line contains two integer numbers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1).
The next line contains *k* integer numbers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=109). | Print *k* numbers, the *i*-th one corresponds to the number of child to be eliminated at the *i*-th step. | [
"7 5\n10 4 11 4 1\n",
"3 2\n2 5\n"
] | [
"4 2 5 6 1 \n",
"3 2 \n"
] | Let's consider first example:
- In the first step child 4 is eliminated, child 5 becomes the leader. - In the second step child 2 is eliminated, child 3 becomes the leader. - In the third step child 5 is eliminated, child 6 becomes the leader. - In the fourth step child 6 is eliminated, child 7 becomes the leader. - In the final step child 1 is eliminated, child 3 becomes the leader. | 0 | [
{
"input": "7 5\n10 4 11 4 1",
"output": "4 2 5 6 1 "
},
{
"input": "3 2\n2 5",
"output": "3 2 "
},
{
"input": "2 1\n1",
"output": "2 "
},
{
"input": "2 1\n2",
"output": "1 "
},
{
"input": "2 1\n3",
"output": "2 "
},
{
"input": "10 7\n5 10 4 3 8 10 6",
"output": "6 8 3 9 2 4 10 "
},
{
"input": "10 8\n12 6 12 15 20 8 17 12",
"output": "3 10 6 8 2 9 4 5 "
},
{
"input": "12 10\n76 58 82 54 97 46 17 40 36 15",
"output": "5 9 12 1 3 10 8 11 2 4 "
},
{
"input": "12 6\n76 61 94 15 66 26",
"output": "5 12 6 2 7 3 "
},
{
"input": "90 10\n1045 8705 6077 3282 1459 9809 383 6206 2674 7274",
"output": "56 39 45 20 17 55 14 85 51 33 "
},
{
"input": "100 30\n601771 913885 829106 91674 465657 367068 142461 873149 294276 916519 720701 370006 551782 321506 68525 570684 81178 724855 564907 661130 10112 983124 799801 100639 766045 862312 513021 232094 979480 408554",
"output": "72 89 16 26 85 73 29 99 63 30 8 46 70 19 100 93 36 54 65 77 17 79 62 64 21 69 42 82 68 1 "
},
{
"input": "3 2\n20148340 81473314",
"output": "2 3 "
},
{
"input": "3 2\n301633543 643389490",
"output": "2 3 "
},
{
"input": "6 5\n532623340 628883728 583960589 690950241 488468353",
"output": "5 3 6 1 4 "
},
{
"input": "6 2\n458995521 294343587",
"output": "4 1 "
},
{
"input": "68 1\n5",
"output": "6 "
}
] | 1,637,303,391 | 291 | PyPy 3-64 | OK | TESTS | 22 | 62 | 0 | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
l = sorted(list(range(1, n+1)))
c = 0
t = []
for i in [int(j) for j in input().split()]:
c = (c+i)%len(l)
t.append(l[c])
l = l[:c]+l[c+1:]
print(*t)
| Title: Counting-out Rhyme
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In the *i*-th step the leader counts out *a**i* people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader.
For example, if there are children with numbers [8,<=10,<=13,<=14,<=16] currently in the circle, the leader is child 13 and *a**i*<==<=12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader.
You have to write a program which prints the number of the child to be eliminated on every step.
Input Specification:
The first line contains two integer numbers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1).
The next line contains *k* integer numbers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print *k* numbers, the *i*-th one corresponds to the number of child to be eliminated at the *i*-th step.
Demo Input:
['7 5\n10 4 11 4 1\n', '3 2\n2 5\n']
Demo Output:
['4 2 5 6 1 \n', '3 2 \n']
Note:
Let's consider first example:
- In the first step child 4 is eliminated, child 5 becomes the leader. - In the second step child 2 is eliminated, child 3 becomes the leader. - In the third step child 5 is eliminated, child 6 becomes the leader. - In the fourth step child 6 is eliminated, child 7 becomes the leader. - In the final step child 1 is eliminated, child 3 becomes the leader. | ```python
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
l = sorted(list(range(1, n+1)))
c = 0
t = []
for i in [int(j) for j in input().split()]:
c = (c+i)%len(l)
t.append(l[c])
l = l[:c]+l[c+1:]
print(*t)
``` | 3 |