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. Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there. The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe. And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure: * if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively); * if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code; * if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits. * The length of the safe code coincides with the length of the hint. For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666". After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint. At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night... Input The first line contains string s β€” the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0. The input limits for scoring 30 points are (subproblem A1): * 1 ≀ |s| ≀ 5. The input limits for scoring 100 points are (subproblems A1+A2): * 1 ≀ |s| ≀ 105. Here |s| means the length of string s. Output Print the number of codes that match the given hint. Examples Input AJ Output 81 Input 1?AA Output 100
instruction
0
32,837
6
65,674
Tags: math Correct Solution: ``` def main(): s=input() l=[] t='' result=1 count=0 for i in range(len(s)): if s[i:i+1]=='?': if i==0: result=result*9 else: count=count+1 if s[i:i+1]>='A' and s[i:i+1]<='J': if i==0: result=result*9 l.append(s[i:i+1]) else: if l.count(s[i:i+1])==0: result=result*(10-len(l)) l.append(s[i:i+1]) for j in range (count): t=t+'0' print(str(result)+t) if __name__=='__main__': main() ```
output
1
32,837
6
65,675
Provide tags and a correct Python 3 solution for this coding contest problem. Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. <image> English alphabet You are given a string s. Check if the string is "s-palindrome". Input The only line contains the string s (1 ≀ |s| ≀ 1000) which consists of only English letters. Output Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise. Examples Input oXoxoXo Output TAK Input bod Output TAK Input ER Output NIE
instruction
0
33,005
6
66,010
Tags: implementation, strings Correct Solution: ``` # Author : nitish420 -------------------------------------------------------------------- import os import sys from io import BytesIO, IOBase mod=10**9+7 # sys.setrecursionlimit(10**6) # from functools import lru_cache def main(): s=list(input()) n=len(s) # print(n) ans="TAK" l=n//2 r=n//2-1+n%2 while r<n: check=list(set([s[l],s[r]])) check.sort() if len(check)==1: i=check[0] if i in "AHIMOoTUVvWwXxY": pass else: ans="NIE" break else: if check==['b','d']: pass elif check==['p','q']: pass else: ans="NIE" break l-=1 r+=1 print(ans) #---------------------------------------------------------------------------------------- def nouse0(): # This is to save my code from plag due to use of FAST IO template in it. a=420 b=420 print(f'i am nitish{(a+b)//2}') def nouse1(): # This is to save my code from plag due to use of FAST IO template in it. a=420 b=420 print(f'i am nitish{(a+b)//2}') def nouse2(): # This is to save my code from plag due to use of FAST IO template in it. a=420 b=420 print(f'i am nitish{(a+b)//2}') # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = 'x' in file.mode or 'r' not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b'\n') + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode('ascii')) self.read = lambda: self.buffer.read().decode('ascii') self.readline = lambda: self.buffer.readline().decode('ascii') sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip('\r\n') def nouse3(): # This is to save my code from plag due to use of FAST IO template in it. a=420 b=420 print(f'i am nitish{(a+b)//2}') def nouse4(): # This is to save my code from plag due to use of FAST IO template in it. a=420 b=420 print(f'i am nitish{(a+b)//2}') def nouse5(): # This is to save my code from plag due to use of FAST IO template in it. a=420 b=420 print(f'i am nitish{(a+b)//2}') # endregion if __name__ == '__main__': main() ```
output
1
33,005
6
66,011
Provide tags and a correct Python 3 solution for this coding contest problem. ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice. Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him? Input The first and only line of the input contains a single string s (1 ≀ |s| ≀ 50 000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember. Output If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print - 1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them. Examples Input ABC??FGHIJK???OPQR?TUVWXY? Output ABCDEFGHIJKLMNOPQRZTUVWXYS Input WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO Output -1 Input ?????????????????????????? Output MNBVCXZLKJHGFDSAQPWOEIRUYT Input AABCDEFGHIJKLMNOPQRSTUVW??M Output -1 Note In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS. In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is - 1. In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
instruction
0
33,018
6
66,036
Tags: greedy, two pointers Correct Solution: ``` def fill_uniq(nice,cts): l_nice = list(nice) letters = [chr(ord('A')+i) for i in range(26) if not cts[i]] l_i = 0 for i,c in enumerate(l_nice): if c == '?': l_nice[i] = letters[l_i] l_i += 1 return ''.join(l_nice) def ans(s, i, cts): nice = s[i:i+26] return s[:i].replace('?','A') + fill_uniq(nice,cts) + s[i+26:].replace('?','A') def main(): s = input() if len(s) < 26: print(-1) return cts = [0]*26 for c in s[:26]: if c == '?': continue cts[ord(c)-ord('A')] += 1 max_ct = max(cts) if max_ct <= 1: print(ans(s,0,cts)) return for i in range(1,len(s) - 26+1): if s[i-1] != '?': cts[ord(s[i-1]) - ord('A')] -= 1 if s[i+25] != '?': cts[ord(s[i+25]) - ord('A')] += 1 #print(s[i-1], i,cts,sum(cts)) max_ct = max(cts) if max_ct <= 1: print(ans(s,i,cts)) return print(-1) main() ```
output
1
33,018
6
66,037
Provide tags and a correct Python 3 solution for this coding contest problem. ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice. Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him? Input The first and only line of the input contains a single string s (1 ≀ |s| ≀ 50 000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember. Output If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print - 1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them. Examples Input ABC??FGHIJK???OPQR?TUVWXY? Output ABCDEFGHIJKLMNOPQRZTUVWXYS Input WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO Output -1 Input ?????????????????????????? Output MNBVCXZLKJHGFDSAQPWOEIRUYT Input AABCDEFGHIJKLMNOPQRSTUVW??M Output -1 Note In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS. In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is - 1. In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
instruction
0
33,019
6
66,038
Tags: greedy, two pointers Correct Solution: ``` from collections import Counter from string import ascii_uppercase s = input() counter = Counter(s[:25]) for j in range(25, len(s)): counter[s[j]] += 1 if j >= 26: counter.subtract(s[j-26]) q = [] for l in ascii_uppercase: if counter[l] == 0: q.append(l) if counter['?'] < len(q): continue else: output = '' i = 0 for c in s[:j - 25]: if c == '?': output += 'A' else: output += c for c in s[j - 25 : j + 1]: if c == '?': output += q[i] i += 1 else: output += c for c in s[j + 1 :]: if c == '?': output += 'A' else: output += c print(output) exit() print('-1') ```
output
1
33,019
6
66,039
Provide tags and a correct Python 3 solution for this coding contest problem. ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice. Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him? Input The first and only line of the input contains a single string s (1 ≀ |s| ≀ 50 000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember. Output If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print - 1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them. Examples Input ABC??FGHIJK???OPQR?TUVWXY? Output ABCDEFGHIJKLMNOPQRZTUVWXYS Input WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO Output -1 Input ?????????????????????????? Output MNBVCXZLKJHGFDSAQPWOEIRUYT Input AABCDEFGHIJKLMNOPQRSTUVW??M Output -1 Note In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS. In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is - 1. In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
instruction
0
33,020
6
66,040
Tags: greedy, two pointers Correct Solution: ``` from collections import Counter s = input() counter = Counter(s[:26]) left, right = 0, 0 if len(counter) - int("?" in counter) + counter["?"] == 26: left, right = 0, 26 else: for i in range(26, len(s)): counter[s[i]] += 1 counter[s[i-26]] -= 1 if counter[s[i-26]] == 0: del counter[s[i-26]] if len(counter) - int("?" in counter) + counter["?"] == 26: left, right = i - 25, i + 1 break if right: a = set("ABCDEFGHIJKLMNOPQRSTUVWXYZ") - counter.keys() ans = "" for i in range(len(s)): if s[i] == "?": if left <= i < right: ans += a.pop() else: ans += "A" else: ans += s[i] print(ans) else: print("-1") ```
output
1
33,020
6
66,041
Provide tags and a correct Python 3 solution for this coding contest problem. ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice. Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him? Input The first and only line of the input contains a single string s (1 ≀ |s| ≀ 50 000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember. Output If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print - 1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them. Examples Input ABC??FGHIJK???OPQR?TUVWXY? Output ABCDEFGHIJKLMNOPQRZTUVWXYS Input WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO Output -1 Input ?????????????????????????? Output MNBVCXZLKJHGFDSAQPWOEIRUYT Input AABCDEFGHIJKLMNOPQRSTUVW??M Output -1 Note In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS. In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is - 1. In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
instruction
0
33,021
6
66,042
Tags: greedy, two pointers Correct Solution: ``` import collections def GetWord(word,start_index,letter_dict,letters): good_word = '' for i in range(start_index): if word[i] != '?': good_word += word[i] else: good_word += 'A' for i in range(start_index,start_index+26): if word[i] != '?': good_word += word[i] else: for j in range(26): if letter_dict[letters[j]] == 0: good_word += letters[j] #print (letter_dict[letters[j]],letters[j]) letter_dict[letters[j]] += 1 #print (letter_dict[letters[j]]) break #print (letter_dict) for i in range(start_index+26,len(word)): if word[i] != '?': good_word += word[i] else: good_word += 'A' return good_word def CompleteWord(): word = input() letter_count = {} letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' for i in letters: letter_count[i] = 0 n = len(word) letter_count = dict(collections.OrderedDict(sorted(letter_count.items()))) #print (letter_count) for i in range(n-25): letter_count_temp = letter_count.copy() count = 0 for j in range(i,i+26): if word[j] != '?': letter_count_temp[word[j]] += 1 else: count += 1 total = 0 count1 = 0 for k in letter_count_temp: if letter_count_temp[k] == 1 or letter_count_temp[k] == 0: total += 1 if letter_count_temp[k] == 0: count1 += 1 if total == 26: if count == count1: return GetWord(word,i,letter_count_temp,letters) return '-1' print (CompleteWord()) ```
output
1
33,021
6
66,043
Provide tags and a correct Python 3 solution for this coding contest problem. ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice. Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him? Input The first and only line of the input contains a single string s (1 ≀ |s| ≀ 50 000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember. Output If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print - 1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them. Examples Input ABC??FGHIJK???OPQR?TUVWXY? Output ABCDEFGHIJKLMNOPQRZTUVWXYS Input WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO Output -1 Input ?????????????????????????? Output MNBVCXZLKJHGFDSAQPWOEIRUYT Input AABCDEFGHIJKLMNOPQRSTUVW??M Output -1 Note In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS. In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is - 1. In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
instruction
0
33,022
6
66,044
Tags: greedy, two pointers Correct Solution: ``` s = input() left = 0 counter = 0 arr = [0]*26 if (len(s) < 26): print(-1) else: for i in range(len(s)): if (s[i] != '?'): while (arr[ord(s[i]) - ord('A')] == 1): if (s[left] != '?'): arr[ord(s[left]) - ord('A')] = 0 left = left + 1 counter -= 1 arr[ord(s[i]) - ord('A')] = 1 counter += 1 if (counter == 26): break if (counter == 26): guesses = [] for i in range(26): if (arr[i] != 1): guesses.append(chr(i + ord('A'))) characters = [] for i in range(len(s)): if (i < left or i > left + 25): if (s[i] == '?'): characters.append('A') else: characters.append(s[i]) else: if (s[i] == '?'): characters.append(guesses.pop()) else: characters.append(s[i]) print(''.join(characters)) else: print(-1) ```
output
1
33,022
6
66,045
Provide tags and a correct Python 3 solution for this coding contest problem. ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice. Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him? Input The first and only line of the input contains a single string s (1 ≀ |s| ≀ 50 000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember. Output If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print - 1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them. Examples Input ABC??FGHIJK???OPQR?TUVWXY? Output ABCDEFGHIJKLMNOPQRZTUVWXYS Input WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO Output -1 Input ?????????????????????????? Output MNBVCXZLKJHGFDSAQPWOEIRUYT Input AABCDEFGHIJKLMNOPQRSTUVW??M Output -1 Note In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS. In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is - 1. In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
instruction
0
33,023
6
66,046
Tags: greedy, two pointers Correct Solution: ``` s=list(input()) n=len(s) if n<26: print(-1) else: a=[0]*26 c=0 j=0 x,y=-1,-1 for q in range(26): if s[q]=='?': j+=1 else: a[ord(s[q])-65]+=1 if a[ord(s[q])-65]==1: c+=1 if j+c==26: x,y=0,25 else: for q in range(26,n): if s[q-26]=='?': j-=1 else: a[ord(s[q-26])-65]-=1 if a[ord(s[q-26])-65]==0: c-=1 if s[q]=='?': j+=1 else: a[ord(s[q])-65]+=1 if a[ord(s[q])-65]==1: c+=1 if j+c==26: x,y=q-26+1,q break if x==-1: print(-1) else: for q in range(x): if s[q]=='?': s[q]='A' for q in range(y+1,n): if s[q]=='?': s[q]='A' w=0 #print(l) #print(x,y) for q in range(x,y+1): if s[q]=='?': while a[w]: w+=1 s[q]=chr(65+w) w+=1 print(''.join(s)) ```
output
1
33,023
6
66,047
Provide tags and a correct Python 3 solution for this coding contest problem. ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice. Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him? Input The first and only line of the input contains a single string s (1 ≀ |s| ≀ 50 000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember. Output If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print - 1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them. Examples Input ABC??FGHIJK???OPQR?TUVWXY? Output ABCDEFGHIJKLMNOPQRZTUVWXYS Input WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO Output -1 Input ?????????????????????????? Output MNBVCXZLKJHGFDSAQPWOEIRUYT Input AABCDEFGHIJKLMNOPQRSTUVW??M Output -1 Note In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS. In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is - 1. In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
instruction
0
33,024
6
66,048
Tags: greedy, two pointers Correct Solution: ``` def main(): s, cnt = input(), [-1] * 91 l = s.encode('utf-8') for c in l[:25]: cnt[c] += 1 twins, cnt[63] = sum(i > 0 for i in cnt[65:]), -27 for i, u, v in zip(range(50000), l, l[25:]): cnt[v] = c = cnt[v] + 1 if c == 1: twins += 1 elif not twins: res = [s[:i].replace('?', 'A')] for c in filter(cnt.__getitem__, range(65, 91)): while c: a = l[i] if a == 63: a, c = c, 0 res.append(chr(a)) i += 1 res.append(s[i:].replace('?', 'A')) return print(*res, sep='') cnt[u] = c = cnt[u] - 1 if not c: twins -= 1 print(-1) if __name__ == '__main__': main() ```
output
1
33,024
6
66,049
Provide tags and a correct Python 3 solution for this coding contest problem. ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice. Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him? Input The first and only line of the input contains a single string s (1 ≀ |s| ≀ 50 000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember. Output If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print - 1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them. Examples Input ABC??FGHIJK???OPQR?TUVWXY? Output ABCDEFGHIJKLMNOPQRZTUVWXYS Input WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO Output -1 Input ?????????????????????????? Output MNBVCXZLKJHGFDSAQPWOEIRUYT Input AABCDEFGHIJKLMNOPQRSTUVW??M Output -1 Note In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS. In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is - 1. In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
instruction
0
33,025
6
66,050
Tags: greedy, two pointers Correct Solution: ``` s = input() marks = 0 alphabit = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" missed = '' sub_s = '' s_length = len(s) i = 0 while (i+26) <= s_length: marks = 0 missed = '' sub_s = s[i:(i+26)] for ch in alphabit: if ch not in sub_s: missed += ch marks = sub_s.count('?') if marks >= len(missed): sub_s = sub_s[::-1] for ch in missed[::-1]: sub_s = sub_s.replace('?', ch, 1) s = s[:i] + sub_s[::-1] + s[i+26:] s = s.replace('?', 'A') print(s) exit(0) i+=1 print(-1) ```
output
1
33,025
6
66,051
Provide tags and a correct Python 3 solution for this coding contest problem. One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written. As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 ≀ i < j ≀ n, 1 ≀ k ≀ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD". You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7). Input The first input line contains two integers n and m (1 ≀ n, m ≀ 100) β€” the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters. Output Print the single number β€” the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7). Examples Input 2 3 AAB BAA Output 4 Input 4 5 ABABA BCGDG AAAAA YABSA Output 216 Note In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
instruction
0
33,619
6
67,238
Tags: combinatorics Correct Solution: ``` def solve(): mod=int(1e9+7) line=input().split(' ') n=int(line[0]) m=int(line[1]) lista = [set() for _ in range(m)] for i in range(n): string=input(); for j in range(m): if(string[j] in lista[j]): pass else: lista[j].add(string[j]) result=1 for i in range(m): result=result*len(lista[i]) result=result%mod print(result) solve() ```
output
1
33,619
6
67,239
Provide tags and a correct Python 3 solution for this coding contest problem. One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written. As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 ≀ i < j ≀ n, 1 ≀ k ≀ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD". You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7). Input The first input line contains two integers n and m (1 ≀ n, m ≀ 100) β€” the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters. Output Print the single number β€” the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7). Examples Input 2 3 AAB BAA Output 4 Input 4 5 ABABA BCGDG AAAAA YABSA Output 216 Note In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
instruction
0
33,620
6
67,240
Tags: combinatorics Correct Solution: ``` from collections import defaultdict n,m=map(int,input().split()) d=defaultdict(set) for i in range(n): s=input() for j in range(m): d[j].add(s[j]) ans=1 for i in d: ans*=len(d[i]) ans%=(10**9+7) print(ans) ```
output
1
33,620
6
67,241
Provide tags and a correct Python 3 solution for this coding contest problem. <image> You can preview the image in better quality by the link: [http://assets.codeforces.com/files/656/without-text.png](//assets.codeforces.com/files/656/without-text.png) Input The only line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be an alphanumeric character or a full stop ".". Output Output the required answer. Examples Input Codeforces Output -87 Input APRIL.1st Output 17
instruction
0
33,843
6
67,686
Tags: *special Correct Solution: ``` __author__ = "runekri3" ALPHABET_LOWER = "abcdefghijklmnopqrstuvwxyz" ALPHABET_HIGHER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" inp_str = input() answer = 0 for letter in inp_str: if letter in ALPHABET_HIGHER: answer += ALPHABET_HIGHER.index(letter) + 1 elif letter in ALPHABET_LOWER: answer -= (ALPHABET_LOWER.index(letter) + 1) print(answer) ```
output
1
33,843
6
67,687
Provide tags and a correct Python 3 solution for this coding contest problem. <image> You can preview the image in better quality by the link: [http://assets.codeforces.com/files/656/without-text.png](//assets.codeforces.com/files/656/without-text.png) Input The only line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be an alphanumeric character or a full stop ".". Output Output the required answer. Examples Input Codeforces Output -87 Input APRIL.1st Output 17
instruction
0
33,844
6
67,688
Tags: *special Correct Solution: ``` def f(c): v1 = c > '@' v2 = c < '[' v3 = c > '`' v4 = c < '{' v5 = int(v1 and v2) v6 = int(v3 and v4) if c in '.0123456789': v7 = -1 else: v7 = 'abcdefghijklmnopqrstuvwxyz'.index(c.lower()) + 1 v8 = v5 * v7 v9 = v6 * v7 return v8 - v9 line = input() res = 0 for c in line: res += f(c) print(res) ```
output
1
33,844
6
67,689
Provide tags and a correct Python 3 solution for this coding contest problem. <image> You can preview the image in better quality by the link: [http://assets.codeforces.com/files/656/without-text.png](//assets.codeforces.com/files/656/without-text.png) Input The only line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be an alphanumeric character or a full stop ".". Output Output the required answer. Examples Input Codeforces Output -87 Input APRIL.1st Output 17
instruction
0
33,845
6
67,690
Tags: *special Correct Solution: ``` '''s=input() ans=0 for i in s[1:len(s)]: p1=1 if '@'<i else 0; p2=1 if '['>i else 0; p3=1 if '`'<i else 0; p4=1 if '{'>i else 0; p1=1 if p1==p2 and p1==1 else 0; p3=1 if p3==p4 and p4==1 else 0; if i.isupper(): p5=ord(i)-64 elif ''' s=input() ans=0; for i in s: if i.isupper(): ans+=ord(i)-64; elif i.islower(): ans-=ord(i)-96; print(ans) ```
output
1
33,845
6
67,691
Provide tags and a correct Python 3 solution for this coding contest problem. <image> You can preview the image in better quality by the link: [http://assets.codeforces.com/files/656/without-text.png](//assets.codeforces.com/files/656/without-text.png) Input The only line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be an alphanumeric character or a full stop ".". Output Output the required answer. Examples Input Codeforces Output -87 Input APRIL.1st Output 17
instruction
0
33,846
6
67,692
Tags: *special Correct Solution: ``` s = input() ans = 0 for i in range(0, len(s)): if (s[i] >= 'a' and s[i] <= 'z'): ans -= ord(s[i]) - ord('a') + 1 elif (s[i] >= 'A' and s[i] <= 'Z'): ans += ord(s[i]) - ord('A') + 1 print(ans) ```
output
1
33,846
6
67,693
Provide tags and a correct Python 3 solution for this coding contest problem. <image> You can preview the image in better quality by the link: [http://assets.codeforces.com/files/656/without-text.png](//assets.codeforces.com/files/656/without-text.png) Input The only line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be an alphanumeric character or a full stop ".". Output Output the required answer. Examples Input Codeforces Output -87 Input APRIL.1st Output 17
instruction
0
33,847
6
67,694
Tags: *special Correct Solution: ``` s = input() ans = 0 for c in s: ind = ord(c) if 'a' <= c <= 'z': ans -= ind - ord('a') + 1 elif 'A' <= c <= 'Z': ans += ind - ord('A') + 1 print(ans) ```
output
1
33,847
6
67,695
Provide tags and a correct Python 3 solution for this coding contest problem. <image> You can preview the image in better quality by the link: [http://assets.codeforces.com/files/656/without-text.png](//assets.codeforces.com/files/656/without-text.png) Input The only line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be an alphanumeric character or a full stop ".". Output Output the required answer. Examples Input Codeforces Output -87 Input APRIL.1st Output 17
instruction
0
33,848
6
67,696
Tags: *special Correct Solution: ``` print(sum(ch.isupper() * (ord(ch) - ord('A') + 1) - ch.islower() * (ord(ch) - ord('a') + 1) for ch in input())) ```
output
1
33,848
6
67,697
Provide tags and a correct Python 3 solution for this coding contest problem. <image> You can preview the image in better quality by the link: [http://assets.codeforces.com/files/656/without-text.png](//assets.codeforces.com/files/656/without-text.png) Input The only line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be an alphanumeric character or a full stop ".". Output Output the required answer. Examples Input Codeforces Output -87 Input APRIL.1st Output 17
instruction
0
33,849
6
67,698
Tags: *special Correct Solution: ``` print(sum(map(lambda x:96-x if x>96 else x-64,map(ord,filter(str.isalpha,input()))))) ```
output
1
33,849
6
67,699
Provide tags and a correct Python 3 solution for this coding contest problem. <image> You can preview the image in better quality by the link: [http://assets.codeforces.com/files/656/without-text.png](//assets.codeforces.com/files/656/without-text.png) Input The only line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be an alphanumeric character or a full stop ".". Output Output the required answer. Examples Input Codeforces Output -87 Input APRIL.1st Output 17
instruction
0
33,850
6
67,700
Tags: *special Correct Solution: ``` s = input() ans = 0 for i in s: if (i >= 'A') and (i <= 'Z'): ans += ord(i) - ord('A') + 1 elif (i >= 'a') and (i <= 'z'): ans -= ord(i) - ord('a') + 1 print(ans) ```
output
1
33,850
6
67,701
Provide tags and a correct Python 3 solution for this coding contest problem. There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts. * Current character pointer (CP); * Direction pointer (DP) which can point left or right; Initially CP points to the leftmost character of the sequence and DP points to the right. We repeat the following steps until the first moment that CP points to somewhere outside the sequence. * If CP is pointing to a digit the interpreter prints that digit then CP moves one step according to the direction of DP. After that the value of the printed digit in the sequence decreases by one. If the printed digit was 0 then it cannot be decreased therefore it's erased from the sequence and the length of the sequence decreases by one. * If CP is pointing to "<" or ">" then the direction of DP changes to "left" or "right" correspondingly. Then CP moves one step according to DP. If the new character that CP is pointing to is "<" or ">" then the previous character will be erased from the sequence. If at any moment the CP goes outside of the sequence the execution is terminated. It's obvious the every program in this language terminates after some steps. We have a sequence s1, s2, ..., sn of "<", ">" and digits. You should answer q queries. Each query gives you l and r and asks how many of each digit will be printed if we run the sequence sl, sl + 1, ..., sr as an independent program in this language. Input The first line of input contains two integers n and q (1 ≀ n, q ≀ 105) β€” represents the length of the sequence s and the number of queries. The second line contains s, a sequence of "<", ">" and digits (0..9) written from left to right. Note, that the characters of s are not separated with spaces. The next q lines each contains two integers li and ri (1 ≀ li ≀ ri ≀ n) β€” the i-th query. Output For each query print 10 space separated integers: x0, x1, ..., x9 where xi equals the number of times the interpreter prints i while running the corresponding program. Print answers to the queries in the order they are given in input. Examples Input 7 4 1&gt;3&gt;22&lt; 1 3 4 7 7 7 1 7 Output 0 1 0 1 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 2 1 0 0 0 0 0 0
instruction
0
35,443
6
70,886
Tags: data structures, implementation Correct Solution: ``` n, q = map(int, input().split()) s = input() for _ in range(q): l, r = map(int, input().split()) t = list(s[l-1:r]) p, d = 0, 1 res = [0] * 10 while 0 <= p < len(t): if '0' <= t[p] <= '9': k = int(t[p]) res[k] += 1 if k > 0: t[p] = str(k-1) p += d else: t.pop(p) if d == -1: p += d else: d = -1 if t[p] == '<' else 1 if 0 <= p+d < len(t) and not ('0' <= t[p+d] <= '9'): t.pop(p) if d == -1: p += d else: p += d print(*res) ```
output
1
35,443
6
70,887
Provide tags and a correct Python 3 solution for this coding contest problem. There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts. * Current character pointer (CP); * Direction pointer (DP) which can point left or right; Initially CP points to the leftmost character of the sequence and DP points to the right. We repeat the following steps until the first moment that CP points to somewhere outside the sequence. * If CP is pointing to a digit the interpreter prints that digit then CP moves one step according to the direction of DP. After that the value of the printed digit in the sequence decreases by one. If the printed digit was 0 then it cannot be decreased therefore it's erased from the sequence and the length of the sequence decreases by one. * If CP is pointing to "<" or ">" then the direction of DP changes to "left" or "right" correspondingly. Then CP moves one step according to DP. If the new character that CP is pointing to is "<" or ">" then the previous character will be erased from the sequence. If at any moment the CP goes outside of the sequence the execution is terminated. It's obvious the every program in this language terminates after some steps. We have a sequence s1, s2, ..., sn of "<", ">" and digits. You should answer q queries. Each query gives you l and r and asks how many of each digit will be printed if we run the sequence sl, sl + 1, ..., sr as an independent program in this language. Input The first line of input contains two integers n and q (1 ≀ n, q ≀ 105) β€” represents the length of the sequence s and the number of queries. The second line contains s, a sequence of "<", ">" and digits (0..9) written from left to right. Note, that the characters of s are not separated with spaces. The next q lines each contains two integers li and ri (1 ≀ li ≀ ri ≀ n) β€” the i-th query. Output For each query print 10 space separated integers: x0, x1, ..., x9 where xi equals the number of times the interpreter prints i while running the corresponding program. Print answers to the queries in the order they are given in input. Examples Input 7 4 1&gt;3&gt;22&lt; 1 3 4 7 7 7 1 7 Output 0 1 0 1 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 2 1 0 0 0 0 0 0
instruction
0
35,444
6
70,888
Tags: data structures, implementation Correct Solution: ``` n,Q = map(int,input().strip().split()) s = input() d = 1 for q in range(Q): arr = [0]*(10) l,r = map(int,input().strip().split()) su = "" for i in range(l-1,r): su+=s[i] su = list(su) i = 0 d = 1 #print(su) ll = 0 while i<len(su) and i>=0: if su[i].isdigit(): arr[int(su[i])]+=1 if su[i]=='0': su = su[:i]+su[i+1:] if d==1: i-=1 else: su[i] = str(int(su[i])-1) if d==1: i+=1 else: i-=1; ll = 0 else: if su[i]=='>' or su[i]=='<': if d==1 and i!=0 and ll == 1: if su[i-1]=='>' or su[i-1]=='<': su = su[:i-1]+su[i:] i-=1 if d==0 and i!=n-1 and ll==1: if su[i+1]=='>' or su[i+1]=='<' or su[i+1]=='-1': su = su[:i+1]+su[i+2:] if su[i]=='>': d = 1 else: d = 0 if d==0: i-=1; else: i+=1 ll = 1 #print(su,i,d) #print(arr) #print(su) print(*arr) ```
output
1
35,444
6
70,889
Provide tags and a correct Python 3 solution for this coding contest problem. Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message. Input First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. Output Print a line that contains the original message. Examples Input R s;;upimrrfod;pbr Output allyouneedislove
instruction
0
35,540
6
71,080
Tags: implementation Correct Solution: ``` #!/usr/bin/env python3 import sys keyboard = "qwertyuiopasdfghjkl;zxcvbnm,./" right = "pqwertyuio;asdfghjkl/zxcvbnm,." left = "wertyuiopqsdfghjkl;axcvbnm,./z" def decrypt(shift, message): table = str.maketrans(keyboard, right if shift == 'R' else left) message = message.translate(table) return message if __name__ == "__main__": input = sys.stdin.read() shift, message = input.split() print(decrypt(shift, message)) """ qwertyuiop asdfghjkl; zxcvbnm,./ """ ```
output
1
35,540
6
71,081
Provide tags and a correct Python 3 solution for this coding contest problem. Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message. Input First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. Output Print a line that contains the original message. Examples Input R s;;upimrrfod;pbr Output allyouneedislove
instruction
0
35,541
6
71,082
Tags: implementation Correct Solution: ``` # Lang: pypy3.6-v7.1.0-win32\pypy3.exe # Problem Name: Keyboard # Problem Serial No: 474 # Problem Type: A # Problem Url: https://codeforces.com/problemset/problem/474/A # Solution Generated at: 2019-09-17 20:19:20.119275 UTC keyboard = [j for j in """qwertyuiop[]asdfghjkl;'zxcvbnm,./"""] side = input() strokes = input() if side == "R": print("".join(map(str, [keyboard[keyboard.index(k) - 1] for k in strokes]))) else: print("".join(map(str, [keyboard[keyboard.index(k) + 1] for k in strokes]))) # Accepted ```
output
1
35,541
6
71,083
Provide tags and a correct Python 3 solution for this coding contest problem. Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message. Input First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. Output Print a line that contains the original message. Examples Input R s;;upimrrfod;pbr Output allyouneedislove
instruction
0
35,542
6
71,084
Tags: implementation Correct Solution: ``` s1 = 'qwertyuiopasdfghjkl;zxcvbnm,./' d = input() s = input() ans = [] if d == 'R': for i in s: ans.append(s1[s1.index(i) - 1]) else: for i in s: ans.append(s1[s1.index(i) + 1]) print(*ans, sep = '') ```
output
1
35,542
6
71,085
Provide tags and a correct Python 3 solution for this coding contest problem. Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message. Input First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. Output Print a line that contains the original message. Examples Input R s;;upimrrfod;pbr Output allyouneedislove
instruction
0
35,543
6
71,086
Tags: implementation Correct Solution: ``` s="qwertyuiopasdfghjkl;zxcvbnm,./" c,r,ans=input(),input(),"" if(c=="R"): for i in range(len(r)): ans+=s[s.find(r[i])-1] else: for i in range(len(r)): ans+=s[s.find(r[i])+1] print(ans) ```
output
1
35,543
6
71,087
Provide tags and a correct Python 3 solution for this coding contest problem. Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message. Input First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. Output Print a line that contains the original message. Examples Input R s;;upimrrfod;pbr Output allyouneedislove
instruction
0
35,544
6
71,088
Tags: implementation Correct Solution: ``` n = input() keyboard = "qwertyuiopasdfghjkl;zxcvbnm,./" index_map = { c: keyboard.index(c) for c in keyboard } s = input() shift = -1 if n == 'R' else 1 ans = '' for c in s: index = index_map.get(c) + shift ans += keyboard[index] print(ans) ```
output
1
35,544
6
71,089
Provide tags and a correct Python 3 solution for this coding contest problem. Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message. Input First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. Output Print a line that contains the original message. Examples Input R s;;upimrrfod;pbr Output allyouneedislove
instruction
0
35,545
6
71,090
Tags: implementation Correct Solution: ``` a,b,c='qwertyuiopasdfghjkl;zxcvbnm,./',input(),input();print(''.join(a[a.index(i)+1] for i in c) if b=='L' else ''.join(a[a.index(i)-1] for i in c)) ```
output
1
35,545
6
71,091
Provide tags and a correct Python 3 solution for this coding contest problem. Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message. Input First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. Output Print a line that contains the original message. Examples Input R s;;upimrrfod;pbr Output allyouneedislove
instruction
0
35,546
6
71,092
Tags: implementation Correct Solution: ``` """ *** Author--Saket Saumya *** IIITM """ import math import os import random import re from sys import stdin, stdout from collections import Counter from itertools import permutations def si(): return str(stdin.readline()) def ii(): return int(stdin.readline()) def mi(): return map(int, stdin.readline().split()) def li(): return list(mi()) def debug(x): return stdout.write(str(x)) arr=['q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l',';','z','x','c','v','b','n','m',',','.','/'] rightdict={} leftdict={} for i in range(len(arr)): rightdict[arr[i]]=arr[i-1] for i in range(len(arr)-1): leftdict[arr[i]]=arr[i+1] #print(rightdict) t=input() s=si() ansr=[] ansl=[] if t=="R": for j in range(len(s)): for i in rightdict: if s[j]==i: ansr.append(rightdict[i]) #print(ansr) print(''.join(str(e) for e in ansr)) if t=="L": for j in range(len(s)): for i in leftdict: if s[j]==i: ansl.append(leftdict[i]) print(''.join(str(e) for e in ansl)) ```
output
1
35,546
6
71,093
Provide tags and a correct Python 3 solution for this coding contest problem. Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message. Input First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. Output Print a line that contains the original message. Examples Input R s;;upimrrfod;pbr Output allyouneedislove
instruction
0
35,547
6
71,094
Tags: implementation Correct Solution: ``` s = 'qwertyuiop asdfghjkl; zxcvbnm,./' mod = input() txt = input() if mod=='R': pre = {s[i]:s[i-1] for i in range(1,len(s))} else: pre = {s[i]:s[i+1] for i in range(0,len(s)-1)} print(''.join(pre[c] for c in txt)) ```
output
1
35,547
6
71,095
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message. Input First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. Output Print a line that contains the original message. Examples Input R s;;upimrrfod;pbr Output allyouneedislove Submitted Solution: ``` R={'q':'p','w':'q','e':'w','r':'e','t':'r','y':'t','u':'y','i':'u','o':'i','p':'o', 'a':';','s':'a','d':'s','f':'d','g':'f','h':'g','j':'h','k':'j','l':'k',';':'l', 'z':'/','x':'z','c':'x','v':'c','b':'v','n':'b','m':'n',',':'m','.':',','/':'.'} L={'q':'w','w':'e','e':'r','r':'t','t':'y','y':'u','u':'i','i':'o','o':'p','p':'q', 'a':'s','s':'d','d':'f','f':'g','g':'h','h':'j','j':'k','k':'l','l':';',';':'a', 'z':'x','x':'c','c':'v','v':'b','b':'n','n':'m','m':',',',':'.','.':'/','/':'z'} direction =input() sent=input() mess=[] if direction =='R': for i in sent: mess.append(R[i]) else: for i in sent: mess.append(L[i]) print("".join(mess)) ```
instruction
0
35,550
6
71,100
Yes
output
1
35,550
6
71,101
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message. Input First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. Output Print a line that contains the original message. Examples Input R s;;upimrrfod;pbr Output allyouneedislove Submitted Solution: ``` dir = input().strip() seq = input().strip() keyboard = 'qwertyuiopasdfghjkl;zxcvbnm,./' chToPos = {} for i in range( len(keyboard) ): chToPos[ keyboard[i] ] = i offset = 1 if dir == 'L' else -1 ans = '' for c in seq: ans += keyboard[ offset + chToPos[c] ] print(ans) ```
instruction
0
35,551
6
71,102
Yes
output
1
35,551
6
71,103
Provide tags and a correct Python 3 solution for this coding contest problem. Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once. Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome. You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string. Input The first line of the input contains a positive integer n (1 ≀ n ≀ 100) β€” the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings. Output In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. Examples Input 3 bcd ab cdef Output abcdef Input 4 x y z w Output xyzw
instruction
0
35,592
6
71,184
Tags: *special, dfs and similar, strings Correct Solution: ``` n=int(input()) d={} p={} ans='' for x in [input() for i in range(n)]: for i in range(len(x)-1): d[x[i]]=x[i+1] for i in range(1,len(x)): p[x[i]]=1 d.setdefault(x[-1],'') for x in range(9,123): x=chr(x) if p.get(x,0)>0 or d.get(x,'Q')=='Q': continue while x!='': ans+=x; t=d[x]; del d[x]; x=t print(''.join(ans)) ```
output
1
35,592
6
71,185
Provide tags and a correct Python 3 solution for this coding contest problem. Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once. Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome. You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string. Input The first line of the input contains a positive integer n (1 ≀ n ≀ 100) β€” the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings. Output In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. Examples Input 3 bcd ab cdef Output abcdef Input 4 x y z w Output xyzw
instruction
0
35,593
6
71,186
Tags: *special, dfs and similar, strings Correct Solution: ``` n = int(input()) enabled = [False] * 26 a = [[False]*26 for i in range(26)] for i in range(n): s = list(map(lambda x: ord(x)-ord('a'), input())) for c in s: enabled[c] = True for i in range(len(s)-1): a[s[i]][s[i+1]] = True pos = sum(enabled) ans = [0]*pos def topSort(v): global pos enabled[v] = False for v2 in range(26): if a[v][v2] and enabled[v2]: topSort(v2) pos -= 1 ans[pos] = v for i in range(26): if enabled[i]: notvisited = True for j in range(26): if a[j][i] == True: notvisited = False if notvisited: topSort(i) print(''.join(map(lambda x: chr(x+ord('a')), ans))) ```
output
1
35,593
6
71,187
Provide tags and a correct Python 3 solution for this coding contest problem. Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once. Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome. You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string. Input The first line of the input contains a positive integer n (1 ≀ n ≀ 100) β€” the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings. Output In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. Examples Input 3 bcd ab cdef Output abcdef Input 4 x y z w Output xyzw
instruction
0
35,594
6
71,188
Tags: *special, dfs and similar, strings Correct Solution: ``` from sys import exit n = int(input()) a = [] for i in range(n): s = input() for j in range(len(a)): check = a[j] if s in check: break if check in s: a[j] = s break else: a.append(s) br_flag = False while True: for j in range(len(a)): answer = a[j] for i in a: if j == a.index(i): continue if answer[-1] in i: if len(answer) > i.index(answer[-1]): a[j] = answer[:len(answer) - 1] + i[i.index(answer[-1]):] a.remove(i) else: a.remove(answer) br_flag = True break if br_flag: br_flag = False break for i in a: if j == a.index(i): continue if answer[0] in i: if len(answer) > len(i) - i.index(answer[0]): a[j] = i[:i.index(answer[0])] + answer[:len(answer)] a.remove(i) else: a.remove(answer) br_flag = True break if br_flag: br_flag = False break st = ''.join(a) for i in st: if st.count(i) == 1: continue else: break else: break print(''.join(a)) ```
output
1
35,594
6
71,189
Provide tags and a correct Python 3 solution for this coding contest problem. Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once. Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome. You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string. Input The first line of the input contains a positive integer n (1 ≀ n ≀ 100) β€” the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings. Output In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. Examples Input 3 bcd ab cdef Output abcdef Input 4 x y z w Output xyzw
instruction
0
35,595
6
71,190
Tags: *special, dfs and similar, strings Correct Solution: ``` n = int(input()) a = [] b = [True]*n S = '' for i in range(n): s = input() S += s a.append(s) alf = list(set(S)) def find(): l = len(a) b = False for i in range(l): if b: break x = list(a[i]) for j in range(len(x)): if b: break s = x[j] for k in range(i+1,l): if s in a[k]: b = True skl(a[i],a[k],s) break if not b: return else: find() def skl(x,y,s): a.remove(x) a.remove(y) i1 = x.index(s) i2 = y.index(s) z = '' n1 = x[:i1] n2 = y[:i2] if len(n1) > len(n2): z += n1 else: z += n2 k1 = x[i1:] k2 = y[i2:] if len(k1) > len(k2): z += k1 else: z += k2 a.append(z) find() for i in range(len(a)): print(a[i],end='') ```
output
1
35,595
6
71,191
Provide tags and a correct Python 3 solution for this coding contest problem. Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once. Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome. You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string. Input The first line of the input contains a positive integer n (1 ≀ n ≀ 100) β€” the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings. Output In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. Examples Input 3 bcd ab cdef Output abcdef Input 4 x y z w Output xyzw
instruction
0
35,596
6
71,192
Tags: *special, dfs and similar, strings Correct Solution: ``` n = int(input()) seqs = [] lang = '' for i in range(n): s = input().strip() seqs.append(s) for let in s: if let not in lang: lang += let seqs.sort(key=lambda x: -len(x)) class letB: right = None left = None letters = {} visited = {} for i in lang: letters[i] = letB() letters[i].right = None letters[i].left = None visited[i] = False for seq in seqs: for letter in range(len(seq)-1): letters[seq[letter]].right = seq[letter + 1] letters[seq[letter + 1]].left = seq[letter] res = "" for i in letters: #print('i', i) if not visited[i]: curC = i while letters[curC].left: curC = letters[curC].left while letters[curC].right: #print('c',curC) res += curC visited[curC] = True curC = letters[curC].right res += curC visited[curC] = True print(res) ```
output
1
35,596
6
71,193
Provide tags and a correct Python 3 solution for this coding contest problem. Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once. Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome. You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string. Input The first line of the input contains a positive integer n (1 ≀ n ≀ 100) β€” the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings. Output In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. Examples Input 3 bcd ab cdef Output abcdef Input 4 x y z w Output xyzw
instruction
0
35,597
6
71,194
Tags: *special, dfs and similar, strings Correct Solution: ``` def f(cur): i = cur while i != -1: print(chr(i + 97), end = '') i = d[i] n = int(input()) d = [-2 for i in range(26)] ans = [] first = [0] * 26 for i in range(n): s = input() if d[ord(s[0]) - 97] == -2: first[ord(s[0]) - 97] = 1 for j in range(len(s) - 1): if first[ord(s[j]) - 97] == 1 and j != 0: first[ord(s[j]) - 97] = 0 d[ord(s[j]) - 97] = ord(s[j + 1]) - 97 d[ord(s[len(s) - 1]) - 97] = max(d[ord(s[len(s) - 1]) - 97], -1) if first[ord(s[len(s) - 1]) - 97] == 1 and len(s) != 1: first[ord(s[len(s) - 1]) - 97] = 0 for i in range(len(first)): if first[i]: f(i) ```
output
1
35,597
6
71,195
Provide tags and a correct Python 3 solution for this coding contest problem. Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once. Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome. You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string. Input The first line of the input contains a positive integer n (1 ≀ n ≀ 100) β€” the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings. Output In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. Examples Input 3 bcd ab cdef Output abcdef Input 4 x y z w Output xyzw
instruction
0
35,598
6
71,196
Tags: *special, dfs and similar, strings Correct Solution: ``` #number = random.randrange(start, stop, step) n = int(input()) arr = [] arr2 = "" for i in range(n): arr.append(str(input())) res = [""] count = 0 z = 0 while len(arr) != 0: flag = False z = 0 for i in range(len(arr)): if res[count].find(arr[i-z]) != -1: del arr[i-z] z+=1 continue elif arr[i-z].find(res[count])!= -1: res[count] = arr[i-z] del arr[i-z] z+=1 continue if res[count].find(arr[i-z][0]) != -1: res[count] += arr[i-z] del arr[i-z] z+=1 elif res[count].find(arr[i-z][-1]) != -1: res[count] = arr[i-z] + res[count] del arr[i-z] z+=1 if z == 0: for j in range(len(arr)): for k in arr[j]: for s in range(j,len(arr)): if arr[s].find(k) != -1: res.append(arr[j]) count += 1 del arr[j] flag = True break if flag: break if flag: break for t in res: for m in t: if arr2.find(m) == -1: arr2 += m print(arr2) ```
output
1
35,598
6
71,197
Provide tags and a correct Python 3 solution for this coding contest problem. Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once. Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome. You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string. Input The first line of the input contains a positive integer n (1 ≀ n ≀ 100) β€” the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings. Output In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. Examples Input 3 bcd ab cdef Output abcdef Input 4 x y z w Output xyzw
instruction
0
35,599
6
71,198
Tags: *special, dfs and similar, strings Correct Solution: ``` n = int(input()) s = set() for i in range(n): s.add(input()) strings = list(s) for i in range(len(strings)): for j in range(len(strings)): if i != j and strings[i] in strings[j]: s.discard(strings[i]) strings = list(s) label = True while label: label = False length = len(strings) for i in range(length): for j in range(length): if strings[i] and i != j and strings[i][-1] in strings[j]: s.discard(strings[i]) s.discard(strings[j]) s.add(strings[i] + strings[j][strings[j].index(strings[i][-1]) + 1:]) strings[i], strings[j] = '', '' label = True break if label: break strings = list(s) length = len(strings) for i in range(length): for j in range(length): if strings[i] and i != j and strings[i] in strings[j]: s.discard(strings[i]) strings = list(s) print(''.join(strings)) ```
output
1
35,599
6
71,199
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once. Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome. You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string. Input The first line of the input contains a positive integer n (1 ≀ n ≀ 100) β€” the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings. Output In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. Examples Input 3 bcd ab cdef Output abcdef Input 4 x y z w Output xyzw Submitted Solution: ``` #from bisect import bisect_left as bl #c++ lowerbound bl(array,element) #from bisect import bisect_right as br #c++ upperbound br(array,element) #from __future__ import print_function, division #while using python2 def modinv(n,p): return pow(n,p-2,p) def merge(a, b): if a in b: return b elif b in a: return a possible = False ind_1 = -1 ind_2 = -1 for c in a: if c in b: possible = True ind_1 = a.index(c) ind_2 = b.index(c) break if not possible: return a+b else: if ind_1 > ind_2: return a[:ind_1] + b else: return b[:ind_2] + a def main(): #sys.stdin = open('input.txt', 'r') #sys.stdout = open('output.txt', 'w') n = int(input()) genomes = [] for i in range(n): genomes.append(input()) no_overlaps = False while len(genomes) > 1: if no_overlaps: break new_genome = [] # print(genomes) # print(new_genome) # print() # input() l = -1 r = -1 merged = "" for i in range(len(genomes)): for j in range(i+1, len(genomes)): k = merge(genomes[i], genomes[j]) if len(k) < len(genomes[i]) + len(genomes[j]): l, r = i, j merged = k break if merged != "": break if l != -1: for i in range(len(genomes)): if i not in [l, r]: new_genome.append(genomes[i]) new_genome.append(merged) genomes = [x for x in new_genome] else: no_overlaps = True break print("".join(genomes)) #------------------ Python 2 and 3 footer by Pajenegod and c1729----------------------------------------- py2 = round(0.5) if py2: from future_builtins import ascii, filter, hex, map, oct, zip range = xrange import os, sys from io import IOBase, BytesIO BUFSIZE = 8192 class FastIO(BytesIO): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.writable = "x" in file.mode or "w" in file.mode self.write = super(FastIO, self).write if self.writable else None def _fill(self): s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0]) return s def read(self): while self._fill(): pass return super(FastIO,self).read() def readline(self): while self.newlines == 0: s = self._fill(); self.newlines = s.count(b"\n") + (not s) self.newlines -= 1 return super(FastIO, self).readline() def flush(self): if self.writable: os.write(self._fd, self.getvalue()) self.truncate(0), self.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable if py2: self.write = self.buffer.write self.read = self.buffer.read self.readline = self.buffer.readline else: self.write = lambda s:self.buffer.write(s.encode('ascii')) self.read = lambda:self.buffer.read().decode('ascii') self.readline = lambda:self.buffer.readline().decode('ascii') sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip('\r\n') if __name__ == '__main__': main() ```
instruction
0
35,600
6
71,200
Yes
output
1
35,600
6
71,201
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once. Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome. You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string. Input The first line of the input contains a positive integer n (1 ≀ n ≀ 100) β€” the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings. Output In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. Examples Input 3 bcd ab cdef Output abcdef Input 4 x y z w Output xyzw Submitted Solution: ``` genes = [] n = int(input().split()[0]) for i in range(n): new_chain = input().split()[0] new_content = set() for c in new_chain: new_content.add(c) genes.append({ "chain": new_chain, "content": new_content }) # print(genes) for rep in range(100): for i in range(n): for j in range(n): if i == j: continue # if 1 belongs if genes[i]["content"].issubset(genes[j]["content"]): # print(genes[i]["chain"], "belongs", genes[j]["chain"]) # nullifying genes[i]["chain"] = "" genes[i]["content"] = set() # if 2 belongs elif genes[j]["content"].issubset(genes[i]["content"]): # print(genes[j]["chain"], "belongs", genes[i]["chain"]) # nullifying genes[j]["chain"] = "" genes[j]["content"] = set() elif genes[j]["content"] & genes[i]["content"]: # print(genes[i]["chain"], "&", genes[j]["chain"], "=>", genes[j]["content"] & genes[i]["content"]) inter = genes[i]["content"] & genes[j]["content"] inter_l = len(inter) # desiding whre to put it if(genes[i]["chain"].endswith(genes[j]["chain"][:inter_l])): genes[i]["chain"] += genes[j]["chain"][inter_l:] else: genes[i]["chain"] = genes[j]["chain"][:-inter_l]+genes[i]["chain"] genes[i]["content"] |= genes[j]["content"] # print(genes[i]["chain"]) # nullifying genes[j]["chain"] = "" genes[j]["content"] = set() # print(genes) ans = "" for i in range(n): ans += genes[i]["chain"] print(ans) ```
instruction
0
35,601
6
71,202
Yes
output
1
35,601
6
71,203
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once. Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome. You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string. Input The first line of the input contains a positive integer n (1 ≀ n ≀ 100) β€” the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings. Output In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. Examples Input 3 bcd ab cdef Output abcdef Input 4 x y z w Output xyzw Submitted Solution: ``` import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ########################################################## from collections import Counter #c=sorted((i,int(val))for i,val in enumerate(input().split())) import heapq #n = int(input()) #ls = list(map(int, input().split())) #n, k = map(int, input().split()) #n =int(input()) #e=list(map(int, input().split())) #n =int(input()) #for _ in range(int(input())): n =int(input()) v=[0]*26 ans=[] def dfs(s): v[s]=2 #### indicate that node has used for j in g[s]: if v[j]==1 or v[j]==6: dfs(j) ans.append(chr(s+97)) #print(ans) g=[set() for i in range(26)] for i in range(n): s=input() for j in range(1,len(s)): g[ord(s[j-1])-97].add(ord(s[j])-97) v[ord(s[j])-ord("a")]=1 if v[ord(s[0])-97]==0: v[ord(s[0])-97]=6 ######## no preceddor node we have start from node with indegree==0 #print(g) #print(v) for i in range(26): if v[i]==6: #### if no preceddor node dfs(i) print("".join(reversed(ans))) #opbigh ```
instruction
0
35,602
6
71,204
Yes
output
1
35,602
6
71,205
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once. Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome. You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string. Input The first line of the input contains a positive integer n (1 ≀ n ≀ 100) β€” the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings. Output In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. Examples Input 3 bcd ab cdef Output abcdef Input 4 x y z w Output xyzw Submitted Solution: ``` n = int(input()) a = {} b = {} w, e = set(), set() for i in range(n): s = input() q = s[0] if s[0] not in b.keys(): b[s[0]] = -1 e.add(s[0]) if s[-1] not in a.keys(): a[s[-1]] = -1 w.add(s[-1]) for j in range(1, len(s)): if s[j-1] in w: w.remove(s[j-1]) if s[j] in e: e.remove(s[j]) a[s[j-1]] = s[j] b[s[j]] = s[j-1] while b[q[0]] != -1: q = b[q[0]]+q while a[q[-1]] != -1: q = q+a[q[-1]] while(len(e)!= 1 or len(w)!=1): if(len(e)!= 1): r = e.pop() if q[0]==r: i = e.pop() e.add(r) r = i q+=r a[q[-2]]=r b[r]=q[-2] if q[-2] in w: w.remove(q[-2]) else: r=w.pop() if q[-1]==r: i = w.pop() w.add(r) r = i q = r+q a[r]=q[1] b[q[1]] = r if q[1] in e: e.remove(q[1]) while b[q[0]] != -1: q = b[q[0]]+q while a[q[-1]] != -1: q = q+a[q[-1]] print(q) ```
instruction
0
35,603
6
71,206
Yes
output
1
35,603
6
71,207
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once. Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome. You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string. Input The first line of the input contains a positive integer n (1 ≀ n ≀ 100) β€” the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings. Output In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. Examples Input 3 bcd ab cdef Output abcdef Input 4 x y z w Output xyzw Submitted Solution: ``` l = int(input()) a = '' for i in range(l): h = input() a = a+h a = a.lower() c = 'abcdefghijklmnopqrstuvwxyz' b = [] for i in range(len(a)): b.append(a[i]) b.sort() m = '' e = len(c) for i in range(e): try: p = b.index(c[i]) except ValueError: continue m = m+c[i] print(m) ```
instruction
0
35,604
6
71,208
No
output
1
35,604
6
71,209
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once. Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome. You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string. Input The first line of the input contains a positive integer n (1 ≀ n ≀ 100) β€” the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings. Output In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. Examples Input 3 bcd ab cdef Output abcdef Input 4 x y z w Output xyzw Submitted Solution: ``` #------------------------template--------------------------# import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import* from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") def value():return tuple(map(int,input().split())) def array():return [int(i) for i in input().split()] def Int():return int(input()) def Str():return input() def arrayS():return [i for i in input().split()] #-------------------------code---------------------------# #vsInput() def operate(s1,s2): if(s1 in s2): need[s1]=True return False elif(s2 in s1): need[s2]=True return False try:ind=s2.index(s1[-1]) except:return False joinWith[s1]=(s2,ind+1) return True def merge(s1,s2): s=list(s1) s.extend(s2[joinWith[s1][1]:]) #print(s1,s2,s) return s def dfs(s,ans=[]): vis[s]=True #print((s,ans),end=" ") flag=True if(not vis[joinWith[s][0]]): flag=False ans+=merge(s,list(joinWith[s][0])) ans=dfs(joinWith[s][0],ans) if(flag):vis[s]=False return ans n=Int() strings=[] vis=defaultdict(bool) vis['']=True over=set() for i in range(n): s=input() if(s not in over): strings.append(s) over.add(s) n=len(strings) need=defaultdict(bool) joinWith=defaultdict(lambda: ('',0)) for i in range(n-1): for j in range(n): if(i!=j and not need[strings[i]] and not need[strings[j]]): if(operate(strings[i],strings[j])): break have=[i[0] for i in joinWith.values()] score={} for i in strings: if( i in joinWith.keys() and i in have): score[i]=3 elif(i in have): score[i]=4 elif(i in joinWith.keys()): score[i]=1 else: score[i]=0 final=[] strings.sort(key= lambda st:score[st]) #print(score) for i in strings: if(not vis[i] and not need[i]): #print(i,score[i]) if(score[i]!=0): ans=dfs(i) else: ans=list(i) final=ans+final over=set() for i in final: if(i not in over): print(i,end="") over.add(i) ```
instruction
0
35,605
6
71,210
No
output
1
35,605
6
71,211
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once. Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome. You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string. Input The first line of the input contains a positive integer n (1 ≀ n ≀ 100) β€” the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings. Output In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. Examples Input 3 bcd ab cdef Output abcdef Input 4 x y z w Output xyzw Submitted Solution: ``` n = int(input()) words = [] s = set() res = "" for i in range(n): words.append(input()) fl = True while fl: fl = False m = 0 curWord = "" for i in words: tm = 0 for j in i: if j not in s: tm += 1 if tm > m: m = tm curWord = i if m: fl = True for i in curWord: s.add(i) res += curWord print(res) ```
instruction
0
35,606
6
71,212
No
output
1
35,606
6
71,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once. Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome. You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string. Input The first line of the input contains a positive integer n (1 ≀ n ≀ 100) β€” the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings. Output In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. Examples Input 3 bcd ab cdef Output abcdef Input 4 x y z w Output xyzw Submitted Solution: ``` n = int(input()) arr = [set(input()) for i in range(n)] for i in range(n): arr[0].intersection_update(arr[i]) for e in arr: for e2 in e: print(e2, end='') ```
instruction
0
35,607
6
71,214
No
output
1
35,607
6
71,215
Provide tags and a correct Python 3 solution for this coding contest problem. Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: * An 'L' indicates he should move one unit left. * An 'R' indicates he should move one unit right. * A 'U' indicates he should move one unit up. * A 'D' indicates he should move one unit down. But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in s with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string. Input The first and only line contains the string s (1 ≀ |s| ≀ 100 000) β€” the instructions Memory is given. Output If there is a string satisfying the conditions, output a single integer β€” the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1. Examples Input RRU Output -1 Input UDUR Output 1 Input RUUR Output 2 Note In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk. In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change s to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin.
instruction
0
35,612
6
71,224
Tags: implementation, strings Correct Solution: ``` s = input() u, d, l, r = 0, 0, 0, 0 for i in s: if i == 'U': u += 1 elif i == 'D': d += 1 elif i == 'R': r += 1 else: l += 1 if (r + l + u + d) % 2 != 0: print(-1) else: print((abs(r - l) + abs(u - d)) // 2) ```
output
1
35,612
6
71,225
Provide tags and a correct Python 3 solution for this coding contest problem. Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: * An 'L' indicates he should move one unit left. * An 'R' indicates he should move one unit right. * A 'U' indicates he should move one unit up. * A 'D' indicates he should move one unit down. But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in s with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string. Input The first and only line contains the string s (1 ≀ |s| ≀ 100 000) β€” the instructions Memory is given. Output If there is a string satisfying the conditions, output a single integer β€” the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1. Examples Input RRU Output -1 Input UDUR Output 1 Input RUUR Output 2 Note In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk. In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change s to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin.
instruction
0
35,613
6
71,226
Tags: implementation, strings Correct Solution: ``` s = input() if len(s) % 2 == 1: print('-1') exit() a = abs(s.count('U') - s.count('D')) b = abs(s.count('L') - s.count('R')) print(a + b >> 1) ```
output
1
35,613
6
71,227