message stringlengths 2 23.4k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 129 108k | cluster float64 6 6 | __index_level_0__ int64 258 216k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words.
To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u".
Three phases from a certain poem are given. Determine whether it is haiku or not.
Input
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The i-th line contains the i-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification.
Output
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
Examples
Input
on codeforces
beta round is running
a rustling of keys
Output
YES
Input
how many gallons
of edo s rain did you drink
cuckoo
Output
NO | instruction | 0 | 24,385 | 6 | 48,770 |
Tags: implementation, strings
Correct Solution:
```
a,b,c=input(),input(),input()
def cnt(s):
ans=0
for e in s:
ans+= e in "aeiou"
return ans
print("YES" if cnt(a)==cnt(c)==5 and cnt(b)==7 else "NO")
``` | output | 1 | 24,385 | 6 | 48,771 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words.
To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u".
Three phases from a certain poem are given. Determine whether it is haiku or not.
Input
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The i-th line contains the i-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification.
Output
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
Examples
Input
on codeforces
beta round is running
a rustling of keys
Output
YES
Input
how many gallons
of edo s rain did you drink
cuckoo
Output
NO | instruction | 0 | 24,386 | 6 | 48,772 |
Tags: implementation, strings
Correct Solution:
```
for i in range(1,4):
s=input()
sum=s.count('a')+s.count('e')+s.count('i')+s.count('o')+s.count('u')
if((i==2 and sum!=7)or(i!=2 and sum!=5)):
exit(print('NO'))
print('YES')
``` | output | 1 | 24,386 | 6 | 48,773 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words.
To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u".
Three phases from a certain poem are given. Determine whether it is haiku or not.
Input
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The i-th line contains the i-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification.
Output
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
Examples
Input
on codeforces
beta round is running
a rustling of keys
Output
YES
Input
how many gallons
of edo s rain did you drink
cuckoo
Output
NO | instruction | 0 | 24,387 | 6 | 48,774 |
Tags: implementation, strings
Correct Solution:
```
a = input()
b = input()
c = input()
def isVowel(c):
return c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u'
def vowelNo(s):
c = 0
for i in s:
if isVowel(i):
c += 1
return c
if vowelNo(a) == 5 and vowelNo(b) == 7 and vowelNo(c) == 5:
print("YES")
else:
print("NO")
``` | output | 1 | 24,387 | 6 | 48,775 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of a-s and others — a group of b-s), but cccc is not since in each possible consequent partition letters in these two groups coincide.
You're given a string s. Check whether it can be split into two non-empty subsequences such that the strings formed by these subsequences are adorable. Here a subsequence is an arbitrary set of indexes of the string.
Input
The only line contains s (1 ≤ |s| ≤ 105) consisting of lowercase latin letters.
Output
Print «Yes» if the string can be split according to the criteria above or «No» otherwise.
Each letter can be printed in arbitrary case.
Examples
Input
ababa
Output
Yes
Input
zzcxx
Output
Yes
Input
yeee
Output
No
Note
In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable.
There's no suitable partition in sample case three. | instruction | 0 | 24,447 | 6 | 48,894 |
Tags: implementation
Correct Solution:
```
st=input()
st=list(st)
flg=0
n=len(set(st))
if n==3:
for i in set(st):
if st.count(i)>=2:
flg=1
break
elif n==2:
for i in set(st):
if st.count(i)==1:
flg=0
break
else:
flg=1
elif n==1 or n>4:
flg=0
elif n==4:
flg=1
if flg==1:
print('Yes')
else:
print('No')
``` | output | 1 | 24,447 | 6 | 48,895 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of a-s and others — a group of b-s), but cccc is not since in each possible consequent partition letters in these two groups coincide.
You're given a string s. Check whether it can be split into two non-empty subsequences such that the strings formed by these subsequences are adorable. Here a subsequence is an arbitrary set of indexes of the string.
Input
The only line contains s (1 ≤ |s| ≤ 105) consisting of lowercase latin letters.
Output
Print «Yes» if the string can be split according to the criteria above or «No» otherwise.
Each letter can be printed in arbitrary case.
Examples
Input
ababa
Output
Yes
Input
zzcxx
Output
Yes
Input
yeee
Output
No
Note
In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable.
There's no suitable partition in sample case three. | instruction | 0 | 24,449 | 6 | 48,898 |
Tags: implementation
Correct Solution:
```
from collections import Counter
def no():
print("No")
exit(0)
s = input()
if len(s) < 4:
no()
cnt = Counter(s)
cnt = list(cnt.items())
if len(cnt) < 2 or len(cnt) > 4:
no()
if len(cnt) == 2 and (cnt[0][1] == 1 or cnt[1][1] == 1):
no()
if len(cnt) == 3 and (max(cnt[0][1], cnt[1][1], cnt[2][1]) == 1):
no()
print("Yes")
``` | output | 1 | 24,449 | 6 | 48,899 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of a-s and others — a group of b-s), but cccc is not since in each possible consequent partition letters in these two groups coincide.
You're given a string s. Check whether it can be split into two non-empty subsequences such that the strings formed by these subsequences are adorable. Here a subsequence is an arbitrary set of indexes of the string.
Input
The only line contains s (1 ≤ |s| ≤ 105) consisting of lowercase latin letters.
Output
Print «Yes» if the string can be split according to the criteria above or «No» otherwise.
Each letter can be printed in arbitrary case.
Examples
Input
ababa
Output
Yes
Input
zzcxx
Output
Yes
Input
yeee
Output
No
Note
In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable.
There's no suitable partition in sample case three. | instruction | 0 | 24,452 | 6 | 48,904 |
Tags: implementation
Correct Solution:
```
import sys
import bisect
#input=sys.stdin.readline
s=input()
hashi=dict()
for i in s:
if(i in hashi):
hashi[i]+=1
else:
hashi[i]=1
z=len(hashi)
if(len(s)<4):
print("No")
quit()
if(z>4):
print("No")
quit()
if(z==1):
print("No")
quit()
rem=0
for i in hashi:
if(hashi[i]>1):
rem+=1
if(rem+z>=4):
print("Yes")
else:
print("No")
``` | output | 1 | 24,452 | 6 | 48,905 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of a-s and others — a group of b-s), but cccc is not since in each possible consequent partition letters in these two groups coincide.
You're given a string s. Check whether it can be split into two non-empty subsequences such that the strings formed by these subsequences are adorable. Here a subsequence is an arbitrary set of indexes of the string.
Input
The only line contains s (1 ≤ |s| ≤ 105) consisting of lowercase latin letters.
Output
Print «Yes» if the string can be split according to the criteria above or «No» otherwise.
Each letter can be printed in arbitrary case.
Examples
Input
ababa
Output
Yes
Input
zzcxx
Output
Yes
Input
yeee
Output
No
Note
In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable.
There's no suitable partition in sample case three. | instruction | 0 | 24,454 | 6 | 48,908 |
Tags: implementation
Correct Solution:
```
import sys
from collections import defaultdict
s = list(input().strip())
n = len(s)
if n < 4:
print("No")
sys.exit(0)
count = defaultdict(int)
for x in s:
count[x] += 1
n = len(count)
if n == 1 or n > 4:
res = "No"
elif n == 4:
res = "Yes"
elif n == 3:
res = "No"
for x in count.values():
if x >=2:
res = "Yes"
else:
res = "Yes"
for x in count.values():
if x < 2:
res = "No"
print(res)
``` | output | 1 | 24,454 | 6 | 48,909 |
Provide a correct Python 3 solution for this coding contest problem.
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.
The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
Input
word page_number
::
::
Output
word
a_list_of_the_page_number
word
a_list_of_the_Page_number
::
::
Example
Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output
document
13
easy
9
even
18 25
introduction
3
style
7 12 21 | instruction | 0 | 24,653 | 6 | 49,306 |
"Correct Solution:
```
d = {}
while True:
try:
w, p = input().split()
if w in d:
d[w].append(int(p))
else:
d[w] = [int(p)]
except:
break
for k in sorted(d.items(), key=lambda x: x[0]):
print(k[0])
print(*sorted(k[1]))
``` | output | 1 | 24,653 | 6 | 49,307 |
Provide a correct Python 3 solution for this coding contest problem.
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.
The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
Input
word page_number
::
::
Output
word
a_list_of_the_page_number
word
a_list_of_the_Page_number
::
::
Example
Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output
document
13
easy
9
even
18 25
introduction
3
style
7 12 21 | instruction | 0 | 24,654 | 6 | 49,308 |
"Correct Solution:
```
Date_lis = []
W_lis = []
while True:
try:
s,n = map(str,input().split())
if s in W_lis:
Date_lis[W_lis.index(s)][1].append(int(n))
else:
Date_lis.append([s,[int(n)]])
W_lis.append(s)
except :
Date_lis = sorted(Date_lis)
for i in range(len(Date_lis)):
print(Date_lis[i][0])
Num = sorted(Date_lis[i][1])
for j in range(len(Date_lis[i][1]) - 1):
print(Num[j],end = " ")
print(Num[len(Date_lis[i][1]) - 1])
break
``` | output | 1 | 24,654 | 6 | 49,309 |
Provide a correct Python 3 solution for this coding contest problem.
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.
The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
Input
word page_number
::
::
Output
word
a_list_of_the_page_number
word
a_list_of_the_Page_number
::
::
Example
Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output
document
13
easy
9
even
18 25
introduction
3
style
7 12 21 | instruction | 0 | 24,655 | 6 | 49,310 |
"Correct Solution:
```
import sys
d={}
for e in sys.stdin:
k,v=e.split()
d.setdefault(k,[])
d[k]+=[int(v)]
for k in sorted(d):
print(k)
print(*sorted(d[k]))
``` | output | 1 | 24,655 | 6 | 49,311 |
Provide a correct Python 3 solution for this coding contest problem.
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.
The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
Input
word page_number
::
::
Output
word
a_list_of_the_page_number
word
a_list_of_the_Page_number
::
::
Example
Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output
document
13
easy
9
even
18 25
introduction
3
style
7 12 21 | instruction | 0 | 24,656 | 6 | 49,312 |
"Correct Solution:
```
def get_input():
while True:
try:
yield ''.join(input())
except EOFError:
break
N = list(get_input())
N.sort()
N1,N2 = N[0].split()
word = N1
pnum = []
pnum.append(int(N2))
for l in range(1, len(N)):
N1,N2 = N[l].split()
if word != N1:
print(word)
pnum.sort()
print(pnum[0], end="")
for i in range(1, len(pnum)):
print(" ", end="")
print(pnum[i], end="")
print("")
word = N1
pnum.clear()
pnum.append(int(N2))
else:
pnum.append(int(N2))
print(word)
pnum.sort()
print(pnum[0], end="")
for i in range(1, len(pnum)):
print(" ", end="")
print(pnum[i], end="")
print("")
``` | output | 1 | 24,656 | 6 | 49,313 |
Provide a correct Python 3 solution for this coding contest problem.
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.
The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
Input
word page_number
::
::
Output
word
a_list_of_the_page_number
word
a_list_of_the_Page_number
::
::
Example
Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output
document
13
easy
9
even
18 25
introduction
3
style
7 12 21 | instruction | 0 | 24,657 | 6 | 49,314 |
"Correct Solution:
```
#!/usr/bin/env python3
d = {}
while True:
try:
w, p = input().split()
except:
break
try:
d[w].add(int(p))
except:
d[w] = set()
d[w].add(int(p))
l = list(d.keys())
l.sort()
for i in l:
print(i)
a = list(d[i])
a.sort()
print(" ".join(map(str, a)))
``` | output | 1 | 24,657 | 6 | 49,315 |
Provide a correct Python 3 solution for this coding contest problem.
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.
The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
Input
word page_number
::
::
Output
word
a_list_of_the_page_number
word
a_list_of_the_Page_number
::
::
Example
Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output
document
13
easy
9
even
18 25
introduction
3
style
7 12 21 | instruction | 0 | 24,658 | 6 | 49,316 |
"Correct Solution:
```
dic = {}
while 1:
try:
word, page = map(str, input().split())
page = int(page)
if word in dic:
dic[word].append(page)
else:
dic[word] = [page]
except:
break
for d in sorted(dic):
print(d)
print(' '.join(map(str, sorted(dic[d]))))
``` | output | 1 | 24,658 | 6 | 49,317 |
Provide a correct Python 3 solution for this coding contest problem.
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.
The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
Input
word page_number
::
::
Output
word
a_list_of_the_page_number
word
a_list_of_the_Page_number
::
::
Example
Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output
document
13
easy
9
even
18 25
introduction
3
style
7 12 21 | instruction | 0 | 24,659 | 6 | 49,318 |
"Correct Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import array
import bisect
import collections
import sys
if __name__ == "__main__":
pre_dict = collections.defaultdict(lambda: array.array("I"))
for line in sys.stdin:
[word, page0] = line.split()
page = int(page0)
bisect.insort(pre_dict[word], page)
sorted_dict = collections.OrderedDict(sorted(pre_dict.items(), key=lambda i: i[0]))
for k, v in sorted_dict.items():
print(k)
print(*v)
``` | output | 1 | 24,659 | 6 | 49,319 |
Provide a correct Python 3 solution for this coding contest problem.
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.
The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
Input
word page_number
::
::
Output
word
a_list_of_the_page_number
word
a_list_of_the_Page_number
::
::
Example
Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output
document
13
easy
9
even
18 25
introduction
3
style
7 12 21 | instruction | 0 | 24,660 | 6 | 49,320 |
"Correct Solution:
```
c={}
while 1:
try:
a,b=input().split()
if a in c.keys():c[a].append(int(b))
else: c[a]=[int(b)]
except:
for i,j in sorted(c.items()):
print(i)
print(' '.join(map(str,sorted(j))))
break
``` | output | 1 | 24,660 | 6 | 49,321 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.
The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
Input
word page_number
::
::
Output
word
a_list_of_the_page_number
word
a_list_of_the_Page_number
::
::
Example
Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output
document
13
easy
9
even
18 25
introduction
3
style
7 12 21
Submitted Solution:
```
import sys
a={}
for i in sys.stdin:
b,c=i.split()
a.setdefault(b, []).append(c)
for a,b in sorted(a.items(), key=lambda x: x[0]):
print(a)
print(*sorted(map(int,b)))
``` | instruction | 0 | 24,661 | 6 | 49,322 |
Yes | output | 1 | 24,661 | 6 | 49,323 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.
The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
Input
word page_number
::
::
Output
word
a_list_of_the_page_number
word
a_list_of_the_Page_number
::
::
Example
Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output
document
13
easy
9
even
18 25
introduction
3
style
7 12 21
Submitted Solution:
```
d = dict()
while True:
try:
w, n = input().split()
except:
break
n = int(n)
if d.get(w):
d[w].append(n)
else:
d[w] = []
d[w].append(n)
for k in sorted(d.keys()):
print(k)
print( *sorted(d[k]) )
``` | instruction | 0 | 24,662 | 6 | 49,324 |
Yes | output | 1 | 24,662 | 6 | 49,325 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.
The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
Input
word page_number
::
::
Output
word
a_list_of_the_page_number
word
a_list_of_the_Page_number
::
::
Example
Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output
document
13
easy
9
even
18 25
introduction
3
style
7 12 21
Submitted Solution:
```
import sys
dictionary = {}
for i in sys.stdin.readlines():
word, page = i.split()
if word in dictionary:
dictionary[word].append(int(page))
else:
dictionary[word] = [int(page)]
dictionary = sorted(dictionary.items()) #???????????????????????????
for i in dictionary:
print(i[0]) #??????
print(*sorted(i[1]))
``` | instruction | 0 | 24,663 | 6 | 49,326 |
Yes | output | 1 | 24,663 | 6 | 49,327 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.
The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
Input
word page_number
::
::
Output
word
a_list_of_the_page_number
word
a_list_of_the_Page_number
::
::
Example
Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output
document
13
easy
9
even
18 25
introduction
3
style
7 12 21
Submitted Solution:
```
if __name__ == '__main__':
dic = {}
while True:
try:
s,n = input().split()
dic.setdefault(s,[]).append(int(n))
except EOFError:
break
# print(dic)
tmp = sorted(list(dic))
for word in tmp:
print(word)
print(*sorted(dic[word]))
``` | instruction | 0 | 24,664 | 6 | 49,328 |
Yes | output | 1 | 24,664 | 6 | 49,329 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.
The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
Input
word page_number
::
::
Output
word
a_list_of_the_page_number
word
a_list_of_the_Page_number
::
::
Example
Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output
document
13
easy
9
even
18 25
introduction
3
style
7 12 21
Submitted Solution:
```
import sys
a={}
for i in sys.stdin:
b,c=i.split()
a.setdefault(b, []).append(c)
if c=='18':break
for a,b in sorted(a.items(), key=lambda x: x[0]):
print(a)
print(*b.sort())
``` | instruction | 0 | 24,665 | 6 | 49,330 |
No | output | 1 | 24,665 | 6 | 49,331 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.
The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
Input
word page_number
::
::
Output
word
a_list_of_the_page_number
word
a_list_of_the_Page_number
::
::
Example
Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output
document
13
easy
9
even
18 25
introduction
3
style
7 12 21
Submitted Solution:
```
import sys
l=[i.split() for i in sys.stdin]
d={}
for i in l:
if i[0] not in d:
d[i[0]]=[i[1]]
else:
d[i[0]].append(i[1])
for i in sorted(d.keys()):
print(i)
print(" ".join(d[i]))
``` | instruction | 0 | 24,666 | 6 | 49,332 |
No | output | 1 | 24,666 | 6 | 49,333 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.
The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
Input
word page_number
::
::
Output
word
a_list_of_the_page_number
word
a_list_of_the_Page_number
::
::
Example
Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output
document
13
easy
9
even
18 25
introduction
3
style
7 12 21
Submitted Solution:
```
import sys
a={}
for i in sys.stdin:
b,c=i.split()
a.setdefault(b, []).append(c)
if c=='18':break
for a,b in sorted(a.items(), key=lambda x: x[0]):
print(a)
print(*b)
``` | instruction | 0 | 24,667 | 6 | 49,334 |
No | output | 1 | 24,667 | 6 | 49,335 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.
The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
Input
word page_number
::
::
Output
word
a_list_of_the_page_number
word
a_list_of_the_Page_number
::
::
Example
Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output
document
13
easy
9
even
18 25
introduction
3
style
7 12 21
Submitted Solution:
```
book_index = {}
while True:
try:
word, page = input().split(' ')
page = int(page)
page_list = book_index.get(word)
if page_list:
page_list.append(page)
else:
book_index[word] = [page]
except Exception:
break
for k in sorted(book_index.keys()):
print(k)
print(' '.join(map(str, (sorted(book_index.get(k))))))
``` | instruction | 0 | 24,668 | 6 | 49,336 |
No | output | 1 | 24,668 | 6 | 49,337 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an n × m table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every 2 × 2 square contains all four distinct characters. Your task is to find a nice table (also consisting of «A», «G», «C», «T»), that differs from the given table in the minimum number of characters.
Input
First line contains two positive integers n and m — number of rows and columns in the table you are given (2 ≤ n, m, n × m ≤ 300 000). Then, n lines describing the table follow. Each line contains exactly m characters «A», «G», «C», «T».
Output
Output n lines, m characters each. This table must be nice and differ from the input table in the minimum number of characters.
Examples
Input
2 2
AG
CT
Output
AG
CT
Input
3 5
AGCAG
AGCAG
AGCAG
Output
TGCAT
CATGC
TGCAT
Note
In the first sample, the table is already nice. In the second sample, you can change 9 elements to make the table nice. | instruction | 0 | 24,795 | 6 | 49,590 |
Tags: brute force, constructive algorithms, greedy, math
Correct Solution:
```
from itertools import permutations
from sys import stdin, stdout
ly, lx = map(int, input().split())
grid = [[c for c in inp] for inp in stdin.read().splitlines()]
first = set()
bl = []
bpattern = []
bcost = 1e6
flip_row = False
for l in permutations('AGCT'):
if bcost == 0:
break
if ''.join(l[:2]) in first:
continue
first |= set([''.join(l[:2]), ''.join(l[1::-1])])
#try row flip
cost = 0
pattern = [0] * ly
for i, row in enumerate(grid):
diff1, diff2 = 0, 0
for j, letter in enumerate(row):
if letter != l[((i & 1) << 1) + (j & 1)]:
diff1 += 1
if letter != l[((i & 1) << 1) + ((j ^ 1) & 1)]:
diff2 += 1
cost += min(diff1, diff2)
if diff1 >= diff2: # 1 -> diff1, 0 -> diff2
pattern[i] = 1
if cost < bcost:
bcost = cost
bpattern = pattern.copy()
flip_row = True
bl = l
# try col flip
cost = 0
pattern = [0] * lx
for j in range(lx):
diff1 = diff2 = 0
for i in range(ly):
if grid[i][j] != l[((j & 1) << 1) + (i & 1)]:
diff1 += 1
if grid[i][j] != l[((j & 1) << 1) + ((i ^ 1) & 1)]:
diff2 += 1
cost += min(diff1, diff2)
if diff1 >= diff2:
pattern[j] = 1
if cost < bcost:
bcost = cost
bpattern = pattern.copy()
flip_row = False
bl = l
if flip_row:
for i in range(ly):
grid[i] = ''.join(
[bl[((i & 1) << 1) + ((j ^ bpattern[i]) & 1)] for j in range(lx)])
else:
for i in range(ly):
grid[i] = ''.join(
[bl[((j & 1) << 1) + ((i ^ bpattern[j]) & 1)] for j in range(lx)])
# print(f'need at least:{bcost}')
print('\n'.join(''.join((k for k in grid[i])) for i in range(ly)))
``` | output | 1 | 24,795 | 6 | 49,591 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an n × m table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every 2 × 2 square contains all four distinct characters. Your task is to find a nice table (also consisting of «A», «G», «C», «T»), that differs from the given table in the minimum number of characters.
Input
First line contains two positive integers n and m — number of rows and columns in the table you are given (2 ≤ n, m, n × m ≤ 300 000). Then, n lines describing the table follow. Each line contains exactly m characters «A», «G», «C», «T».
Output
Output n lines, m characters each. This table must be nice and differ from the input table in the minimum number of characters.
Examples
Input
2 2
AG
CT
Output
AG
CT
Input
3 5
AGCAG
AGCAG
AGCAG
Output
TGCAT
CATGC
TGCAT
Note
In the first sample, the table is already nice. In the second sample, you can change 9 elements to make the table nice. | instruction | 0 | 24,796 | 6 | 49,592 |
Tags: brute force, constructive algorithms, greedy, math
Correct Solution:
```
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
grid=[]
for i in range(n):
s=input()
grid.append([])
for j in range(m):
if s[j]=='A':
grid[-1].append(0)
elif s[j]=='C':
grid[-1].append(1)
elif s[j]=='G':
grid[-1].append(2)
else:
grid[-1].append(3)
bestscore=n*m
rowsum0=[]
rowsum1=[]
for i in range(n):
rowsum0.append([0]*4)
rowsum1.append([0]*4)
columnsum0=[]
columnsum1=[]
for i in range(m):
columnsum0.append([0]*4)
columnsum1.append([0]*4)
for i in range(n):
for j in range(m):
if j%2==0:
rowsum0[i][grid[i][j]]+=1
else:
rowsum1[i][grid[i][j]]+=1
if i%2==0:
columnsum0[j][grid[i][j]]+=1
else:
columnsum1[j][grid[i][j]]+=1
flag=0
bestx=-1
besty=-1
for x in range(3):
for y in range(x+1,4):
for i in range(4):
if i!=x and i!=y:
p=i
break
for i in range(4):
if i!=x and i!=y and i!=p:
q=i
break
tmpscore=0
for i in range(n):
if i%2==0:
tmpscore+=m-max(rowsum0[i][x]+rowsum1[i][y],rowsum0[i][y]+rowsum1[i][x])
else:
tmpscore+=m-max(rowsum0[i][p]+rowsum1[i][q],rowsum0[i][q]+rowsum1[i][p])
if bestscore>tmpscore:
flag=0
bestx=x
besty=y
bestscore=tmpscore
for x in range(3):
for y in range(x+1,4):
for i in range(4):
if i!=x and i!=y:
p=i
break
for i in range(4):
if i!=x and i!=y and i!=p:
q=i
break
tmpscore=0
for i in range(m):
if i%2==0:
tmpscore+=n-max(columnsum0[i][x]+columnsum1[i][y],columnsum0[i][y]+columnsum1[i][x])
else:
tmpscore+=n-max(columnsum0[i][p]+columnsum1[i][q],columnsum0[i][q]+columnsum1[i][p])
if bestscore>tmpscore:
flag=1
bestx=x
besty=y
bestscore=tmpscore
ans=[]
for i in range(n):
ans.append([0]*m)
x=bestx
y=besty
conv='ACGT'
if flag:
for i in range(4):
if i!=x and i!=y:
p=i
break
for i in range(4):
if i!=x and i!=y and i!=p:
q=i
break
for i in range(m):
if i%2==0:
if columnsum0[i][y]+columnsum1[i][x]>columnsum0[i][x]+columnsum1[i][y]:
tmp=x
x=y
y=tmp
for j in range(n):
if j%2==0:
ans[j][i]=conv[x]
else:
ans[j][i]=conv[y]
else:
if columnsum0[i][q]+columnsum1[i][p]>columnsum0[i][p]+columnsum1[i][q]:
tmp=p
p=q
q=tmp
for j in range(n):
if j%2==0:
ans[j][i]=conv[p]
else:
ans[j][i]=conv[q]
else:
for i in range(4):
if i!=x and i!=y:
p=i
break
for i in range(4):
if i!=x and i!=y and i!=p:
q=i
break
for i in range(n):
if i%2==0:
if rowsum0[i][y]+rowsum1[i][x]>rowsum0[i][x]+rowsum1[i][y]:
tmp=x
x=y
y=tmp
for j in range(m):
if j%2==0:
ans[i][j]=conv[x]
else:
ans[i][j]=conv[y]
else:
if rowsum0[i][q]+rowsum1[i][p]>rowsum0[i][p]+rowsum1[i][q]:
tmp=p
p=q
q=tmp
for j in range(m):
if j%2==0:
ans[i][j]=conv[p]
else:
ans[i][j]=conv[q]
for i in range(n):
print(''.join(ans[i]))
``` | output | 1 | 24,796 | 6 | 49,593 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an n × m table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every 2 × 2 square contains all four distinct characters. Your task is to find a nice table (also consisting of «A», «G», «C», «T»), that differs from the given table in the minimum number of characters.
Input
First line contains two positive integers n and m — number of rows and columns in the table you are given (2 ≤ n, m, n × m ≤ 300 000). Then, n lines describing the table follow. Each line contains exactly m characters «A», «G», «C», «T».
Output
Output n lines, m characters each. This table must be nice and differ from the input table in the minimum number of characters.
Examples
Input
2 2
AG
CT
Output
AG
CT
Input
3 5
AGCAG
AGCAG
AGCAG
Output
TGCAT
CATGC
TGCAT
Note
In the first sample, the table is already nice. In the second sample, you can change 9 elements to make the table nice. | instruction | 0 | 24,797 | 6 | 49,594 |
Tags: brute force, constructive algorithms, greedy, math
Correct Solution:
```
from itertools import permutations
from sys import stdin, stdout
ly, lx = map(int, input().split())
grid = [[c for c in inp] for inp in stdin.read().splitlines()]
first = set()
bl = []
bpattern = []
bcost = 1e6
flip_row = False
for l in permutations('AGCT'):
if bcost == 0:
break
if ''.join(l[:2]) in first:
continue
first |= set([''.join(l[:2]), ''.join(l[1::-1])])
#try row flip
cost = 0
pattern = [0] * ly
for i in range(ly):
diff1, diff2 = 0, 0
for j in range(lx):
if grid[i][j] != l[((i & 1) << 1) + (j & 1)]:
diff1 += 1
if grid[i][j] != l[((i & 1) << 1) + ((j ^ 1) & 1)]:
diff2 += 1
cost += min(diff1, diff2)
if diff1 >= diff2: # 1 -> diff1, 0 -> diff2
pattern[i] = 1
if cost < bcost:
bcost = cost
bpattern = pattern.copy()
flip_row = True
bl = l
# try col flip
cost = 0
pattern = [0] * lx
for j in range(lx):
diff1 = diff2 = 0
for i in range(ly):
if grid[i][j] != l[((j & 1) << 1) + (i & 1)]:
diff1 += 1
if grid[i][j] != l[((j & 1) << 1) + ((i ^ 1) & 1)]:
diff2 += 1
cost += min(diff1, diff2)
if diff1 >= diff2:
pattern[j] = 1
if cost < bcost:
bcost = cost
bpattern = pattern.copy()
flip_row = False
bl = l
if flip_row:
for i in range(ly):
grid[i] = ''.join(
[bl[((i & 1) << 1) + ((j ^ bpattern[i]) & 1)] for j in range(lx)])
else:
for i in range(ly):
grid[i] = ''.join(
[bl[((j & 1) << 1) + ((i ^ bpattern[j]) & 1)] for j in range(lx)])
# print(f'need at least:{bcost}')
stdout.write('\n'.join(''.join((k for k in grid[i])) for i in range(ly)))
``` | output | 1 | 24,797 | 6 | 49,595 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an n × m table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every 2 × 2 square contains all four distinct characters. Your task is to find a nice table (also consisting of «A», «G», «C», «T»), that differs from the given table in the minimum number of characters.
Input
First line contains two positive integers n and m — number of rows and columns in the table you are given (2 ≤ n, m, n × m ≤ 300 000). Then, n lines describing the table follow. Each line contains exactly m characters «A», «G», «C», «T».
Output
Output n lines, m characters each. This table must be nice and differ from the input table in the minimum number of characters.
Examples
Input
2 2
AG
CT
Output
AG
CT
Input
3 5
AGCAG
AGCAG
AGCAG
Output
TGCAT
CATGC
TGCAT
Note
In the first sample, the table is already nice. In the second sample, you can change 9 elements to make the table nice. | instruction | 0 | 24,798 | 6 | 49,596 |
Tags: brute force, constructive algorithms, greedy, math
Correct Solution:
```
from itertools import permutations
from sys import stdin, stdout
ly, lx = map(int, input().split())
grid = [[c for c in inp] for inp in stdin.read().splitlines()]
first = set()
bl = []
bpattern = []
bcost = 1e6
flip_row = False
for l in permutations('AGCT'):
if bcost == 0:
break
if ''.join(l[:2]) in first:
continue
first |= set([''.join(l[:2]), ''.join(l[1::-1])])
#try row flip
cost = 0
pattern = [0] * ly
for i in range(ly):
diff1, diff2 = 0, 0
for j in range(lx):
if grid[i][j] != l[((i & 1) << 1) + (j & 1)]:
diff1 += 1
if grid[i][j] != l[((i & 1) << 1) + ((j ^ 1) & 1)]:
diff2 += 1
cost += min(diff1, diff2)
if diff1 >= diff2: # 1 -> diff1, 0 -> diff2
pattern[i] = 1
if cost < bcost:
bcost = cost
bpattern = pattern.copy()
flip_row = True
bl = l
# try col flip
cost = 0
pattern = [0] * lx
for j in range(lx):
diff1 = diff2 = 0
for i in range(ly):
if grid[i][j] != l[((j & 1) << 1) + (i & 1)]:
diff1 += 1
if grid[i][j] != l[((j & 1) << 1) + ((i ^ 1) & 1)]:
diff2 += 1
cost += min(diff1, diff2)
if diff1 >= diff2:
pattern[j] = 1
if cost < bcost:
bcost = cost
bpattern = pattern.copy()
flip_row = False
bl = l
if flip_row:
for i in range(ly):
grid[i] = ''.join(
[bl[((i & 1) << 1) + ((j ^ bpattern[i]) & 1)] for j in range(lx)])
else:
for i in range(ly):
grid[i] = ''.join(
[bl[((j & 1) << 1) + ((i ^ bpattern[j]) & 1)] for j in range(lx)])
# print(f'need at least:{bcost}')
print('\n'.join(''.join((k for k in grid[i])) for i in range(ly)))
``` | output | 1 | 24,798 | 6 | 49,597 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an n × m table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every 2 × 2 square contains all four distinct characters. Your task is to find a nice table (also consisting of «A», «G», «C», «T»), that differs from the given table in the minimum number of characters.
Input
First line contains two positive integers n and m — number of rows and columns in the table you are given (2 ≤ n, m, n × m ≤ 300 000). Then, n lines describing the table follow. Each line contains exactly m characters «A», «G», «C», «T».
Output
Output n lines, m characters each. This table must be nice and differ from the input table in the minimum number of characters.
Examples
Input
2 2
AG
CT
Output
AG
CT
Input
3 5
AGCAG
AGCAG
AGCAG
Output
TGCAT
CATGC
TGCAT
Note
In the first sample, the table is already nice. In the second sample, you can change 9 elements to make the table nice.
Submitted Solution:
```
n,m = list(map(int, input().split()))
rows = []
for i in range(n):
rows.append(input())
rowtypes = [('AC','GT'), ('AG', 'CT'), ('AT', 'CG'),
('GT','AC'), ('CT', 'AG'), ('CG', 'AT')]
outBest = []
difBest = 10**7
#Horiz
for typ in rowtypes:
out = []
dif = 0
for row in range(n):
chars = typ[row%2]
want = rows[row]
off = [0, 0] #cur, swp
for col in range(m):
if want[col] != chars[0]:
off[col%2] += 1
if want[col] != chars[1]:
off[(col+1)%2] += 1
if off[0] < off[1]:
newRow = chars*(m//2)
if m%2:
newRow += chars[0]
dif += off[0]
else:
newRow = chars*(m//2)
if m%2:
newRow = chars[1] + newRow
dif += off[1]
out.append(newRow)
if dif < difBest:
difBest = dif
outBest = out
#Vert
for typ in rowtypes:
out = []
dif = 0
for col in range(m):
chars = typ[col%2]
want = [rows[i][col] for i in range(n)]
off = [0, 0] #cur, swp
for row in range(n):
if want[row] != chars[0]:
off[row%2] += 1
if want[row] != chars[1]:
off[(row+1)%2] += 1
if off[0] < off[1]:
newRow = chars*(n//2)
if n%2:
newRow += chars[0]
dif += off[0]
else:
newRow = chars*(n//2)
if n%2:
newRow = chars[1] + newRow
dif += off[1]
out.append(newRow)
if dif < difBest:
difBest = dif
out2 = []
for i in range(n):
out2.append(''.join([out[j][i] for j in range(m)]))
outBest = out2
for row in outBest:
print(row)
``` | instruction | 0 | 24,799 | 6 | 49,598 |
No | output | 1 | 24,799 | 6 | 49,599 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an n × m table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every 2 × 2 square contains all four distinct characters. Your task is to find a nice table (also consisting of «A», «G», «C», «T»), that differs from the given table in the minimum number of characters.
Input
First line contains two positive integers n and m — number of rows and columns in the table you are given (2 ≤ n, m, n × m ≤ 300 000). Then, n lines describing the table follow. Each line contains exactly m characters «A», «G», «C», «T».
Output
Output n lines, m characters each. This table must be nice and differ from the input table in the minimum number of characters.
Examples
Input
2 2
AG
CT
Output
AG
CT
Input
3 5
AGCAG
AGCAG
AGCAG
Output
TGCAT
CATGC
TGCAT
Note
In the first sample, the table is already nice. In the second sample, you can change 9 elements to make the table nice.
Submitted Solution:
```
from sys import stdin
n, m = map(int, stdin.readline().split())
tabl = [input() for _ in range(n)]
ans = 10 ** 10
tetr = []
patt = {'GCTA', 'GTAC', 'ATCG', 'ATGC', 'TACG', 'CGTA', 'CAGT', 'GATC', 'TGAC', 'CTGA', 'GTCA', 'CTAG', 'TCAG', 'GACT',
'ACTG', 'TCGA', 'AGCT', 'TAGC', 'CGAT', 'GCAT', 'CATG', 'ACGT', 'AGTC', 'TGCA'}
for p in patt:
cnt = 0
for i in range(n):
for j in range(m):
Q = i % 2
W = j % 4
if (Q == 1 and W == 0) or (Q == 0 and W == 2):
if tabl[i][j] != p[0]:
cnt += 1
elif (Q == 1 and W == 1) or (Q == 0 and W == 3):
if tabl[i][j] != p[1]:
cnt += 1
elif (Q == 1 and W == 2) or (Q == 0 and W == 0):
if tabl[i][j] != p[2]:
cnt += 1
else:
if tabl[i][j] != p[3]:
cnt += 1
if ans > cnt:
ans = cnt
tetr = [p, 1]
cnt = 0
for i in range(n):
for j in range(m):
Q = i % 2
W = j % 2
if Q == 0 and W == 0:
if tabl[i][j] != p[0]:
cnt += 1
elif Q == 0 and W == 1:
if tabl[i][j] != p[1]:
cnt += 1
elif Q == 1 and W == 0:
if tabl[i][j] != p[2]:
cnt += 1
else:
if tabl[i][j] != p[3]:
cnt += 1
if ans > cnt:
ans = cnt
tetr = [p, 2]
tabl2 = []
if tetr[1] == 1:
p = tetr[0]
for i in range(n):
s = ''
Q = i % 2
if Q:
s += (p[0] + p[1] + p[2] + p[3]) * (m // 4 + 1)
else:
s += (p[2] + p[3] + p[0] + p[1]) * (m // 4 + 1)
tabl2.append(s[:m])
else:
p = tetr[0]
for i in range(n):
s = ''
Q = i % 2
if Q == 0:
s += (p[0] + p[1]) * (m // 2 + 1)
else:
s += (p[2] + p[3]) * (m // 2 + 1)
tabl2.append(s[:m])
print('\n'.join(tabl2))
``` | instruction | 0 | 24,800 | 6 | 49,600 |
No | output | 1 | 24,800 | 6 | 49,601 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an n × m table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every 2 × 2 square contains all four distinct characters. Your task is to find a nice table (also consisting of «A», «G», «C», «T»), that differs from the given table in the minimum number of characters.
Input
First line contains two positive integers n and m — number of rows and columns in the table you are given (2 ≤ n, m, n × m ≤ 300 000). Then, n lines describing the table follow. Each line contains exactly m characters «A», «G», «C», «T».
Output
Output n lines, m characters each. This table must be nice and differ from the input table in the minimum number of characters.
Examples
Input
2 2
AG
CT
Output
AG
CT
Input
3 5
AGCAG
AGCAG
AGCAG
Output
TGCAT
CATGC
TGCAT
Note
In the first sample, the table is already nice. In the second sample, you can change 9 elements to make the table nice.
Submitted Solution:
```
n,m=map(int,input().split())
a=[""]*n
strokov=[]
stolb=[]
schetstolb=0
schetstrok=0
for i in range(n):
a[i]=input()
g=[["0"]*m for i in range(n)]
list1=[]
list2=[]
schetl1=0
schetl2=0
for i in range(n):
t=a[i]
for j in range(m):
g[i][j]=t[j]
for i in range(n):
#выбор букв на строки(1 вариант )
s=g[i]
if (i%2==0):
x="A"
y="G"
else:
x="C"
y="T"
schet1=0
schet2=0
stroka1=""
stroka2=""
for j in range(m):
#расматриваем 2 варианта (xy,yx)
#xy
if (j%2)==0:
if s[j]!=x:
schet1=schet1+1
stroka1=stroka1+x
else:
if s[j]!=y:
schet1=schet1+1
stroka1=stroka1+y
#yx
if ((j%2)==0):
if (s[j]!=y):
schet2=schet2+1
stroka2=stroka2+y
else:
if (s[j]!=x):
schet2=schet2+1
stroka2=stroka2+x
#выбираем лутший
if schet1<schet2:
schetl1=schetl1+schet1
list1.append(stroka1)
else:
schetl1=schetl1+schet2
list1.append(stroka2)
for i in range(n):
#выбор букв на строки(2 вариант )
s=g[i]
if (i%2==0):
x="C"
y="T"
else:
x="A"
y="G"
schet1=0
schet2=0
stroka1=""
stroka2=""
for j in range(m):
#расматриваем 2 варианта (xy,yx)
#xy
if (j%2)==0:
if s[j]!=x:
schet1=schet1+1
stroka1=stroka1+x
else:
if s[j]!=y:
schet1=schet1+1
stroka1=stroka1+y
#yx
if ((j%2)==0):
if (s[j]!=y):
schet2=schet2+1
stroka2=stroka2+y
else:
if (s[j]!=x):
schet2=schet2+1
stroka2=stroka2+x
#выбираем лутший
if schet1<schet2:
schetl2=schetl2+schet1
list2.append(stroka1)
else:
schetl2=schetl2+schet2
list2.append(stroka2)
#выбираем лутший строковый
if schetl1<schetl2:
strokov=list1
schetstrok=schetl1
else:
strokov=list2
schetstrok=schetl2
#переворачиваем массив
g=tuple(zip(*g[::1]))
#тоже самое только со столбцами
list1=[]
list2=[]
schetl1=0
schetl2=0
for i in range(m):
#выбор букв на стотбцы(1 вариант )
s=g[i]
if (i%2==0):
x="A"
y="G"
else:
x="C"
y="T"
schet1=0
schet2=0
stroka1=""
stroka2=""
for j in range(n):
#расматриваем 2 варианта (xy,yx)
#xy
if (j%2)==0:
if s[j]!=x:
schet1=schet1+1
stroka1=stroka1+x
else:
if s[j]!=y:
schet1=schet1+1
stroka1=stroka1+y
#yx
if ((j%2)==0):
if (s[j]!=y):
schet2=schet2+1
stroka2=stroka2+y
else:
if (s[j]!=x):
schet2=schet2+1
stroka2=stroka2+x
#выбираем лутший
if schet1<schet2:
schetl1=schetl1+schet1
list1.append(stroka1)
else:
schetl1=schetl1+schet2
list1.append(stroka2)
for i in range(m):
#выбор букв на столбцы(2 вариант )
s=g[i]
if (i%2==0):
x="C"
y="T"
else:
x="A"
y="G"
schet1=0
schet2=0
stroka1=""
stroka2=""
for j in range(n):
#расматриваем 2 варианта (xy,yx)
#xy
if (j%2)==0:
if s[j]!=x:
schet1=schet1+1
stroka1=stroka1+x
else:
if s[j]!=y:
schet1=schet1+1
stroka1=stroka1+y
#yx
if ((j%2)==0):
if (s[j]!=y):
schet2=schet2+1
stroka2=stroka2+y
else:
if (s[j]!=x):
schet2=schet2+1
stroka2=stroka2+x
#выбираем лутший
if schet1<schet2:
schetl2=schetl2+schet1
list2.append(stroka1)
else:
schetl2=schetl2+schet2
list2.append(stroka2)
#выбираем лутший столбцевой
if schetl1<schetl2:
stolb=list1
schetstolb=schetl1
else:
stolb=list2
schetstolb=schetl2
#выбираем самый лутший
if schetstolb<schetstrok:
stolb=tuple(zip(*stolb[::1]))
for i in range(n):
print(*stolb[i],sep='')
else:
for i in range(n):
print(*strokov[i])
``` | instruction | 0 | 24,802 | 6 | 49,604 |
No | output | 1 | 24,802 | 6 | 49,605 |
Provide tags and a correct Python 3 solution for this coding contest problem.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
Input
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output
Output the sequence in the required format.
Examples
Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30 | instruction | 0 | 25,064 | 6 | 50,128 |
Tags: expression parsing, implementation, sortings, strings
Correct Solution:
```
lst=[int(x) for x in input().split(',')]
lst=list(set(lst))
lst=sorted(lst)
f=0
fir=lst[0]
lt=lst[0]
for i in range(len(lst)-1):
if lst[i]+1==lst[i+1]:
lt=lst[i+1]
else:
if fir==lt:
print(fir,end=',')
else:
print(fir,lt,sep='-',end=',')
fir=lst[i+1]
lt=lst[i+1]
if fir==lt:
print(fir)
else:
print(fir,lt,sep='-')
``` | output | 1 | 25,064 | 6 | 50,129 |
Provide tags and a correct Python 3 solution for this coding contest problem.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
Input
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output
Output the sequence in the required format.
Examples
Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30 | instruction | 0 | 25,065 | 6 | 50,130 |
Tags: expression parsing, implementation, sortings, strings
Correct Solution:
```
import sys
pages = list(map(int, sys.stdin.readline().strip().split(",")))
unipages = set(pages)
unilist = []
for i in unipages:
unilist.append(i)
unilist.sort()
unilen = len(unilist)
first = unilist[0]
prev = first
for i in range(1, unilen):
if unilist[i] == prev + 1:
prev = unilist[i]
else:
last = prev
if first != last:
print(first, last, sep = '-', end = '')
else:
print(first, end = '')
print(",", end = '')
first = unilist[i]
prev = unilist[i]
if unilist[unilen-1] == first:
print(unilist.pop())
else:
print(first, unilist.pop(), sep = '-', end = '')
``` | output | 1 | 25,065 | 6 | 50,131 |
Provide tags and a correct Python 3 solution for this coding contest problem.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
Input
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output
Output the sequence in the required format.
Examples
Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30 | instruction | 0 | 25,066 | 6 | 50,132 |
Tags: expression parsing, implementation, sortings, strings
Correct Solution:
```
mass = list(set(list(map(int, input().split(',')))))
mass.append(1234214)
mass.sort()
prev = mass[0]
begin = mass[0]
ans = []
# print(mass)
for i in range(1, len(mass)):
if mass[i] == prev + 1:
prev = mass[i]
else:
if prev == begin:
ans.append(str(prev))
else:
ans.append(str(begin) + '-' + str(prev))
prev = mass[i]
begin = mass[i]
# print()
print(','.join(ans))
``` | output | 1 | 25,066 | 6 | 50,133 |
Provide tags and a correct Python 3 solution for this coding contest problem.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
Input
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output
Output the sequence in the required format.
Examples
Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30 | instruction | 0 | 25,067 | 6 | 50,134 |
Tags: expression parsing, implementation, sortings, strings
Correct Solution:
```
l=[]
l=[int(x) for x in input().split(',')]
l1=list(set(l))
l1.sort()
x=l1[0]
y=l1[0]
for i in range(len(l1)-1):
if l1[i+1]-l1[i]==1:
y=l1[i+1]
else:
if x==y:
print(x,end=",")
else:
print(x,y,sep='-',end=',')
x=l1[i+1]
y=l1[i+1]
if x==y:
print(x)
else:
print(x,y,sep='-')
``` | output | 1 | 25,067 | 6 | 50,135 |
Provide tags and a correct Python 3 solution for this coding contest problem.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
Input
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output
Output the sequence in the required format.
Examples
Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30 | instruction | 0 | 25,068 | 6 | 50,136 |
Tags: expression parsing, implementation, sortings, strings
Correct Solution:
```
t = list(map(int, input().split(',')))
p, k = [0] * 1002, 0
for i in t:
p[i] = 1
if i > k: k = i
r, i, j = [], 0, -1
while j < k:
i = p.index(1, j + 2)
j = p.index(0, i + 1) - 1
if i == j: r.append(str(i))
else: r.append(str(i) + '-' + str(j))
print(','.join(r))
``` | output | 1 | 25,068 | 6 | 50,137 |
Provide tags and a correct Python 3 solution for this coding contest problem.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
Input
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output
Output the sequence in the required format.
Examples
Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30 | instruction | 0 | 25,069 | 6 | 50,138 |
Tags: expression parsing, implementation, sortings, strings
Correct Solution:
```
#!/usr/bin/env python3
from sys import stdin, stderr
input_tokens = stdin.readline()
tokens = list(set([int(x) for x in input_tokens.split(',')]))
tokens.sort()
print(tokens, file=stderr)
s = ""
prev = 0
seq = False
for n in tokens:
if prev == 0:
s += str(n)
else:
if n == (prev+1):
if seq == False:
s += "-"
seq = True
else:
if seq == True:
s += str(prev)
seq = False
s += ","
s += str(n)
prev = n
if seq == True:
s += str(prev)
print(s)
``` | output | 1 | 25,069 | 6 | 50,139 |
Provide tags and a correct Python 3 solution for this coding contest problem.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
Input
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output
Output the sequence in the required format.
Examples
Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30 | instruction | 0 | 25,070 | 6 | 50,140 |
Tags: expression parsing, implementation, sortings, strings
Correct Solution:
```
l=[int(i) for i in input().split(',')]
l=list(set(l))
#print(l)
ans=''
l.sort()
i=0
res=[]
for i in range(1,10000):
if i>max(l):
break
if i in l:
res.append(i)
else:
if len(res)==1 :
ans+=str(res[0])+','
elif len(res)>1:
ans+=str(res[0])+'-'+str(res[-1])+','
res=[]
if len(res)==1:
ans+=str(res[0])
elif len(res)>1:
ans+=str(res[0])+'-'+str(res[-1])
ans=list(ans)
if ans[-1]==',':
ans.pop()
print(''.join(ans))
``` | output | 1 | 25,070 | 6 | 50,141 |
Provide tags and a correct Python 3 solution for this coding contest problem.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
Input
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output
Output the sequence in the required format.
Examples
Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30 | instruction | 0 | 25,071 | 6 | 50,142 |
Tags: expression parsing, implementation, sortings, strings
Correct Solution:
```
a = list(set([int(x) for x in input().split(",")]))
a = sorted(a)
l = a[0]
r = []
for i in range(0, len(a) - 1):
if a[i] < a[i + 1] - 1:
if a[i] == l:
r.append("%d" % l)
l = a[i + 1]
else:
r.append("%d-%d" % (l, a[i]))
l = a[i + 1]
if a[-1] == l:
r.append("%d" % l)
else:
r.append("%d-%d" % (l, a[-1]))
print(",".join(r))
``` | output | 1 | 25,071 | 6 | 50,143 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).
Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».
For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.
Input
The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.
Output
Output the sequence in the required format.
Examples
Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30
Submitted Solution:
```
#Page Numbers(O)
def removeDuplicates(listofElements):
uniqueList = []
for elem in listofElements:
if elem not in uniqueList:
uniqueList.append(elem)
return uniqueList
l = list(map(int,input().split(",")))
l = list(set(l))
l.sort()
pl = []
j = -1
flag = 0
for i in range(0,len(l)-1):
if(l[i+1] - l[i] == 1 and flag == 0):
a = l[i]
b = l[i+1]
s = str(a) + "-" + str(b)
if(j>=0 and pl[j] != str(a)):
j = j + 1
pl.insert(j,s)
elif(j<0):
j = j + 1
pl.insert(j,s)
else:
pl[j] = s
flag = 1
elif(l[i+1] - l[i] == 1 and flag == 1):
b = l[i+1]
s = str(a) + "-" + str(b)
pl[j] = s
elif(l[i+1] - l[i] != 1):
if(j<0):
j = j + 1
pl.insert(j,str(l[i]))
j = j + 1
pl.insert(j,str(l[i+1]))
flag = 0
pl = removeDuplicates(pl)
print(*pl,sep = ",")
``` | instruction | 0 | 25,077 | 6 | 50,154 |
No | output | 1 | 25,077 | 6 | 50,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, second one is love, third one is hate and so on...
For example if n = 1, then his feeling is "I hate it" or if n = 2 it's "I hate that I love it", and if n = 3 it's "I hate that I love that I hate it" and so on.
Please help Dr. Banner.
Input
The only line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of layers of love and hate.
Output
Print Dr.Banner's feeling in one line.
Examples
Input
1
Output
I hate it
Input
2
Output
I hate that I love it
Input
3
Output
I hate that I love that I hate it | instruction | 0 | 25,224 | 6 | 50,448 |
Tags: implementation
Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 6 20:45:13 2020
@author: alber
"""
that = 'I hate that I love that '
love2 = 'I hate that I love it'
love = 'I love it'
hate = 'I hate it'
x = int(input())
rep = x//2
if x == 1:
print('I hate it')
elif x==2:
print('I hate that I love it')
elif x%2 == 0 and x != 2:
print(that*(rep-1)+love2)
elif x%2 and x != 1:
print(that*rep + hate)
``` | output | 1 | 25,224 | 6 | 50,449 |
Provide tags and a correct Python 3 solution for this coding contest problem.
zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.
Initially, the text editor is empty. It takes him x seconds to insert or delete a letter 'a' from the text file and y seconds to copy the contents of the entire text file, and duplicate it.
zscoder wants to find the minimum amount of time needed for him to create the input file of exactly n letters 'a'. Help him to determine the amount of time needed to generate the input.
Input
The only line contains three integers n, x and y (1 ≤ n ≤ 107, 1 ≤ x, y ≤ 109) — the number of letters 'a' in the input file and the parameters from the problem statement.
Output
Print the only integer t — the minimum amount of time needed to generate the input file.
Examples
Input
8 1 1
Output
4
Input
8 1 10
Output
8 | instruction | 0 | 26,093 | 6 | 52,186 |
Tags: dfs and similar, dp
Correct Solution:
```
import sys
n, x, y = map(int, input().split())
size = 10**7
dq_x, dq_y, dq_i = [0]*size, [0]*size, [0]*size
l, r = 0, 0
cx, cy = 0, 0
for i in range(1, n+1):
cx += 1
while l < r and dq_i[l] < i:
l += 1
if l < r and (dq_x[l]-i-cx)*x + (dq_y[l]-cy)*y < 0:
cx = dq_x[l] - i
cy = dq_y[l]
tx, ty = cx + i*2, cy+1
while l < r and (dq_x[r]-tx)*x + (dq_y[r]-ty)*y > 0:
r -= 1
dq_x[r] = tx
dq_y[r] = ty
dq_i[r] = i*2
r += 1
print(cx*x + cy*y)
``` | output | 1 | 26,093 | 6 | 52,187 |
Provide tags and a correct Python 3 solution for this coding contest problem.
zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.
Initially, the text editor is empty. It takes him x seconds to insert or delete a letter 'a' from the text file and y seconds to copy the contents of the entire text file, and duplicate it.
zscoder wants to find the minimum amount of time needed for him to create the input file of exactly n letters 'a'. Help him to determine the amount of time needed to generate the input.
Input
The only line contains three integers n, x and y (1 ≤ n ≤ 107, 1 ≤ x, y ≤ 109) — the number of letters 'a' in the input file and the parameters from the problem statement.
Output
Print the only integer t — the minimum amount of time needed to generate the input file.
Examples
Input
8 1 1
Output
4
Input
8 1 10
Output
8 | instruction | 0 | 26,094 | 6 | 52,188 |
Tags: dfs and similar, dp
Correct Solution:
```
n, a, b = input().split(' ')
n = int(n)
a = int(a)
b = int(b)
tk = tk2 = dk = dk2 = hg = hg2 = tag = tag2 = k1 = k2 = 0
kg = n
while kg >= 2:
if kg % 2 != 0:
tag = 1
if tag == 1 and (kg-kg//2-1)*a < b:
break
hg2 = kg
hg = (kg+1)//2
while hg >= 2:
if hg % 2 != 0:
tag2 = 1
if tag2 == 1 and (hg-hg//2-1)*a < b:
break
if tag2 == 0 and (hg-hg//2)*a < b:
break
if hg % 2 != 0:
tk2 += 1
hg //= 2
tag2 = 0
tk += 1
t0 = b*tk + a*hg + a*tk2
tag2 = 0
hg = (hg2 - 1)//2
while hg >= 2:
if hg % 2 != 0:
tag2 = 1
if tag2 == 1 and (hg - hg//2 - 1) * a < b:
break
if tag2 == 0 and (hg - hg//2) * a < b:
break
if hg % 2 != 0:
dk2 += 1
hg //= 2
tag2 = 0
dk += 1
t1 = b*dk + a*hg + a*dk2
if t0 <= t1:
kg += 1
else:
kg -= 1
tk = tk2 = dk = dk2 = hg2 = 0
if tag == 1:
k2 += 1
if (kg-kg//2)*a <= b:
break
kg //= 2
tag = 0
k1 += 1
t = b*k1 + k2*a + kg*a
print(t)
``` | output | 1 | 26,094 | 6 | 52,189 |
Provide tags and a correct Python 3 solution for this coding contest problem.
zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.
Initially, the text editor is empty. It takes him x seconds to insert or delete a letter 'a' from the text file and y seconds to copy the contents of the entire text file, and duplicate it.
zscoder wants to find the minimum amount of time needed for him to create the input file of exactly n letters 'a'. Help him to determine the amount of time needed to generate the input.
Input
The only line contains three integers n, x and y (1 ≤ n ≤ 107, 1 ≤ x, y ≤ 109) — the number of letters 'a' in the input file and the parameters from the problem statement.
Output
Print the only integer t — the minimum amount of time needed to generate the input file.
Examples
Input
8 1 1
Output
4
Input
8 1 10
Output
8 | instruction | 0 | 26,095 | 6 | 52,190 |
Tags: dfs and similar, dp
Correct Solution:
```
__author__ = 'Think'
n, x, y=[int(i) for i in input().split()]
def worth(num):
if num%2==0:
dub=y
alt=x*(num//2)
else:
dub=y+x
alt=x*((num//2)+1)
return dub<alt, dub, alt
time=0
while n>0:
parity=n%2
should_double, dub, alt=worth(n)
if should_double:
time+=dub
if parity==0:
# print("Doubled, even,", n, n//2, time)
n=n//2
continue
else:
half=n//2
if half%2==0:
# print("Doubled, 1 mod 4,", n, half, time)
n=half
continue
else:
if ((half//2+1)*x+y)<half*x:
# print("Doubled, 3 mod 4, continued", n, half+1, time)
n=half+1
continue
else:
# print("Doubled, 3 mod 4, end", n, half, time)
time+=half*x
break
else:
# print("Haven't doubled, ", n, time)
time+=n*x
break
print(time)
``` | output | 1 | 26,095 | 6 | 52,191 |
Provide tags and a correct Python 3 solution for this coding contest problem.
zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.
Initially, the text editor is empty. It takes him x seconds to insert or delete a letter 'a' from the text file and y seconds to copy the contents of the entire text file, and duplicate it.
zscoder wants to find the minimum amount of time needed for him to create the input file of exactly n letters 'a'. Help him to determine the amount of time needed to generate the input.
Input
The only line contains three integers n, x and y (1 ≤ n ≤ 107, 1 ≤ x, y ≤ 109) — the number of letters 'a' in the input file and the parameters from the problem statement.
Output
Print the only integer t — the minimum amount of time needed to generate the input file.
Examples
Input
8 1 1
Output
4
Input
8 1 10
Output
8 | instruction | 0 | 26,096 | 6 | 52,192 |
Tags: dfs and similar, dp
Correct Solution:
```
def main():
def f(t):
u = cache.get(t)
if u is None:
if t & 1:
u = min(f(t - 1), f(t + 1)) + x
else:
u = x * t
if y * 2 < u:
u = f(t // 2) + y
cache[t] = u
return u
n, x, y = map(int, input().split())
cache = {1: x}
print(f(n))
if __name__ == '__main__':
main()
``` | output | 1 | 26,096 | 6 | 52,193 |
Provide tags and a correct Python 3 solution for this coding contest problem.
zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.
Initially, the text editor is empty. It takes him x seconds to insert or delete a letter 'a' from the text file and y seconds to copy the contents of the entire text file, and duplicate it.
zscoder wants to find the minimum amount of time needed for him to create the input file of exactly n letters 'a'. Help him to determine the amount of time needed to generate the input.
Input
The only line contains three integers n, x and y (1 ≤ n ≤ 107, 1 ≤ x, y ≤ 109) — the number of letters 'a' in the input file and the parameters from the problem statement.
Output
Print the only integer t — the minimum amount of time needed to generate the input file.
Examples
Input
8 1 1
Output
4
Input
8 1 10
Output
8 | instruction | 0 | 26,097 | 6 | 52,194 |
Tags: dfs and similar, dp
Correct Solution:
```
def main():
def f(t):
if t & 1:
return x if t == 1 else min(f(t - 1), f(t + 1)) + x
else:
u = x * t
return f(t // 2) + y if y * 2 < u else u
n, x, y = map(int, input().split())
print(f(n))
if __name__ == '__main__':
main()
``` | output | 1 | 26,097 | 6 | 52,195 |
Provide tags and a correct Python 3 solution for this coding contest problem.
zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.
Initially, the text editor is empty. It takes him x seconds to insert or delete a letter 'a' from the text file and y seconds to copy the contents of the entire text file, and duplicate it.
zscoder wants to find the minimum amount of time needed for him to create the input file of exactly n letters 'a'. Help him to determine the amount of time needed to generate the input.
Input
The only line contains three integers n, x and y (1 ≤ n ≤ 107, 1 ≤ x, y ≤ 109) — the number of letters 'a' in the input file and the parameters from the problem statement.
Output
Print the only integer t — the minimum amount of time needed to generate the input file.
Examples
Input
8 1 1
Output
4
Input
8 1 10
Output
8 | instruction | 0 | 26,098 | 6 | 52,196 |
Tags: dfs and similar, dp
Correct Solution:
```
import sys
sys.setrecursionlimit(1000000)
def f(n):
if n == 1:
return x
elif n == 2:
return x + min(x, y)
else:
if n % 2 == 0:
return f(n // 2) + min(y, x * (n - n // 2))
else:
return min(f(n + 1), f(n - 1)) + x
n, x, y = map(int, input().split())
print(f(n))
``` | output | 1 | 26,098 | 6 | 52,197 |
Provide tags and a correct Python 3 solution for this coding contest problem.
zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.
Initially, the text editor is empty. It takes him x seconds to insert or delete a letter 'a' from the text file and y seconds to copy the contents of the entire text file, and duplicate it.
zscoder wants to find the minimum amount of time needed for him to create the input file of exactly n letters 'a'. Help him to determine the amount of time needed to generate the input.
Input
The only line contains three integers n, x and y (1 ≤ n ≤ 107, 1 ≤ x, y ≤ 109) — the number of letters 'a' in the input file and the parameters from the problem statement.
Output
Print the only integer t — the minimum amount of time needed to generate the input file.
Examples
Input
8 1 1
Output
4
Input
8 1 10
Output
8 | instruction | 0 | 26,099 | 6 | 52,198 |
Tags: dfs and similar, dp
Correct Solution:
```
import sys
sys.setrecursionlimit(100000)
from functools import lru_cache
@lru_cache()
def best(a):
if a == 1:
return x
elif a > 0:
if a == 2:
return x + min(x, y)
elif a % 2 == 0:
return best(a//2) + min(y, (a - a//2) * x)
else:
return min(best(a-1) , best(a+1) ) + x
n, x, y = map(int, input().split())
print(best(n))
``` | output | 1 | 26,099 | 6 | 52,199 |
Provide tags and a correct Python 3 solution for this coding contest problem.
zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.
Initially, the text editor is empty. It takes him x seconds to insert or delete a letter 'a' from the text file and y seconds to copy the contents of the entire text file, and duplicate it.
zscoder wants to find the minimum amount of time needed for him to create the input file of exactly n letters 'a'. Help him to determine the amount of time needed to generate the input.
Input
The only line contains three integers n, x and y (1 ≤ n ≤ 107, 1 ≤ x, y ≤ 109) — the number of letters 'a' in the input file and the parameters from the problem statement.
Output
Print the only integer t — the minimum amount of time needed to generate the input file.
Examples
Input
8 1 1
Output
4
Input
8 1 10
Output
8 | instruction | 0 | 26,100 | 6 | 52,200 |
Tags: dfs and similar, dp
Correct Solution:
```
def fi(n):
if n == 1:
return x
elif n == 2:
return x + min(x, y)
else:
if n % 2 == 1:
return min(fi(n-1), fi(n+1)) + x
else:
return fi(n//2) + min(y, x * (n//2))
n,x,y = map(int, input().split())
print(fi(n))
``` | output | 1 | 26,100 | 6 | 52,201 |
Provide tags and a correct Python 3 solution for this coding contest problem.
INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence of characters to print, using the following method.
The integers of the array are processed one by one, starting from the first. Processing i-th element of the array is done in three steps:
1. The 8-bit binary notation of the ASCII-code of the previous printed character is reversed. When the first element of the array is processed, the result of this step is considered to be 0.
2. The i-th element of the array is subtracted from the result of the previous step modulo 256.
3. The binary notation of the result of the previous step is reversed again to produce ASCII-code of the i-th character to be printed.
You are given the text printed using this method. Restore the array used to produce this text.
Input
The input will consist of a single line text which contains the message printed using the described method. String text will contain between 1 and 100 characters, inclusive. ASCII-code of each character of text will be between 32 (space) and 126 (tilde), inclusive.
Output
Output the initial array, which was used to produce text, one integer per line.
Examples
Input
Hello, World!
Output
238
108
112
0
64
194
48
26
244
168
24
16
162
Note
Let's have a closer look at the beginning of the example. The first character is "H" with ASCII-code 72 = 010010002. Its reverse is 000100102 = 18, and this number should become the result of the second step of processing. The result of the first step is considered to be 0, so the first element of the array has to be (0 - 18) mod 256 = 238, where a mod b is the remainder of division of a by b. | instruction | 0 | 26,689 | 6 | 53,378 |
Tags: implementation
Correct Solution:
```
n = input()
prev = 0
for i in n:
asci = ord(i)
binary = format(asci, '#010b')[2:][::-1]
num = int(binary, 2)
print((prev-num) % 256)
prev = num
``` | output | 1 | 26,689 | 6 | 53,379 |
Provide tags and a correct Python 3 solution for this coding contest problem.
INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence of characters to print, using the following method.
The integers of the array are processed one by one, starting from the first. Processing i-th element of the array is done in three steps:
1. The 8-bit binary notation of the ASCII-code of the previous printed character is reversed. When the first element of the array is processed, the result of this step is considered to be 0.
2. The i-th element of the array is subtracted from the result of the previous step modulo 256.
3. The binary notation of the result of the previous step is reversed again to produce ASCII-code of the i-th character to be printed.
You are given the text printed using this method. Restore the array used to produce this text.
Input
The input will consist of a single line text which contains the message printed using the described method. String text will contain between 1 and 100 characters, inclusive. ASCII-code of each character of text will be between 32 (space) and 126 (tilde), inclusive.
Output
Output the initial array, which was used to produce text, one integer per line.
Examples
Input
Hello, World!
Output
238
108
112
0
64
194
48
26
244
168
24
16
162
Note
Let's have a closer look at the beginning of the example. The first character is "H" with ASCII-code 72 = 010010002. Its reverse is 000100102 = 18, and this number should become the result of the second step of processing. The result of the first step is considered to be 0, so the first element of the array has to be (0 - 18) mod 256 = 238, where a mod b is the remainder of division of a by b. | instruction | 0 | 26,690 | 6 | 53,380 |
Tags: implementation
Correct Solution:
```
def f(x):
return int(format(256 + x, 'b')[:: -1][: -1], 2)
t, x = input(), 0
for i in t:
y = f(ord(i))
print((x - y) % 256)
x = y
# Made By Mostafa_Khaled
``` | output | 1 | 26,690 | 6 | 53,381 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.