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. Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point. Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that. Input The first line contains integer q (1 ≤ q ≤ 1000), the number of handle change requests. Next q lines contain the descriptions of the requests, one per line. Each query consists of two non-empty strings old and new, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings old and new are distinct. The lengths of the strings do not exceed 20. The requests are given chronologically. In other words, by the moment of a query there is a single person with handle old, and handle new is not used and has not been used by anyone. Output In the first line output the integer n — the number of users that changed their handles at least once. In the next n lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, old and new, separated by a space, meaning that before the user had handle old, and after all the requests are completed, his handle is new. You may output lines in any order. Each user who changes the handle must occur exactly once in this description. Examples Input 5 Misha ILoveCodeforces Vasya Petrov Petrov VasyaPetrov123 ILoveCodeforces MikeMirzayanov Petya Ivanov Output 3 Petya Ivanov Misha MikeMirzayanov Vasya VasyaPetrov123
instruction
0
12,864
6
25,728
Tags: data structures, dsu, strings Correct Solution: ``` #coding:utf-8 n = int( input()) names = {} changes = 0 for i in range(n): current, changed = map(str, input().split()) if current not in names: names[changed] = current changes += 1 else: aux = names[current] names.pop(current) names[changed] = aux print(changes) for i in names: print(names[i],i) ```
output
1
12,864
6
25,729
Provide tags and a correct Python 3 solution for this coding contest problem. Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point. Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that. Input The first line contains integer q (1 ≤ q ≤ 1000), the number of handle change requests. Next q lines contain the descriptions of the requests, one per line. Each query consists of two non-empty strings old and new, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings old and new are distinct. The lengths of the strings do not exceed 20. The requests are given chronologically. In other words, by the moment of a query there is a single person with handle old, and handle new is not used and has not been used by anyone. Output In the first line output the integer n — the number of users that changed their handles at least once. In the next n lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, old and new, separated by a space, meaning that before the user had handle old, and after all the requests are completed, his handle is new. You may output lines in any order. Each user who changes the handle must occur exactly once in this description. Examples Input 5 Misha ILoveCodeforces Vasya Petrov Petrov VasyaPetrov123 ILoveCodeforces MikeMirzayanov Petya Ivanov Output 3 Petya Ivanov Misha MikeMirzayanov Vasya VasyaPetrov123
instruction
0
12,865
6
25,730
Tags: data structures, dsu, strings Correct Solution: ``` maps = {} for i in range(int(input())): old, new = input().split() if old in maps: maps[new] = maps[old] del maps[old] else: maps[new] = old print(len(maps)) for k, v in maps.items(): print(v + " " + k) ```
output
1
12,865
6
25,731
Provide tags and a correct Python 3 solution for this coding contest problem. Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point. Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that. Input The first line contains integer q (1 ≤ q ≤ 1000), the number of handle change requests. Next q lines contain the descriptions of the requests, one per line. Each query consists of two non-empty strings old and new, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings old and new are distinct. The lengths of the strings do not exceed 20. The requests are given chronologically. In other words, by the moment of a query there is a single person with handle old, and handle new is not used and has not been used by anyone. Output In the first line output the integer n — the number of users that changed their handles at least once. In the next n lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, old and new, separated by a space, meaning that before the user had handle old, and after all the requests are completed, his handle is new. You may output lines in any order. Each user who changes the handle must occur exactly once in this description. Examples Input 5 Misha ILoveCodeforces Vasya Petrov Petrov VasyaPetrov123 ILoveCodeforces MikeMirzayanov Petya Ivanov Output 3 Petya Ivanov Misha MikeMirzayanov Vasya VasyaPetrov123
instruction
0
12,866
6
25,732
Tags: data structures, dsu, strings Correct Solution: ``` n=int(input()) arr=[] for i in range(n): s=input() a=s.split(' ') arr.append(a) array=[['' for col in range(n)]for row in range(2)] a1=[[]for k in range(n)] a1[0].append(arr[0][0]) a1[0].append(arr[0][1]) a2=[] a2.append(arr[0][1]) p=1 while(p<n): a2.append(arr[p][1]) if arr[p][0] in a2: c=0 while(c<p): if arr[p][0] in a1[c]: break else: c=c+1 a1[c].append(arr[p][1]) p=p+1 else: a1[p].append(arr[p][0]) a1[p].append(arr[p][1]) p=p+1 count=0 for z in range(len(a1)): if(a1[z]!=[]): count+=1 print(count) for z in range(len(a1)): if(a1[z]!=[]): print(a1[z][0]+' '+a1[z][-1]) ```
output
1
12,866
6
25,733
Provide tags and a correct Python 3 solution for this coding contest problem. There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet. You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout. Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. Input The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. Output Print the text if the same keys were pressed in the second layout. Examples Input qwertyuiopasdfghjklzxcvbnm veamhjsgqocnrbfxdtwkylupzi TwccpQZAvb2017 Output HelloVKCup2017 Input mnbvcxzlkjhgfdsapoiuytrewq asdfghjklqwertyuiopzxcvbnm 7abaCABAABAcaba7 Output 7uduGUDUUDUgudu7
instruction
0
13,014
6
26,028
Tags: implementation, strings Correct Solution: ``` a,b=input(),input() dict={} d=[] for x in list(input()): if x in '0123456789': d.append(x) elif x == x.lower(): d.append(b[a.index(x)]) elif x==x.upper(): d.append(b[a.index(x.lower())].upper()) print(''.join(d)) ```
output
1
13,014
6
26,029
Provide tags and a correct Python 3 solution for this coding contest problem. There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet. You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout. Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. Input The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. Output Print the text if the same keys were pressed in the second layout. Examples Input qwertyuiopasdfghjklzxcvbnm veamhjsgqocnrbfxdtwkylupzi TwccpQZAvb2017 Output HelloVKCup2017 Input mnbvcxzlkjhgfdsapoiuytrewq asdfghjklqwertyuiopzxcvbnm 7abaCABAABAcaba7 Output 7uduGUDUUDUgudu7
instruction
0
13,015
6
26,030
Tags: implementation, strings Correct Solution: ``` first = input() second = input() request = input() first_d = {} second_d = {} for _, c in enumerate(first): first_d[c] = _ for _, c in enumerate(second): second_d[_] = c ans = "" for c in request: lower_c = c.lower() if lower_c not in first: ans += c else: corr_c = second_d[first_d[lower_c]] if c.lower() == c: ans += corr_c else: ans += corr_c.upper() print(ans) ```
output
1
13,015
6
26,031
Provide tags and a correct Python 3 solution for this coding contest problem. There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet. You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout. Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. Input The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. Output Print the text if the same keys were pressed in the second layout. Examples Input qwertyuiopasdfghjklzxcvbnm veamhjsgqocnrbfxdtwkylupzi TwccpQZAvb2017 Output HelloVKCup2017 Input mnbvcxzlkjhgfdsapoiuytrewq asdfghjklqwertyuiopzxcvbnm 7abaCABAABAcaba7 Output 7uduGUDUUDUgudu7
instruction
0
13,016
6
26,032
Tags: implementation, strings Correct Solution: ``` first = str(input()) second = str(input()) line = (input()) result = '' for word in line: if word.isdigit(): result+=word else: i = first.find(word) if i == -1: i = (first.upper()).find(word) result += second[i].upper() else: result += second[i] print (result) ```
output
1
13,016
6
26,033
Provide tags and a correct Python 3 solution for this coding contest problem. There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet. You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout. Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. Input The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. Output Print the text if the same keys were pressed in the second layout. Examples Input qwertyuiopasdfghjklzxcvbnm veamhjsgqocnrbfxdtwkylupzi TwccpQZAvb2017 Output HelloVKCup2017 Input mnbvcxzlkjhgfdsapoiuytrewq asdfghjklqwertyuiopzxcvbnm 7abaCABAABAcaba7 Output 7uduGUDUUDUgudu7
instruction
0
13,017
6
26,034
Tags: implementation, strings Correct Solution: ``` a = input() b = input() c = input() dic = {} for i in range(26): dic[a[i]] = b[i]; d = "" for i in range(len(c)): if c[i].lower() not in a: d += c[i] elif c[i].isupper(): d += (dic[c[i].lower()]).upper() else: d += dic[c[i]] print (d) ```
output
1
13,017
6
26,035
Provide tags and a correct Python 3 solution for this coding contest problem. There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet. You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout. Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. Input The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. Output Print the text if the same keys were pressed in the second layout. Examples Input qwertyuiopasdfghjklzxcvbnm veamhjsgqocnrbfxdtwkylupzi TwccpQZAvb2017 Output HelloVKCup2017 Input mnbvcxzlkjhgfdsapoiuytrewq asdfghjklqwertyuiopzxcvbnm 7abaCABAABAcaba7 Output 7uduGUDUUDUgudu7
instruction
0
13,018
6
26,036
Tags: implementation, strings Correct Solution: ``` s1=input() s2=input() s3=input() for i in range(len(s3)): try: k=s1.index(s3[i].lower()) if s3[i].lower()==s3[i]: print(s2[k],end="") else: print(s2[k].upper(),end="") except: print(s3[i],end="") ```
output
1
13,018
6
26,037
Provide tags and a correct Python 3 solution for this coding contest problem. There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet. You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout. Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. Input The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. Output Print the text if the same keys were pressed in the second layout. Examples Input qwertyuiopasdfghjklzxcvbnm veamhjsgqocnrbfxdtwkylupzi TwccpQZAvb2017 Output HelloVKCup2017 Input mnbvcxzlkjhgfdsapoiuytrewq asdfghjklqwertyuiopzxcvbnm 7abaCABAABAcaba7 Output 7uduGUDUUDUgudu7
instruction
0
13,019
6
26,038
Tags: implementation, strings Correct Solution: ``` x=input() y=input() t=input() r='' for i in t: if(i.isupper()): w=i.lower() for j in range(26): if(x[j]==w): r=r+y[j].upper() elif(i.islower()): for j in range(26): if(x[j]==i): r=r+y[j] else: r=r+i print(r) ```
output
1
13,019
6
26,039
Provide tags and a correct Python 3 solution for this coding contest problem. There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet. You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout. Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. Input The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. Output Print the text if the same keys were pressed in the second layout. Examples Input qwertyuiopasdfghjklzxcvbnm veamhjsgqocnrbfxdtwkylupzi TwccpQZAvb2017 Output HelloVKCup2017 Input mnbvcxzlkjhgfdsapoiuytrewq asdfghjklqwertyuiopzxcvbnm 7abaCABAABAcaba7 Output 7uduGUDUUDUgudu7
instruction
0
13,020
6
26,040
Tags: implementation, strings Correct Solution: ``` s = input() t = input() d = {} for i in range(26): d[s[i]] = t[i] w = input() result = '' for i in range(len(w)): if w[i].isupper() and 65 <= ord(w[i]) <= 90: result += d[w[i].lower()].upper() elif 97 <= ord(w[i]) <= 122: result += d[w[i]] else: result += w[i] print(result) ```
output
1
13,020
6
26,041
Provide tags and a correct Python 3 solution for this coding contest problem. There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet. You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout. Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters. Input The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000. Output Print the text if the same keys were pressed in the second layout. Examples Input qwertyuiopasdfghjklzxcvbnm veamhjsgqocnrbfxdtwkylupzi TwccpQZAvb2017 Output HelloVKCup2017 Input mnbvcxzlkjhgfdsapoiuytrewq asdfghjklqwertyuiopzxcvbnm 7abaCABAABAcaba7 Output 7uduGUDUUDUgudu7
instruction
0
13,021
6
26,042
Tags: implementation, strings Correct Solution: ``` a = input() b = input() c = input() d = dict((a[i], b[i]) for i in range(0, len(a))) s = '' for _ in c: if _.isupper(): _ = d[_.lower()].upper() elif _.islower(): _ = d[_] s += _ print(s) ```
output
1
13,021
6
26,043
Provide tags and a correct Python 3 solution for this coding contest problem. You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed. Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx". You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by 1. For example, if you delete the character in the position 2 from the string "exxxii", then the resulting string is "exxii". Input The first line contains integer n (3 ≤ n ≤ 100) — the length of the file name. The second line contains a string of length n consisting of lowercase Latin letters only — the file name. Output Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. Examples Input 6 xxxiii Output 1 Input 5 xxoxx Output 0 Input 10 xxxxxxxxxx Output 8 Note In the first example Polycarp tried to send a file with name contains number 33, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
instruction
0
13,076
6
26,152
Tags: greedy, strings Correct Solution: ``` length = int(input()) name = input() i = 0 count =0 while i < length - 2: if name[i] == name[i+1] == name[i+2] == 'x': count+=1 else: pass i+=1 print(count) ```
output
1
13,076
6
26,153
Provide tags and a correct Python 3 solution for this coding contest problem. You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed. Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx". You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by 1. For example, if you delete the character in the position 2 from the string "exxxii", then the resulting string is "exxii". Input The first line contains integer n (3 ≤ n ≤ 100) — the length of the file name. The second line contains a string of length n consisting of lowercase Latin letters only — the file name. Output Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. Examples Input 6 xxxiii Output 1 Input 5 xxoxx Output 0 Input 10 xxxxxxxxxx Output 8 Note In the first example Polycarp tried to send a file with name contains number 33, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
instruction
0
13,077
6
26,154
Tags: greedy, strings Correct Solution: ``` n = int(input()) counter = 0 delete = 0 s = input() for c in s: if c == 'x': counter += 1 else: delete += max(counter-2,0) counter = 0 if counter != 0: delete += max(counter-2,0) print(delete) ```
output
1
13,077
6
26,155
Provide tags and a correct Python 3 solution for this coding contest problem. You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed. Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx". You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by 1. For example, if you delete the character in the position 2 from the string "exxxii", then the resulting string is "exxii". Input The first line contains integer n (3 ≤ n ≤ 100) — the length of the file name. The second line contains a string of length n consisting of lowercase Latin letters only — the file name. Output Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. Examples Input 6 xxxiii Output 1 Input 5 xxoxx Output 0 Input 10 xxxxxxxxxx Output 8 Note In the first example Polycarp tried to send a file with name contains number 33, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
instruction
0
13,078
6
26,156
Tags: greedy, strings Correct Solution: ``` n=int(input()) s=list(input()) i,a,b=0,2,0#要给a一个初值,否则如果#2没有执行到的话,a就没有定义 while i<=n-3: if s[i]==s[i+1]=='x':#2 a=i+2 if s[a]=='x': while s[a]=='x': b+=1 a+=1 i=a if a==n: break #会打破while循环,如果下面的代码在for循环内就执行下面的 else: #代码,否则进入下一个for循环 i+=1 if a==n: break else: i+=1 print(b) ```
output
1
13,078
6
26,157
Provide tags and a correct Python 3 solution for this coding contest problem. You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed. Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx". You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by 1. For example, if you delete the character in the position 2 from the string "exxxii", then the resulting string is "exxii". Input The first line contains integer n (3 ≤ n ≤ 100) — the length of the file name. The second line contains a string of length n consisting of lowercase Latin letters only — the file name. Output Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. Examples Input 6 xxxiii Output 1 Input 5 xxoxx Output 0 Input 10 xxxxxxxxxx Output 8 Note In the first example Polycarp tried to send a file with name contains number 33, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
instruction
0
13,079
6
26,158
Tags: greedy, strings Correct Solution: ``` input() s = input() ans = 0 while s.count('xxx'): i = s.find('xxx') s = s[:i] + s[i + 1:] ans += 1 print(ans) ```
output
1
13,079
6
26,159
Provide tags and a correct Python 3 solution for this coding contest problem. You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed. Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx". You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by 1. For example, if you delete the character in the position 2 from the string "exxxii", then the resulting string is "exxii". Input The first line contains integer n (3 ≤ n ≤ 100) — the length of the file name. The second line contains a string of length n consisting of lowercase Latin letters only — the file name. Output Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. Examples Input 6 xxxiii Output 1 Input 5 xxoxx Output 0 Input 10 xxxxxxxxxx Output 8 Note In the first example Polycarp tried to send a file with name contains number 33, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
instruction
0
13,080
6
26,160
Tags: greedy, strings Correct Solution: ``` a = int(input()) s = input() if a ==2 or a==1: print(0) else: b = 0 for i in range(a-2): if s[i] == s[i+1] == s[i+2] == 'x': b+=1 else: pass print(b) ```
output
1
13,080
6
26,161
Provide tags and a correct Python 3 solution for this coding contest problem. You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed. Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx". You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by 1. For example, if you delete the character in the position 2 from the string "exxxii", then the resulting string is "exxii". Input The first line contains integer n (3 ≤ n ≤ 100) — the length of the file name. The second line contains a string of length n consisting of lowercase Latin letters only — the file name. Output Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. Examples Input 6 xxxiii Output 1 Input 5 xxoxx Output 0 Input 10 xxxxxxxxxx Output 8 Note In the first example Polycarp tried to send a file with name contains number 33, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
instruction
0
13,081
6
26,162
Tags: greedy, strings Correct Solution: ``` input() a = list(input()) i = 1 c = 0 while i < len(a)-1: if a[i] == 'x' and a[i - 1] == 'x' and a[i + 1] == 'x': del a[i] c += 1 else: i += 1 print(c) ```
output
1
13,081
6
26,163
Provide tags and a correct Python 3 solution for this coding contest problem. You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed. Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx". You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by 1. For example, if you delete the character in the position 2 from the string "exxxii", then the resulting string is "exxii". Input The first line contains integer n (3 ≤ n ≤ 100) — the length of the file name. The second line contains a string of length n consisting of lowercase Latin letters only — the file name. Output Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. Examples Input 6 xxxiii Output 1 Input 5 xxoxx Output 0 Input 10 xxxxxxxxxx Output 8 Note In the first example Polycarp tried to send a file with name contains number 33, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
instruction
0
13,082
6
26,164
Tags: greedy, strings Correct Solution: ``` n = int(input()) s = list(input()) con = 0 mov = 0 for i in range(n): if s[i]=='x': con+=1 else: con=0 if con==3: mov+=1 if (i+1)<n and s[i+1]=='x': con=2 else: con=0 print(mov) ```
output
1
13,082
6
26,165
Provide tags and a correct Python 3 solution for this coding contest problem. You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed. Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx". You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by 1. For example, if you delete the character in the position 2 from the string "exxxii", then the resulting string is "exxii". Input The first line contains integer n (3 ≤ n ≤ 100) — the length of the file name. The second line contains a string of length n consisting of lowercase Latin letters only — the file name. Output Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. Examples Input 6 xxxiii Output 1 Input 5 xxoxx Output 0 Input 10 xxxxxxxxxx Output 8 Note In the first example Polycarp tried to send a file with name contains number 33, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
instruction
0
13,083
6
26,166
Tags: greedy, strings Correct Solution: ``` x = int(input()) t = input() t1 = 0 r = 0 for i in range(x): if t[i] == "x": r = r + 1 else: r = 0 if r >= 3: t1 = t1 + 1 print(t1) ```
output
1
13,083
6
26,167
Provide tags and a correct Python 3 solution for this coding contest problem. AquaMoon had n strings of length m each. n is an odd number. When AquaMoon was gone, Cirno tried to pair these n strings together. After making (n-1)/(2) pairs, she found out that there was exactly one string without the pair! In her rage, she disrupted each pair of strings. For each pair, she selected some positions (at least 1 and at most m) and swapped the letters in the two strings of this pair at the selected positions. For example, if m = 6 and two strings "abcdef" and "xyzklm" are in one pair and Cirno selected positions 2, 3 and 6 she will swap 'b' with 'y', 'c' with 'z' and 'f' with 'm'. The resulting strings will be "ayzdem" and "xbcklf". Cirno then stole away the string without pair and shuffled all remaining strings in arbitrary order. AquaMoon found the remaining n-1 strings in complete disarray. Also, she remembers the initial n strings. She wants to know which string was stolen, but she is not good at programming. Can you help her? Input This problem is made as interactive. It means, that your solution will read the input, given by the interactor. But the interactor will give you the full input at the beginning and after that, you should print the answer. So you should solve the problem, like as you solve the usual, non-interactive problem because you won't have any interaction process. The only thing you should not forget is to flush the output buffer, after printing the answer. Otherwise, you can get an "Idleness limit exceeded" verdict. Refer to the [interactive problems guide](https://codeforces.com/blog/entry/45307) for the detailed information about flushing the output buffer. The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The first line of each test case contains two integers n, m (1 ≤ n ≤ 10^5, 1 ≤ m ≤ 10^5) — the number of strings and the length of each string, respectively. The next n lines each contain a string with length m, describing the original n strings. All string consists of lowercase Latin letters. The next n-1 lines each contain a string with length m, describing the strings after Cirno exchanged and reordered them. It is guaranteed that n is odd and that the sum of n ⋅ m over all test cases does not exceed 10^5. Hack format: The first line should contain a single integer t. After that t test cases should follow in the following format: The first line should contain two integers n and m. The following n lines should contain n strings of length m, describing the original strings. The following (n-1)/(2) lines should describe the pairs. They should contain, in the following order: the index of the first string i (1 ≤ i ≤ n), the index of the second string j (1 ≤ j ≤ n, i ≠ j), the number of exchanged positions k (1 ≤ k ≤ m), and the list of k positions that are exchanged (k distinct indices from 1 to m in any order). The final line should contain a permutation of integers from 1 to n, describing the way the strings should be reordered. The strings will be placed in the order indices placed in this permutation, the stolen string index will be ignored. Output For each test case print a single line with the stolen string. Example Input 3 3 5 aaaaa bbbbb ccccc aaaaa bbbbb 3 4 aaaa bbbb cccc aabb bbaa 5 6 abcdef uuuuuu kekeke ekekek xyzklm xbcklf eueueu ayzdem ukukuk Output ccccc cccc kekeke Note In the first test case, "aaaaa" and "bbbbb" exchanged all positions, and "ccccc" is the stolen string. In the second test case, "aaaa" and "bbbb" exchanged two first positions, and "cccc" is the stolen string. This is the first test in the hack format: 3 3 5 aaaaa bbbbb ccccc 1 2 5 1 2 3 4 5 2 1 3 3 4 aaaa bbbb cccc 1 2 2 1 2 2 1 3 5 6 abcdef uuuuuu kekeke ekekek xyzklm 1 5 3 2 3 6 2 4 3 2 4 6 5 4 1 2 3
instruction
0
13,548
6
27,096
Tags: interactive, math Correct Solution: ``` alpha = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] def stringsum(a): ans = 0 for x in a: ans+=alpha.index(x) return ans t = int(input()) for i in range(t): n,m = list(map(int,input().strip().split())) ostrings = [] rstrings = [] bsum1=[] bsum2=[] bsum3 = [] for i in range(n): ostrings.append(input()) for i in range(n-1): rstrings.append(input()) for i in range(m): s=0 for j in range(n): s+= alpha.index(ostrings[j][i]) bsum1.append(s) for i in range(m): s = 0 for j in range(n-1): s+=alpha.index(rstrings[j][i]) bsum2.append(s) for i in range(m): bsum3.append(bsum1[i]-bsum2[i]) ans = '' for x in bsum3: ans = ans+alpha[x] print(ans) ```
output
1
13,548
6
27,097
Provide tags and a correct Python 3 solution for this coding contest problem. AquaMoon had n strings of length m each. n is an odd number. When AquaMoon was gone, Cirno tried to pair these n strings together. After making (n-1)/(2) pairs, she found out that there was exactly one string without the pair! In her rage, she disrupted each pair of strings. For each pair, she selected some positions (at least 1 and at most m) and swapped the letters in the two strings of this pair at the selected positions. For example, if m = 6 and two strings "abcdef" and "xyzklm" are in one pair and Cirno selected positions 2, 3 and 6 she will swap 'b' with 'y', 'c' with 'z' and 'f' with 'm'. The resulting strings will be "ayzdem" and "xbcklf". Cirno then stole away the string without pair and shuffled all remaining strings in arbitrary order. AquaMoon found the remaining n-1 strings in complete disarray. Also, she remembers the initial n strings. She wants to know which string was stolen, but she is not good at programming. Can you help her? Input This problem is made as interactive. It means, that your solution will read the input, given by the interactor. But the interactor will give you the full input at the beginning and after that, you should print the answer. So you should solve the problem, like as you solve the usual, non-interactive problem because you won't have any interaction process. The only thing you should not forget is to flush the output buffer, after printing the answer. Otherwise, you can get an "Idleness limit exceeded" verdict. Refer to the [interactive problems guide](https://codeforces.com/blog/entry/45307) for the detailed information about flushing the output buffer. The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The first line of each test case contains two integers n, m (1 ≤ n ≤ 10^5, 1 ≤ m ≤ 10^5) — the number of strings and the length of each string, respectively. The next n lines each contain a string with length m, describing the original n strings. All string consists of lowercase Latin letters. The next n-1 lines each contain a string with length m, describing the strings after Cirno exchanged and reordered them. It is guaranteed that n is odd and that the sum of n ⋅ m over all test cases does not exceed 10^5. Hack format: The first line should contain a single integer t. After that t test cases should follow in the following format: The first line should contain two integers n and m. The following n lines should contain n strings of length m, describing the original strings. The following (n-1)/(2) lines should describe the pairs. They should contain, in the following order: the index of the first string i (1 ≤ i ≤ n), the index of the second string j (1 ≤ j ≤ n, i ≠ j), the number of exchanged positions k (1 ≤ k ≤ m), and the list of k positions that are exchanged (k distinct indices from 1 to m in any order). The final line should contain a permutation of integers from 1 to n, describing the way the strings should be reordered. The strings will be placed in the order indices placed in this permutation, the stolen string index will be ignored. Output For each test case print a single line with the stolen string. Example Input 3 3 5 aaaaa bbbbb ccccc aaaaa bbbbb 3 4 aaaa bbbb cccc aabb bbaa 5 6 abcdef uuuuuu kekeke ekekek xyzklm xbcklf eueueu ayzdem ukukuk Output ccccc cccc kekeke Note In the first test case, "aaaaa" and "bbbbb" exchanged all positions, and "ccccc" is the stolen string. In the second test case, "aaaa" and "bbbb" exchanged two first positions, and "cccc" is the stolen string. This is the first test in the hack format: 3 3 5 aaaaa bbbbb ccccc 1 2 5 1 2 3 4 5 2 1 3 3 4 aaaa bbbb cccc 1 2 2 1 2 2 1 3 5 6 abcdef uuuuuu kekeke ekekek xyzklm 1 5 3 2 3 6 2 4 3 2 4 6 5 4 1 2 3
instruction
0
13,549
6
27,098
Tags: interactive, math Correct Solution: ``` t = int(input()) # testcases for tests in range(t): # plz don't copy the code, to avoid plagiarism issue n,m = [int(i) for i in input().split(' ')] hash_chrs = [{} for i in range(m)] for i in range(n): inp = input() # plz don't copy the code, to avoid plagiarism issue for j in range(m): if inp[j] in hash_chrs[j].keys(): hash_chrs[j][inp[j]] = hash_chrs[j][inp[j]]+1 else: hash_chrs[j][inp[j]] = 1 # plz don't copy the code, to avoid plagiarism issue for i in range(n-1): inp = input() for j in range(m): hash_chrs[j][inp[j]] = hash_chrs[j][inp[j]]-1 # plz don't copy the code, to avoid plagiarism issue sol = '' for i in range(m): for key in hash_chrs[i].keys(): if hash_chrs[i][key]>0: sol+=key print(sol) # plz don't copy the code, to avoid plagiarism issue ######################################################################################## ```
output
1
13,549
6
27,099
Provide tags and a correct Python 3 solution for this coding contest problem. AquaMoon had n strings of length m each. n is an odd number. When AquaMoon was gone, Cirno tried to pair these n strings together. After making (n-1)/(2) pairs, she found out that there was exactly one string without the pair! In her rage, she disrupted each pair of strings. For each pair, she selected some positions (at least 1 and at most m) and swapped the letters in the two strings of this pair at the selected positions. For example, if m = 6 and two strings "abcdef" and "xyzklm" are in one pair and Cirno selected positions 2, 3 and 6 she will swap 'b' with 'y', 'c' with 'z' and 'f' with 'm'. The resulting strings will be "ayzdem" and "xbcklf". Cirno then stole away the string without pair and shuffled all remaining strings in arbitrary order. AquaMoon found the remaining n-1 strings in complete disarray. Also, she remembers the initial n strings. She wants to know which string was stolen, but she is not good at programming. Can you help her? Input This problem is made as interactive. It means, that your solution will read the input, given by the interactor. But the interactor will give you the full input at the beginning and after that, you should print the answer. So you should solve the problem, like as you solve the usual, non-interactive problem because you won't have any interaction process. The only thing you should not forget is to flush the output buffer, after printing the answer. Otherwise, you can get an "Idleness limit exceeded" verdict. Refer to the [interactive problems guide](https://codeforces.com/blog/entry/45307) for the detailed information about flushing the output buffer. The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The first line of each test case contains two integers n, m (1 ≤ n ≤ 10^5, 1 ≤ m ≤ 10^5) — the number of strings and the length of each string, respectively. The next n lines each contain a string with length m, describing the original n strings. All string consists of lowercase Latin letters. The next n-1 lines each contain a string with length m, describing the strings after Cirno exchanged and reordered them. It is guaranteed that n is odd and that the sum of n ⋅ m over all test cases does not exceed 10^5. Hack format: The first line should contain a single integer t. After that t test cases should follow in the following format: The first line should contain two integers n and m. The following n lines should contain n strings of length m, describing the original strings. The following (n-1)/(2) lines should describe the pairs. They should contain, in the following order: the index of the first string i (1 ≤ i ≤ n), the index of the second string j (1 ≤ j ≤ n, i ≠ j), the number of exchanged positions k (1 ≤ k ≤ m), and the list of k positions that are exchanged (k distinct indices from 1 to m in any order). The final line should contain a permutation of integers from 1 to n, describing the way the strings should be reordered. The strings will be placed in the order indices placed in this permutation, the stolen string index will be ignored. Output For each test case print a single line with the stolen string. Example Input 3 3 5 aaaaa bbbbb ccccc aaaaa bbbbb 3 4 aaaa bbbb cccc aabb bbaa 5 6 abcdef uuuuuu kekeke ekekek xyzklm xbcklf eueueu ayzdem ukukuk Output ccccc cccc kekeke Note In the first test case, "aaaaa" and "bbbbb" exchanged all positions, and "ccccc" is the stolen string. In the second test case, "aaaa" and "bbbb" exchanged two first positions, and "cccc" is the stolen string. This is the first test in the hack format: 3 3 5 aaaaa bbbbb ccccc 1 2 5 1 2 3 4 5 2 1 3 3 4 aaaa bbbb cccc 1 2 2 1 2 2 1 3 5 6 abcdef uuuuuu kekeke ekekek xyzklm 1 5 3 2 3 6 2 4 3 2 4 6 5 4 1 2 3
instruction
0
13,550
6
27,100
Tags: interactive, math Correct Solution: ``` import sys input = sys.stdin.readline def solve(): n, m = map(int, input().split()) original = [input() for _ in range(n)] modified = [input() for _ in range(n-1)] stolen_chars = [] for j in range(m): chars_available = 0 for i in range(n): chars_available += ord(original[i][j]) for i in range(n-1): chars_available -= ord(modified[i][j]) stolen_chars.append(chr(chars_available)) return ''.join(stolen_chars) t = int(input()) output = [] for _ in range(t): print(solve()) sys.stdout.flush() ```
output
1
13,550
6
27,101
Provide tags and a correct Python 3 solution for this coding contest problem. AquaMoon had n strings of length m each. n is an odd number. When AquaMoon was gone, Cirno tried to pair these n strings together. After making (n-1)/(2) pairs, she found out that there was exactly one string without the pair! In her rage, she disrupted each pair of strings. For each pair, she selected some positions (at least 1 and at most m) and swapped the letters in the two strings of this pair at the selected positions. For example, if m = 6 and two strings "abcdef" and "xyzklm" are in one pair and Cirno selected positions 2, 3 and 6 she will swap 'b' with 'y', 'c' with 'z' and 'f' with 'm'. The resulting strings will be "ayzdem" and "xbcklf". Cirno then stole away the string without pair and shuffled all remaining strings in arbitrary order. AquaMoon found the remaining n-1 strings in complete disarray. Also, she remembers the initial n strings. She wants to know which string was stolen, but she is not good at programming. Can you help her? Input This problem is made as interactive. It means, that your solution will read the input, given by the interactor. But the interactor will give you the full input at the beginning and after that, you should print the answer. So you should solve the problem, like as you solve the usual, non-interactive problem because you won't have any interaction process. The only thing you should not forget is to flush the output buffer, after printing the answer. Otherwise, you can get an "Idleness limit exceeded" verdict. Refer to the [interactive problems guide](https://codeforces.com/blog/entry/45307) for the detailed information about flushing the output buffer. The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The first line of each test case contains two integers n, m (1 ≤ n ≤ 10^5, 1 ≤ m ≤ 10^5) — the number of strings and the length of each string, respectively. The next n lines each contain a string with length m, describing the original n strings. All string consists of lowercase Latin letters. The next n-1 lines each contain a string with length m, describing the strings after Cirno exchanged and reordered them. It is guaranteed that n is odd and that the sum of n ⋅ m over all test cases does not exceed 10^5. Hack format: The first line should contain a single integer t. After that t test cases should follow in the following format: The first line should contain two integers n and m. The following n lines should contain n strings of length m, describing the original strings. The following (n-1)/(2) lines should describe the pairs. They should contain, in the following order: the index of the first string i (1 ≤ i ≤ n), the index of the second string j (1 ≤ j ≤ n, i ≠ j), the number of exchanged positions k (1 ≤ k ≤ m), and the list of k positions that are exchanged (k distinct indices from 1 to m in any order). The final line should contain a permutation of integers from 1 to n, describing the way the strings should be reordered. The strings will be placed in the order indices placed in this permutation, the stolen string index will be ignored. Output For each test case print a single line with the stolen string. Example Input 3 3 5 aaaaa bbbbb ccccc aaaaa bbbbb 3 4 aaaa bbbb cccc aabb bbaa 5 6 abcdef uuuuuu kekeke ekekek xyzklm xbcklf eueueu ayzdem ukukuk Output ccccc cccc kekeke Note In the first test case, "aaaaa" and "bbbbb" exchanged all positions, and "ccccc" is the stolen string. In the second test case, "aaaa" and "bbbb" exchanged two first positions, and "cccc" is the stolen string. This is the first test in the hack format: 3 3 5 aaaaa bbbbb ccccc 1 2 5 1 2 3 4 5 2 1 3 3 4 aaaa bbbb cccc 1 2 2 1 2 2 1 3 5 6 abcdef uuuuuu kekeke ekekek xyzklm 1 5 3 2 3 6 2 4 3 2 4 6 5 4 1 2 3
instruction
0
13,551
6
27,102
Tags: interactive, math Correct Solution: ``` import sys from bisect import bisect from math import sqrt, ceil, floor def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def rinput(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) mod = int(1e9)+7 for _ in range(iinput()): n, m = rinput() l = [{} for _ in range(m)] ans = "" for _ in range(n): s = input() for i in range(m): l[i][s[i]] = l[i].get(s[i], 0) + 1 for _ in range(n-1): s = input() for i in range(m): l[i][s[i]] = l[i].get(s[i], 0) + 1 for i in range(m): for key in l[i]: if l[i][key]%2 == 1: ans += key break print(ans) ```
output
1
13,551
6
27,103
Provide tags and a correct Python 3 solution for this coding contest problem. AquaMoon had n strings of length m each. n is an odd number. When AquaMoon was gone, Cirno tried to pair these n strings together. After making (n-1)/(2) pairs, she found out that there was exactly one string without the pair! In her rage, she disrupted each pair of strings. For each pair, she selected some positions (at least 1 and at most m) and swapped the letters in the two strings of this pair at the selected positions. For example, if m = 6 and two strings "abcdef" and "xyzklm" are in one pair and Cirno selected positions 2, 3 and 6 she will swap 'b' with 'y', 'c' with 'z' and 'f' with 'm'. The resulting strings will be "ayzdem" and "xbcklf". Cirno then stole away the string without pair and shuffled all remaining strings in arbitrary order. AquaMoon found the remaining n-1 strings in complete disarray. Also, she remembers the initial n strings. She wants to know which string was stolen, but she is not good at programming. Can you help her? Input This problem is made as interactive. It means, that your solution will read the input, given by the interactor. But the interactor will give you the full input at the beginning and after that, you should print the answer. So you should solve the problem, like as you solve the usual, non-interactive problem because you won't have any interaction process. The only thing you should not forget is to flush the output buffer, after printing the answer. Otherwise, you can get an "Idleness limit exceeded" verdict. Refer to the [interactive problems guide](https://codeforces.com/blog/entry/45307) for the detailed information about flushing the output buffer. The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The first line of each test case contains two integers n, m (1 ≤ n ≤ 10^5, 1 ≤ m ≤ 10^5) — the number of strings and the length of each string, respectively. The next n lines each contain a string with length m, describing the original n strings. All string consists of lowercase Latin letters. The next n-1 lines each contain a string with length m, describing the strings after Cirno exchanged and reordered them. It is guaranteed that n is odd and that the sum of n ⋅ m over all test cases does not exceed 10^5. Hack format: The first line should contain a single integer t. After that t test cases should follow in the following format: The first line should contain two integers n and m. The following n lines should contain n strings of length m, describing the original strings. The following (n-1)/(2) lines should describe the pairs. They should contain, in the following order: the index of the first string i (1 ≤ i ≤ n), the index of the second string j (1 ≤ j ≤ n, i ≠ j), the number of exchanged positions k (1 ≤ k ≤ m), and the list of k positions that are exchanged (k distinct indices from 1 to m in any order). The final line should contain a permutation of integers from 1 to n, describing the way the strings should be reordered. The strings will be placed in the order indices placed in this permutation, the stolen string index will be ignored. Output For each test case print a single line with the stolen string. Example Input 3 3 5 aaaaa bbbbb ccccc aaaaa bbbbb 3 4 aaaa bbbb cccc aabb bbaa 5 6 abcdef uuuuuu kekeke ekekek xyzklm xbcklf eueueu ayzdem ukukuk Output ccccc cccc kekeke Note In the first test case, "aaaaa" and "bbbbb" exchanged all positions, and "ccccc" is the stolen string. In the second test case, "aaaa" and "bbbb" exchanged two first positions, and "cccc" is the stolen string. This is the first test in the hack format: 3 3 5 aaaaa bbbbb ccccc 1 2 5 1 2 3 4 5 2 1 3 3 4 aaaa bbbb cccc 1 2 2 1 2 2 1 3 5 6 abcdef uuuuuu kekeke ekekek xyzklm 1 5 3 2 3 6 2 4 3 2 4 6 5 4 1 2 3
instruction
0
13,552
6
27,104
Tags: interactive, math Correct Solution: ``` import sys from string import ascii_lowercase as alph t = int(input()) for _ in range(t): n, m = map(int, input().split()) cnt = [0] * m for i in range(n): ind = 0 for x in input(): cnt[ind] += alph.index(x) + 1 ind += 1 for i in range(n - 1): ind = 0 for x in input(): cnt[ind] -= alph.index(x) + 1 ind += 1 for i in range(m): ind = cnt[i] if ind != 0: print(alph[ind - 1], end='') print() sys.stdout.flush() ```
output
1
13,552
6
27,105
Provide tags and a correct Python 3 solution for this coding contest problem. AquaMoon had n strings of length m each. n is an odd number. When AquaMoon was gone, Cirno tried to pair these n strings together. After making (n-1)/(2) pairs, she found out that there was exactly one string without the pair! In her rage, she disrupted each pair of strings. For each pair, she selected some positions (at least 1 and at most m) and swapped the letters in the two strings of this pair at the selected positions. For example, if m = 6 and two strings "abcdef" and "xyzklm" are in one pair and Cirno selected positions 2, 3 and 6 she will swap 'b' with 'y', 'c' with 'z' and 'f' with 'm'. The resulting strings will be "ayzdem" and "xbcklf". Cirno then stole away the string without pair and shuffled all remaining strings in arbitrary order. AquaMoon found the remaining n-1 strings in complete disarray. Also, she remembers the initial n strings. She wants to know which string was stolen, but she is not good at programming. Can you help her? Input This problem is made as interactive. It means, that your solution will read the input, given by the interactor. But the interactor will give you the full input at the beginning and after that, you should print the answer. So you should solve the problem, like as you solve the usual, non-interactive problem because you won't have any interaction process. The only thing you should not forget is to flush the output buffer, after printing the answer. Otherwise, you can get an "Idleness limit exceeded" verdict. Refer to the [interactive problems guide](https://codeforces.com/blog/entry/45307) for the detailed information about flushing the output buffer. The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The first line of each test case contains two integers n, m (1 ≤ n ≤ 10^5, 1 ≤ m ≤ 10^5) — the number of strings and the length of each string, respectively. The next n lines each contain a string with length m, describing the original n strings. All string consists of lowercase Latin letters. The next n-1 lines each contain a string with length m, describing the strings after Cirno exchanged and reordered them. It is guaranteed that n is odd and that the sum of n ⋅ m over all test cases does not exceed 10^5. Hack format: The first line should contain a single integer t. After that t test cases should follow in the following format: The first line should contain two integers n and m. The following n lines should contain n strings of length m, describing the original strings. The following (n-1)/(2) lines should describe the pairs. They should contain, in the following order: the index of the first string i (1 ≤ i ≤ n), the index of the second string j (1 ≤ j ≤ n, i ≠ j), the number of exchanged positions k (1 ≤ k ≤ m), and the list of k positions that are exchanged (k distinct indices from 1 to m in any order). The final line should contain a permutation of integers from 1 to n, describing the way the strings should be reordered. The strings will be placed in the order indices placed in this permutation, the stolen string index will be ignored. Output For each test case print a single line with the stolen string. Example Input 3 3 5 aaaaa bbbbb ccccc aaaaa bbbbb 3 4 aaaa bbbb cccc aabb bbaa 5 6 abcdef uuuuuu kekeke ekekek xyzklm xbcklf eueueu ayzdem ukukuk Output ccccc cccc kekeke Note In the first test case, "aaaaa" and "bbbbb" exchanged all positions, and "ccccc" is the stolen string. In the second test case, "aaaa" and "bbbb" exchanged two first positions, and "cccc" is the stolen string. This is the first test in the hack format: 3 3 5 aaaaa bbbbb ccccc 1 2 5 1 2 3 4 5 2 1 3 3 4 aaaa bbbb cccc 1 2 2 1 2 2 1 3 5 6 abcdef uuuuuu kekeke ekekek xyzklm 1 5 3 2 3 6 2 4 3 2 4 6 5 4 1 2 3
instruction
0
13,553
6
27,106
Tags: interactive, math Correct Solution: ``` import sys from copy import deepcopy input = sys.stdin.readline for _ in range(int(input())): n, m = map(int, input().split()) total = [0 for _ in range(m)] for i in range(n): tmp = list(input().rstrip()) for j in range(len(tmp)): total[j] += ord(tmp[j]) for i in range(n - 1): tmp = list(input().rstrip()) for j in range(len(tmp)): total[j] -= ord(tmp[j]) for i in range(m): print(chr(total[i]), end = '', flush=True) print() ```
output
1
13,553
6
27,107
Provide tags and a correct Python 3 solution for this coding contest problem. AquaMoon had n strings of length m each. n is an odd number. When AquaMoon was gone, Cirno tried to pair these n strings together. After making (n-1)/(2) pairs, she found out that there was exactly one string without the pair! In her rage, she disrupted each pair of strings. For each pair, she selected some positions (at least 1 and at most m) and swapped the letters in the two strings of this pair at the selected positions. For example, if m = 6 and two strings "abcdef" and "xyzklm" are in one pair and Cirno selected positions 2, 3 and 6 she will swap 'b' with 'y', 'c' with 'z' and 'f' with 'm'. The resulting strings will be "ayzdem" and "xbcklf". Cirno then stole away the string without pair and shuffled all remaining strings in arbitrary order. AquaMoon found the remaining n-1 strings in complete disarray. Also, she remembers the initial n strings. She wants to know which string was stolen, but she is not good at programming. Can you help her? Input This problem is made as interactive. It means, that your solution will read the input, given by the interactor. But the interactor will give you the full input at the beginning and after that, you should print the answer. So you should solve the problem, like as you solve the usual, non-interactive problem because you won't have any interaction process. The only thing you should not forget is to flush the output buffer, after printing the answer. Otherwise, you can get an "Idleness limit exceeded" verdict. Refer to the [interactive problems guide](https://codeforces.com/blog/entry/45307) for the detailed information about flushing the output buffer. The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The first line of each test case contains two integers n, m (1 ≤ n ≤ 10^5, 1 ≤ m ≤ 10^5) — the number of strings and the length of each string, respectively. The next n lines each contain a string with length m, describing the original n strings. All string consists of lowercase Latin letters. The next n-1 lines each contain a string with length m, describing the strings after Cirno exchanged and reordered them. It is guaranteed that n is odd and that the sum of n ⋅ m over all test cases does not exceed 10^5. Hack format: The first line should contain a single integer t. After that t test cases should follow in the following format: The first line should contain two integers n and m. The following n lines should contain n strings of length m, describing the original strings. The following (n-1)/(2) lines should describe the pairs. They should contain, in the following order: the index of the first string i (1 ≤ i ≤ n), the index of the second string j (1 ≤ j ≤ n, i ≠ j), the number of exchanged positions k (1 ≤ k ≤ m), and the list of k positions that are exchanged (k distinct indices from 1 to m in any order). The final line should contain a permutation of integers from 1 to n, describing the way the strings should be reordered. The strings will be placed in the order indices placed in this permutation, the stolen string index will be ignored. Output For each test case print a single line with the stolen string. Example Input 3 3 5 aaaaa bbbbb ccccc aaaaa bbbbb 3 4 aaaa bbbb cccc aabb bbaa 5 6 abcdef uuuuuu kekeke ekekek xyzklm xbcklf eueueu ayzdem ukukuk Output ccccc cccc kekeke Note In the first test case, "aaaaa" and "bbbbb" exchanged all positions, and "ccccc" is the stolen string. In the second test case, "aaaa" and "bbbb" exchanged two first positions, and "cccc" is the stolen string. This is the first test in the hack format: 3 3 5 aaaaa bbbbb ccccc 1 2 5 1 2 3 4 5 2 1 3 3 4 aaaa bbbb cccc 1 2 2 1 2 2 1 3 5 6 abcdef uuuuuu kekeke ekekek xyzklm 1 5 3 2 3 6 2 4 3 2 4 6 5 4 1 2 3
instruction
0
13,554
6
27,108
Tags: interactive, math Correct Solution: ``` #!/usr/bin/python3 # -*- coding: utf-8 -*- ''' f = open('test.txt') byt = f.readlines() for x in byt: print(x) print(byt) ''' t = int(input()) while t > 0: t -= 1 s = input().split() n = int(s[0]) m = int(s[1]) #建立每列的字典的列表 a = [] for i in range(n): s = input() if i == 0: for x in s: ai = dict() ai[x] = 1 a.append(ai) else: for j in range(m): ai = a[j] if ai.get(s[j]) == None: ai[s[j]] = 1 else: ai[s[j]] += 1 a[j] = ai #从每列的字典中删除出现过的 for i in range(n-1): s = input() for j in range(m): ai = a[j] if ai[s[j]] == 1: del ai[s[j]] else: ai[s[j]] -= 1 #将每列剩余的一个拼接在一块儿 ans = '' for j in range(m): ai = a[j] key = list(ai.keys())[0] ans += key print(ans) ```
output
1
13,554
6
27,109
Provide tags and a correct Python 3 solution for this coding contest problem. AquaMoon had n strings of length m each. n is an odd number. When AquaMoon was gone, Cirno tried to pair these n strings together. After making (n-1)/(2) pairs, she found out that there was exactly one string without the pair! In her rage, she disrupted each pair of strings. For each pair, she selected some positions (at least 1 and at most m) and swapped the letters in the two strings of this pair at the selected positions. For example, if m = 6 and two strings "abcdef" and "xyzklm" are in one pair and Cirno selected positions 2, 3 and 6 she will swap 'b' with 'y', 'c' with 'z' and 'f' with 'm'. The resulting strings will be "ayzdem" and "xbcklf". Cirno then stole away the string without pair and shuffled all remaining strings in arbitrary order. AquaMoon found the remaining n-1 strings in complete disarray. Also, she remembers the initial n strings. She wants to know which string was stolen, but she is not good at programming. Can you help her? Input This problem is made as interactive. It means, that your solution will read the input, given by the interactor. But the interactor will give you the full input at the beginning and after that, you should print the answer. So you should solve the problem, like as you solve the usual, non-interactive problem because you won't have any interaction process. The only thing you should not forget is to flush the output buffer, after printing the answer. Otherwise, you can get an "Idleness limit exceeded" verdict. Refer to the [interactive problems guide](https://codeforces.com/blog/entry/45307) for the detailed information about flushing the output buffer. The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The first line of each test case contains two integers n, m (1 ≤ n ≤ 10^5, 1 ≤ m ≤ 10^5) — the number of strings and the length of each string, respectively. The next n lines each contain a string with length m, describing the original n strings. All string consists of lowercase Latin letters. The next n-1 lines each contain a string with length m, describing the strings after Cirno exchanged and reordered them. It is guaranteed that n is odd and that the sum of n ⋅ m over all test cases does not exceed 10^5. Hack format: The first line should contain a single integer t. After that t test cases should follow in the following format: The first line should contain two integers n and m. The following n lines should contain n strings of length m, describing the original strings. The following (n-1)/(2) lines should describe the pairs. They should contain, in the following order: the index of the first string i (1 ≤ i ≤ n), the index of the second string j (1 ≤ j ≤ n, i ≠ j), the number of exchanged positions k (1 ≤ k ≤ m), and the list of k positions that are exchanged (k distinct indices from 1 to m in any order). The final line should contain a permutation of integers from 1 to n, describing the way the strings should be reordered. The strings will be placed in the order indices placed in this permutation, the stolen string index will be ignored. Output For each test case print a single line with the stolen string. Example Input 3 3 5 aaaaa bbbbb ccccc aaaaa bbbbb 3 4 aaaa bbbb cccc aabb bbaa 5 6 abcdef uuuuuu kekeke ekekek xyzklm xbcklf eueueu ayzdem ukukuk Output ccccc cccc kekeke Note In the first test case, "aaaaa" and "bbbbb" exchanged all positions, and "ccccc" is the stolen string. In the second test case, "aaaa" and "bbbb" exchanged two first positions, and "cccc" is the stolen string. This is the first test in the hack format: 3 3 5 aaaaa bbbbb ccccc 1 2 5 1 2 3 4 5 2 1 3 3 4 aaaa bbbb cccc 1 2 2 1 2 2 1 3 5 6 abcdef uuuuuu kekeke ekekek xyzklm 1 5 3 2 3 6 2 4 3 2 4 6 5 4 1 2 3
instruction
0
13,555
6
27,110
Tags: interactive, math Correct Solution: ``` from collections import Counter for _ in range(int(input())): n, m = map(int, input().split()) f = [];l = [] f1={};l1={} for i in range(n): f += [input()] for j in range(n - 1): l += [input()] for i in range(m): s="";t="" for j in range(n): s+=f[j][i] if j <len(l): t+=l[j][i] f1[i]=list(s) l1[i]=list(t) res=[] for i in range(m): w=list(f1[i]) t=list(l1[i]) res+= list((Counter(w) - Counter(t)).elements()) print("".join(res)) ```
output
1
13,555
6
27,111
Provide tags and a correct Python 3 solution for this coding contest problem. The DNA sequence for every living creature in Berland can be represented as a non-empty line consisting of lowercase Latin letters. Berland scientists found out that all the creatures evolve by stages. During one stage exactly one symbol of the DNA line is replaced by exactly two other ones. At that overall there are n permissible substitutions. The substitution ai->bici means that any one symbol ai can be replaced with two symbols bici. Every substitution could happen an unlimited number of times. They say that two creatures with DNA sequences s1 and s2 can have a common ancestor if there exists such a DNA sequence s3 that throughout evolution it can result in s1 and s2, perhaps after a different number of stages. Your task is to find out by the given s1 and s2 whether the creatures possessing such DNA sequences can have a common ancestor. If the answer is positive, you have to find the length of the shortest sequence of the common ancestor’s DNA. Input The first line contains a non-empty DNA sequence s1, the second line contains a non-empty DNA sequence s2. The lengths of these lines do not exceed 50, the lines contain only lowercase Latin letters. The third line contains an integer n (0 ≤ n ≤ 50) — the number of permissible substitutions. Then follow n lines each of which describes a substitution in the format ai->bici. The characters ai, bi, and ci are lowercase Latin letters. Lines s1 and s2 can coincide, the list of substitutions can contain similar substitutions. Output If s1 and s2 cannot have a common ancestor, print -1. Otherwise print the length of the shortest sequence s3, from which s1 and s2 could have evolved. Examples Input ababa aba 2 c-&gt;ba c-&gt;cc Output 2 Input ababa aba 7 c-&gt;ba c-&gt;cc e-&gt;ab z-&gt;ea b-&gt;ba d-&gt;dd d-&gt;ab Output 1 Input ababa aba 1 c-&gt;ba Output -1
instruction
0
13,687
6
27,374
Tags: dp Correct Solution: ``` #!/usr/bin/env python3 import itertools import collections # Read input strings s1 = input() s2 = input() # Read evolution rules, use a mapping from the 2 target characters to the source character rules = collections.defaultdict(set) n = int(input()) for i in range(n): rule = input() target = rule[-2:] source = rule[0] rules[target].add(source) def substrings_of_precise_length(s, l): # Generator for all substrings of s that are of length l for start_pos in range(len(s)-l+1): yield s[start_pos:start_pos+l] def substrings_of_minimum_length(s, minlen): # Generator for all substrings of s that are of length l or larger, in order from short to long length return itertools.chain.from_iterable(substrings_of_precise_length(s,l) for l in range(minlen, len(s)+1)) def partitions_of_string(s): # Generator for all possible pairs (a,b) such that a+b = c where a and b are not empty strings for l1 in range(1, len(s)): yield (s[:l1], s[l1:]) # Dictionary mapping strings onto the set of single characters from which those strings could evolve ancestors = collections.defaultdict(set) def update_ancestors(ancestors, rules, s): # Update the ancestor dictionary for string s # O(len(s)**3 * len(rules)) # All single characters can "evolve" from a single character for c in s: ancestors[c].add(c) # Examine all substrings of s, in order of increasing length for sub in substrings_of_minimum_length(s, 2): # Examine any way the substring can be created from two seperate, smaller strings for (sub1, sub2) in partitions_of_string(sub): # Check all rules to see if the two substrings can evolve from a single character by using that rule for target, sources in rules.items(): if (target[0] in ancestors[sub1]) and (target[1] in ancestors[sub2]): ancestors[sub].update(sources) # Update the ancestors based on s1 and s2 update_ancestors(ancestors, rules, s1) update_ancestors(ancestors, rules, s2) def prefixes(s): # Generator for all non-empty prefixes of s, in order of increasing length for l in range(1, len(s)+1): yield s[:l] def determine_shortest_common_ancestor(ancestors, s1, s2): # Returns the length of the shortest common ancestor of string s1 and s2, or float('inf') if there is no common ancestor. # The ancestors is a dictionary that contains for every substring of s1 and s2 the set of single characters from which that substring can evolve # O(len(s1)**2 * len(s2)**2 * 26 ) # Dictionary mapping pairs of strings onto the length of their shortest common ancestor shortest_common_ancestor = collections.defaultdict(lambda:float('inf')) # Check every possible combinations of prefixes of s1 and s2 for (pre1,pre2) in itertools.product(prefixes(s1), prefixes(s2)): # If both prefixes have an overlap in the single character from which they can evolve, then the shortest common ancestor is 1 letter if not ancestors[pre1].isdisjoint(ancestors[pre2]): shortest_common_ancestor[(pre1,pre2)] = 1 # Check all possible combinations of partitions of pre1 and pre2 temp = shortest_common_ancestor[(pre1, pre2)] for ((sub1a,sub1b),(sub2a,sub2b)) in itertools.product(partitions_of_string(pre1), partitions_of_string(pre2)): if not ancestors[sub1b].isdisjoint(ancestors[sub2b]): # sub1b and sub2b can evolve from the same character, so the shortest common ancestor of sub1a+sub1b and sub2a+sub2b is # never longer than the shortest common ancestor of sub1a and sub2a plus the one letter from which sub1b and sub2b can evolve temp = min(temp, shortest_common_ancestor[(sub1a, sub2a)] + 1) shortest_common_ancestor[(pre1, pre2)] = temp return shortest_common_ancestor[(s1, s2)] answer = determine_shortest_common_ancestor(ancestors, s1, s2) if (answer == float('inf')): print(-1) else: print(answer) ```
output
1
13,687
6
27,375
Provide tags and a correct Python 3 solution for this coding contest problem. Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. * Masculine adjectives end with -lios, and feminine adjectives end with -liala. * Masculine nouns end with -etr, and feminime nouns end with -etra. * Masculine verbs end with -initis, and feminime verbs end with -inites. * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. * A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. * All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. Input The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. Output If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). Examples Input petr Output YES Input etis atis animatis etis atis amatis Output NO Input nataliala kataliala vetra feinites Output YES
instruction
0
14,198
6
28,396
Tags: implementation, strings Correct Solution: ``` import re al = re.compile(r'^1*23*$') def getType(word): if word.endswith("lios"): return 1 elif word.endswith("liala"): return -1 elif word.endswith("etr"): return 2 elif word.endswith("etra"): return -2 elif word.endswith("initis"):return 3 elif word.endswith("inites"): return -3 else: return 0 words = input().strip().split() words = [getType(x) for x in words] if len(words) == 1: if words[0] != 0:print("YES") else:print("NO") else: p = words[0] for x in words: if p*x <= 0: print("NO") exit() words = [str(abs(x)) for x in words] words = "".join(words) if al.match(words):print("YES") else:print("NO") # Made By Mostafa_Khaled ```
output
1
14,198
6
28,397
Provide tags and a correct Python 3 solution for this coding contest problem. Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. * Masculine adjectives end with -lios, and feminine adjectives end with -liala. * Masculine nouns end with -etr, and feminime nouns end with -etra. * Masculine verbs end with -initis, and feminime verbs end with -inites. * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. * A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. * All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. Input The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. Output If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). Examples Input petr Output YES Input etis atis animatis etis atis amatis Output NO Input nataliala kataliala vetra feinites Output YES
instruction
0
14,199
6
28,398
Tags: implementation, strings Correct Solution: ``` def f(a): b=len(a) if b>=4 and a[-4:]=='lios': return [1,1] if b>=5 and a[-5:]=='liala': return [1,2] if b>=3 and a[-3:]=='etr': return [2,1] if b>=4 and a[-4:]=='etra': return [2,2] if b>=6 and a[-6:]=='initis': return [3,1] if b>=6 and a[-6:]=='inites': return [3,2] return -1 a=[f(i) for i in input().split()] n=len(a) if -1 in a or [i[1] for i in a]!=[a[0][1]]*n: print('NO') else: i,j=0,n-1 while i<n and a[i][0]==1: i+=1 while j>=0 and a[j][0]==3: j-=1 print('YES' if i==j or n==1 else 'NO') ```
output
1
14,199
6
28,399
Provide tags and a correct Python 3 solution for this coding contest problem. Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. * Masculine adjectives end with -lios, and feminine adjectives end with -liala. * Masculine nouns end with -etr, and feminime nouns end with -etra. * Masculine verbs end with -initis, and feminime verbs end with -inites. * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. * A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. * All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. Input The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. Output If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). Examples Input petr Output YES Input etis atis animatis etis atis amatis Output NO Input nataliala kataliala vetra feinites Output YES
instruction
0
14,200
6
28,400
Tags: implementation, strings Correct Solution: ``` import re t = input() p = [r'([^ ]*lios )*([^ ]*etr)( [^ ]*initis)*', r'([^ ]*liala )*([^ ]*etra)( [^ ]*inites)*', r'[^ ]*(li(os|ala)|etra?|init[ie]s)'] print(['NO', 'YES'][any(re.fullmatch(q, t) for q in p)]) ```
output
1
14,200
6
28,401
Provide tags and a correct Python 3 solution for this coding contest problem. Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. * Masculine adjectives end with -lios, and feminine adjectives end with -liala. * Masculine nouns end with -etr, and feminime nouns end with -etra. * Masculine verbs end with -initis, and feminime verbs end with -inites. * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. * A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. * All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. Input The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. Output If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). Examples Input petr Output YES Input etis atis animatis etis atis amatis Output NO Input nataliala kataliala vetra feinites Output YES
instruction
0
14,201
6
28,402
Tags: implementation, strings Correct Solution: ``` s, n, m, f = input().split(), False, False, False def cc(w, me, fe): global m, f if w.endswith(me): m = True return True elif w.endswith(fe): f = True return True else: return False def ad(w): return cc(w, 'lios', 'liala') def nn(w): return cc(w, 'etr', 'etra') def vb(w): return cc(w, 'initis', 'inites') for w in s: if not n: if ad(w) or vb(w) and len(s) == 1: pass elif nn(w): n = True else: print('NO') exit() elif not vb(w): print('NO') exit() print('YES' if len(s) == 1 or (n and (m ^ f)) else 'NO') ```
output
1
14,201
6
28,403
Provide tags and a correct Python 3 solution for this coding contest problem. Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. * Masculine adjectives end with -lios, and feminine adjectives end with -liala. * Masculine nouns end with -etr, and feminime nouns end with -etra. * Masculine verbs end with -initis, and feminime verbs end with -inites. * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. * A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. * All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. Input The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. Output If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). Examples Input petr Output YES Input etis atis animatis etis atis amatis Output NO Input nataliala kataliala vetra feinites Output YES
instruction
0
14,202
6
28,404
Tags: implementation, strings Correct Solution: ``` # from dust i have come dust i will be #each should be of same gender #adjective*-noun*1-verb* a=list(map(str,input().split())) t=[0]*len(a) str=["lios","liala","etr","etra","initis","inites"] if len(a)==1: for i in range(6): if a[0].endswith(str[i]): print("YES") exit(0) print("NO") exit(0) for i in range(len(a)): for j in range(6): if a[i].endswith(str[j]): t[i]=j+1 break #not belonging in any language if t[i]==0: print("NO") exit(0) #all the t[]'s should be either or odd rem=t[0]%2 for i in range(len(t)): if t[i]%2!=rem: print("NO") exit(0) x=sorted(t) cnt=0 for i in range(len(t)): if t[i]==3 or t[i]==4: cnt+=1 if t[i]!=x[i]: print("NO") exit(0) if cnt==1: print("YES") else: print("NO") ```
output
1
14,202
6
28,405
Provide tags and a correct Python 3 solution for this coding contest problem. Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. * Masculine adjectives end with -lios, and feminine adjectives end with -liala. * Masculine nouns end with -etr, and feminime nouns end with -etra. * Masculine verbs end with -initis, and feminime verbs end with -inites. * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. * A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. * All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. Input The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. Output If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). Examples Input petr Output YES Input etis atis animatis etis atis amatis Output NO Input nataliala kataliala vetra feinites Output YES
instruction
0
14,203
6
28,406
Tags: implementation, strings Correct Solution: ``` madj = "lios" fadj = "liala" mnoun = "etr" fnoun = "etra" mver = "initis" fver = "inites" def valid_word(word): sz = len(word) if word[sz-len(mver):] == mver: return (0, "v") if word[sz-len(mver):] == fver: return (1, "v") if word[sz-len(fadj):] == fadj: return (1, "a") if word[sz-len(madj):] == madj: return (0, "a") if word[sz-len(fnoun):] == fnoun: return (1, "n") if word[sz-len(mnoun):] == mnoun: return (0, "n") return False def valid_sentence(l): if len(l) == 1: if valid_word(l[0]): return True else: return False tupla = valid_word(l[0]) if tupla: genero, tipo = tupla else: return False flag = False for i in range(0, len(l)): tupla = valid_word(l[i]) if tupla: g, t = tupla else: return False if g != genero: return False if t == "a": if flag == True: return False if t == "n": if flag == True: return False flag = True if t == "v": if flag == False: return False return flag l = input().split(' ') if valid_sentence(l): print("YES") else: print("NO") ```
output
1
14,203
6
28,407
Provide tags and a correct Python 3 solution for this coding contest problem. Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. * Masculine adjectives end with -lios, and feminine adjectives end with -liala. * Masculine nouns end with -etr, and feminime nouns end with -etra. * Masculine verbs end with -initis, and feminime verbs end with -inites. * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. * A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. * All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. Input The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. Output If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). Examples Input petr Output YES Input etis atis animatis etis atis amatis Output NO Input nataliala kataliala vetra feinites Output YES
instruction
0
14,204
6
28,408
Tags: implementation, strings Correct Solution: ``` def method(a,key): key_len = [ len(i) for i in key ] data = [] for i in a: temp = None x,y,z = i[-key_len[0]::],i[-key_len[1]::],i[-key_len[2]::] if x in key: temp = key.index(x) elif y in key: temp = key.index(y) elif z in key: temp = key.index(z) if temp==None: return [] else: data.append(temp) return data def language(a): m =['lios','etr','initis'] f =['liala','etra','inites'] a = a.split() data_m = method(a,m) data_f = method(a,f) data = data_m if len(data_m)>len(data_f) else data_f try: assert len(a)==len(data) if len(data)==1: pass else: assert data.count(1)==1 for i in range(len(data)-1): assert data[i]<=data[i+1] return "YES" except: return "NO" a = input() print(language(a)) ```
output
1
14,204
6
28,409
Provide tags and a correct Python 3 solution for this coding contest problem. Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. * Masculine adjectives end with -lios, and feminine adjectives end with -liala. * Masculine nouns end with -etr, and feminime nouns end with -etra. * Masculine verbs end with -initis, and feminime verbs end with -inites. * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. * A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. * All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. Input The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. Output If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). Examples Input petr Output YES Input etis atis animatis etis atis amatis Output NO Input nataliala kataliala vetra feinites Output YES
instruction
0
14,205
6
28,410
Tags: implementation, strings Correct Solution: ``` import sys def solve(): validendings = ["lios", "liala", "etr", "etra", "initis", "inites"] s = input().split() if len(s) == 1: if endswith(s[0], validendings): print("YES") return print("NO") return nounends = ["etr", "etra"] nouns = list() for i, word in enumerate(s): if endswith(word, nounends): nouns.append(i) if len(nouns) != 1: print("NO") return nounindex, noun = nouns[0], s[nouns[0]] malenoun = True if endswith(noun, ["etr"]) else False adjectives = list() verbs = list() for i in range(nounindex): word = s[i] shouldendwith = "lios" if malenoun else "liala" if endswith(word, [shouldendwith]): adjectives.append(i) for i in range(nounindex + 1, len(s)): word = s[i] shouldendwith = "initis" if malenoun else "inites" if endswith(word, [shouldendwith]): verbs.append(i) if 1 + len(adjectives) + len(verbs) == len(s): print("YES") return print("NO") def endswith(word, validendings): for ending in validendings: if len(word) >= len(ending): if word[-len(ending) : ] == ending: return True return False def rv(): return map(int, input().split()) def rl(n): return [list(map(int, input().split())) for _ in range(n)] if sys.hexversion == 50594544 : sys.stdin = open("test.txt") solve() ```
output
1
14,205
6
28,411
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. * Masculine adjectives end with -lios, and feminine adjectives end with -liala. * Masculine nouns end with -etr, and feminime nouns end with -etra. * Masculine verbs end with -initis, and feminime verbs end with -inites. * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. * A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. * All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. Input The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. Output If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). Examples Input petr Output YES Input etis atis animatis etis atis amatis Output NO Input nataliala kataliala vetra feinites Output YES Submitted Solution: ``` def ch_gen(word): for x in gen: for w in range(3): try: if word[-len(gen[x][w]):] == gen[x][w]: return (x,str(w)) except IndexError: continue return (-1,-1) gen = {0:['lios','etr','initis'],1:['liala','etra','inites']} s = input().split() if len(s) == 1: print("YES" if ch_gen(s[0])[0] != -1 else "NO") else: gender = ch_gen(s[0]); arr = [0]*len(s); arr[0] = gender[1]; flag = True for t in range(1,len(s)): nxt = ch_gen(s[t]); arr[t] = nxt[1] if nxt[0]!=gender[0] or gender[0] == -1: print('NO'); exit() act = "".join(arr); tur,fur,cur,sir,nut= act.count('1'),act.count('02'),act.count('20'),act.count('21'),act.count('10') if tur == 0 or tur > 1 or fur or cur or sir or nut: flag = False print("YES" if flag else "NO") ```
instruction
0
14,206
6
28,412
Yes
output
1
14,206
6
28,413
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. * Masculine adjectives end with -lios, and feminine adjectives end with -liala. * Masculine nouns end with -etr, and feminime nouns end with -etra. * Masculine verbs end with -initis, and feminime verbs end with -inites. * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. * A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. * All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. Input The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. Output If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). Examples Input petr Output YES Input etis atis animatis etis atis amatis Output NO Input nataliala kataliala vetra feinites Output YES Submitted Solution: ``` s = input() l_adj = ['lios', 'liala'] l_noun = ['etr', 'etra'] l_verb = ['initis', 'inites'] word = [] temp_index = 0 for i in range(len(s)): if s[i]==" ": word.append(s[temp_index:i]) temp_index = i+1 elif i == len(s)-1: word.append(s[temp_index:i+1]) index_adj_mas = [] index_noun_mas= [] index_verb_mas = [] index_adj_fem = [] index_noun_fem = [] index_verb_fem = [] mas = [] fem = [] for i in range(len(word)): if word[i].endswith(l_noun[0]): mas.append(word[i]) index_noun_mas.append(i) elif word[i].endswith(l_adj[0]): mas.append(word[i]) index_adj_mas.append(i) elif word[i].endswith(l_verb[0]): mas.append(word[i]) index_verb_mas.append(i) elif word[i].endswith(l_noun[1]): fem.append(word[i]) index_noun_fem.append(i) elif word[i].endswith(l_adj[1]): fem.append(word[i]) index_adj_fem.append(i) elif word[i].endswith(l_verb[1]): fem.append(word[i]) index_verb_fem.append(i) ''' print(mas , fem) print(len(mas),len(fem),len(word)) print(index_adj_mas, index_noun_mas, index_verb_mas, index_adj_fem, index_noun_fem, index_verb_fem) ''' def f(word): flag = 0 if len(word)==1: if len(index_adj_mas)+len(index_noun_mas)+len(index_verb_mas)+len(index_adj_fem)+len(index_noun_fem)+len(index_verb_fem) == 0: flag = 1 else: flag = 0 else: if (len(mas)==len(word) or len(fem)==len(word)) and (len(index_noun_fem)==1 or len(index_noun_mas)==1): #print("Yes") if len(fem)==len(word): if len(index_adj_fem)>0: for i in range(len(index_adj_fem)): if index_noun_fem[0] <= index_adj_fem[i]: flag = 1 #false/no #print("1") break if len(index_verb_fem)>0: for i in range(len(index_verb_fem)): if index_noun_fem[0] >= index_verb_fem[i]: flag = 1 #false/no #print("2") break elif len(mas)==len(word): if len(index_adj_mas)>0: for i in range(len(index_adj_mas)): if index_noun_mas[0] <= index_adj_mas[i]: flag = 1 #false/no #print("3") break if len(index_verb_mas)>0: for i in range(len(index_verb_mas)): if index_noun_mas[0] >= index_verb_mas[i]: flag = 1 #false/no #print("4") break elif (len(mas)!= len(word) or len(fem)!=len(word)): flag = 1 #print("5") elif len(index_noun_fem)!=1 or len(index_noun_mas)!=1: flag = 1 return flag #print(word) result = f(word) if result==0: print("YES") else: print("NO") ```
instruction
0
14,207
6
28,414
Yes
output
1
14,207
6
28,415
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. * Masculine adjectives end with -lios, and feminine adjectives end with -liala. * Masculine nouns end with -etr, and feminime nouns end with -etra. * Masculine verbs end with -initis, and feminime verbs end with -inites. * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. * A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. * All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. Input The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. Output If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). Examples Input petr Output YES Input etis atis animatis etis atis amatis Output NO Input nataliala kataliala vetra feinites Output YES Submitted Solution: ``` import re al = re.compile(r'^1*23*$') def getType(word): if word.endswith("lios"): return 1 elif word.endswith("liala"): return -1 elif word.endswith("etr"): return 2 elif word.endswith("etra"): return -2 elif word.endswith("initis"):return 3 elif word.endswith("inites"): return -3 else: return 0 words = input().strip().split() words = [getType(x) for x in words] if len(words) == 1: if words[0] != 0:print("YES") else:print("NO") else: p = words[0] for x in words: if p*x <= 0: print("NO") exit() words = [str(abs(x)) for x in words] words = "".join(words) if al.match(words):print("YES") else:print("NO") ```
instruction
0
14,208
6
28,416
Yes
output
1
14,208
6
28,417
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. * Masculine adjectives end with -lios, and feminine adjectives end with -liala. * Masculine nouns end with -etr, and feminime nouns end with -etra. * Masculine verbs end with -initis, and feminime verbs end with -inites. * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. * A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. * All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. Input The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. Output If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). Examples Input petr Output YES Input etis atis animatis etis atis amatis Output NO Input nataliala kataliala vetra feinites Output YES Submitted Solution: ``` lista = input().split() passadj = False passsub = False gender = -1 can = True canF = True # verificando os generos das palavras for i in range(0,len(lista)): if (len(lista[i]) >= 3 and lista[i][len(lista[i])-3::] == "etr") or (len(lista[i]) >= 4 and lista[i][len(lista[i])-4::] == "lios") or (len(lista[i]) >= 6 and lista[i][len(lista[i])-6::] == "initis"): if gender == -1: gender = 1 elif gender == 2: can = False else: if gender == -1: gender = 2 elif gender == 1: can = False # print(can) # verificando os blocos for i in range(0, len(lista)): if (len(lista[i]) >= 4 and lista[i][len(lista[i])-4::] == "lios") or (len(lista[i]) >= 5 and lista[i][len(lista[i])-5::] == "liala"): if(passadj == True): can = False elif (len(lista[i]) >= 3 and lista[i][len(lista[i])-3::] == "etr") or (len(lista[i]) >= 4 and lista[i][len(lista[i])-4::] == "etra"): passadj = True if passsub == True: can = False else: passsub = True elif (len(lista[i]) >= 6 and lista[i][len(lista[i])-6::] == "initis") or (len(lista[i]) >= 6 and lista[i][len(lista[i])-6::] == "inites"): if passadj == False or passsub == False: can = False else: canF = False # print(can) if (len(lista)==1 and canF) or (passsub and canF and can): print("YES\n") else: print("NO\n") ```
instruction
0
14,209
6
28,418
Yes
output
1
14,209
6
28,419
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. * Masculine adjectives end with -lios, and feminine adjectives end with -liala. * Masculine nouns end with -etr, and feminime nouns end with -etra. * Masculine verbs end with -initis, and feminime verbs end with -inites. * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. * A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. * All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. Input The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. Output If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). Examples Input petr Output YES Input etis atis animatis etis atis amatis Output NO Input nataliala kataliala vetra feinites Output YES Submitted Solution: ``` def f(a): b=len(a) if b>=4 and a[-4:]=='lios': return [1,1] if b>=5 and a[-5:]=='liala': return [1,2] if b>=3 and a[-3:]=='etr': return [2,1] if b>=4 and a[-4:]=='etra': return [2,2] if b>=6 and a[-6:]=='initis': return [3,1] if b>=6 and a[-6:]=='inites': return [3,2] return -1 a=[f(i) for i in input().split()] n=len(a) if -1 in a or [i[1] for i in a]!=[a[0][1]]*n: print('NO') else: i,j=0,n-1 while i<n and a[i][0]==1: i+=1 while j>=0 and a[j][0]==3: j-=1 print('YES' if i==j else 'NO') ```
instruction
0
14,210
6
28,420
No
output
1
14,210
6
28,421
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. * Masculine adjectives end with -lios, and feminine adjectives end with -liala. * Masculine nouns end with -etr, and feminime nouns end with -etra. * Masculine verbs end with -initis, and feminime verbs end with -inites. * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. * A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. * All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. Input The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. Output If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). Examples Input petr Output YES Input etis atis animatis etis atis amatis Output NO Input nataliala kataliala vetra feinites Output YES Submitted Solution: ``` ans=list(map(str,input().split())) def tix(s): t=s gender=-1 typ=-1 if(len(t)>=4 and t[len(s)-4:]=='lios'): gender=1 typ=1 if(len(t)>=5 and t[len(s)-5:]=='liala'): gender=0 typ=1 if(len(t)>=3 and t[len(s)-3:]=='etr'): gender=1 typ=2 if(len(t)>=4 and t[len(s)-4:]=='etra'): gender=0 typ=2 if(len(t)>=6 and t[len(s)-6:]=='initis'): gender=1 typ=3 if(len(t)>=6 and t[len(s)-6:]=='inites'): gender=0 typ=3 return [gender,typ] gag=[] sip=[] if(len(ans)==1): if(tix(ans[0])[0]!=-1): print('YES') else: print('NO') exit() for i in range(len(ans)): m=tix(ans[i]) if(m[0]==-1): print('NO') exit() gag.append(m[0]) sip.append(m[1]) if(sip.count(2)!=1): print('NO') exit() if(gag.count(gag[0])!=len(gag)): print('NO') exit() al=[] count=1 for i in range(1,len(sip)): if(sip[i]==sip[i-1]): count+=1 else: al.append(count) count=1 al.append(count) if(len(al)>3): print('NO') exit() if(len(al)==1): print('YES') exit() elif(len(al)==2): if(sip[0]==3): print('NO') exit() else: print('YES') exit() else: if(sip[0]==1 and sip[-1]==3): print('YES') else: print('NO') exit() ```
instruction
0
14,211
6
28,422
No
output
1
14,211
6
28,423
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. * Masculine adjectives end with -lios, and feminine adjectives end with -liala. * Masculine nouns end with -etr, and feminime nouns end with -etra. * Masculine verbs end with -initis, and feminime verbs end with -inites. * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. * A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. * All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. Input The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. Output If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). Examples Input petr Output YES Input etis atis animatis etis atis amatis Output NO Input nataliala kataliala vetra feinites Output YES Submitted Solution: ``` words = [c for c in input().split()] verdict = True category = ["" for i in range(len(words))] for i in range(len(words)): if (not verdict): break if (len(words[i]) < 3): verdict = False elif (words[i][-3:] == "etr" or (len(words[i]) >= 4 and words[i][-4:] == "etra")): category[i] = "noun" elif ((len(words[i]) >= 4 and words[i][-4:] == "lios") or (len(words[i]) >= 5 and words[i][-5:] == "liala")): category[i] = "adjective" elif (len(words[i]) >= 6 and (words[i][-6:] == "initis" or words[i][-6:] == "inites")): category[i] = "verb" else: verdict = False first_noun = -1 for i in range(len(category)): if (category[i] == "noun"): first_noun = i break if (first_noun == -1 and len(words) > 1): verdict = False elif (first_noun != -1): left, right = first_noun - 1, first_noun + 1 while (left >= 0 and category[left] != "noun"): left -= 1 while (right < len(category) and category[right] != "noun"): right += 1 if (left >= 0 or right < len(category)): verdict = False print(("NO" if (not verdict) else "YES")) ```
instruction
0
14,212
6
28,424
No
output
1
14,212
6
28,425
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. * Masculine adjectives end with -lios, and feminine adjectives end with -liala. * Masculine nouns end with -etr, and feminime nouns end with -etra. * Masculine verbs end with -initis, and feminime verbs end with -inites. * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. * A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. * All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. Input The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. Output If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). Examples Input petr Output YES Input etis atis animatis etis atis amatis Output NO Input nataliala kataliala vetra feinites Output YES Submitted Solution: ``` s = input() l_adj = ['lios', 'liala'] l_noun = ['etr', 'etra'] l_verb = ['initis', 'inites'] index_adj_mas = [] index_noun_mas= [] index_verb_mas = [] index_adj_fem = [] index_noun_fem = [] index_verb_fem = [] mas = [] fem = [] word = [] temp_index = 0 for i in range(len(s)): if s[i]==" ": word.append(s[temp_index:i]) temp_index = i+1 elif i == len(s)-1: word.append(s[temp_index:i+1]) #print(word) for i in range(len(word)): if word[i].endswith(l_noun[0]): mas.append(word[i]) index_noun_mas.append(i) elif word[i].endswith(l_adj[0]): mas.append(word[i]) index_adj_mas.append(i) elif word[i].endswith(l_verb[0]): mas.append(word[i]) index_verb_mas.append(i) elif word[i].endswith(l_noun[1]): fem.append(word[i]) index_noun_fem.append(i) elif word[i].endswith(l_adj[1]): fem.append(word[i]) index_adj_fem.append(i) elif word[i].endswith(l_verb[1]): fem.append(word[i]) index_verb_fem.append(i) #print(mas , fem) ''' print(index_adj_mas, index_noun_mas, index_verb_mas, index_adj_fem, index_noun_fem, index_verb_fem) ''' flag = 0 if (len(mas)==len(s) or len(fem)==len(s)) and (len(index_noun_fem)==1 or len(index_noun_mas)==1): #print("Yes") if len(fem)==len(s): for i in range(len(index_adj_fem)): if index_noun_fem[0] <= index_adj_fem[i]: flag = 1 #false/no break for i in range(len(index_verb_fem)): if index_noun_fem[0] >= index_verb_fem[i]: flag = 1 #false/no break elif len(mas)==len(s): for i in range(len(index_adj_mas)): if index_noun_mas[0] <= index_adj_mas[i]: flag = 1 #false/no break for i in range(len(index_verb_mas)): if index_noun_mas[0] >= index_verb_mas[i]: flag = 1 #false/no break elif (len(mas)!=len(s) or len(fem)!=len(s)) and (len(index_noun_fem)!=1 or len(index_noun_mas)!=1): flag = 1 if flag==0: print("YES") else: print("NO") ```
instruction
0
14,213
6
28,426
No
output
1
14,213
6
28,427
Provide tags and a correct Python 3 solution for this coding contest problem. In this problem you will write a simple code generator for a 2D programming language derived from [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck). The code in this language is a rectangular grid of characters '.' and 'X'. The code is converted to a Brainfuck program as follows: the characters are read in the usual order (top to bottom, left to right), and each 'X' character is converted a Brainfuck instruction to be executed. The instruction is defined by the left, top and right neighbors of the 'X' character using the following conversion table: <image> You are given a string. Output a program in the described language which prints this string. You can download the language interpreter used for judging here: <https://assets.codeforces.com/rounds/952/puzzling-interpreter.cpp> (use C++11 to compile the code). Note several implementation details: * The first step of the language interpretation is conversion to a Brainfuck program, which is then executed. * The code must be rectangular, with all lines of the same length. It can have at most 10,000 lines and 10,000 columns, and can have at most 500,000 'X' characters. * The code has toroidal topology, i.e. the 'X' on the first line will have top neighbor in the last line. * Brainfuck interpreter has 30000 memory cells which store integers from 0 to 255 with increment/decrement done modulo 256. * Console input (, command) is allowed in Brainfuck code but has no effect when executed. Input The input consists of a single string of characters with ASCII codes between 33 ('!') and 122 ('z'), inclusive. The length of the string is between 1 and 10 characters, inclusive. Output Output a program in the described language which, when executed, will print the given message. Example Input $$$ Output .......X....... ......XXX...... .....XXXXX..... ....XXXXXXX.... ...XXXXXXXXX... ..XXXXXXXXXXX.. .XXXXXXXXXXXXX. ............... X.............X X.............. X.............. X.............. Note The example corresponds to the following Brainfuck program: - >+< >+++< >+++++< >+++++++< >+++++++++< >+++++++++++< < > . . . The triangular block decrements the first memory cell and sets the value of the second memory cell to 36 - the ASCII code of '$' character. The next line after the triangular block moves the memory pointer to the second memory cell, and the next three lines print the '$' character three times.
instruction
0
14,740
6
29,480
Tags: constructive algorithms Correct Solution: ``` # A + # print(int(input()) % 2) # B # good = ['cool', 'great', 'not bad', '!'] # for i in range(10): # print(i, flush=True) # r = input().strip().lower() # for g in good: # if g in r: # print('normal', flush=True) # exit(0) # print('grumpy', flush=True) # C + # input() # a = [int(x) for x in input().split()] # while a: # for i in range(len(a)-1): # if abs(a[i] - a[i+1]) >= 2: # print('NO') # exit(0) # a.pop(a.index(max(a))) # print('YES') # D # print(20) # E + # n = int(input()) # a, b = 0, 0 # for _ in range(n): # _, s = input().split() # if s == 'soft': # a += 1 # else: # b += 1 # if a < b: # a, b = b, a # x = 0 # for i in range(1, 200): # x += 1 + (i*2 - 1) // 4 * 2 # if a <= x and b <= i**2 - x: # print(i) # break # G s = [ord(x) for x in input().strip()] pv = 0 at = 0 wid = 600 for x in s: dt = (x - pv) % 256 dt = -dt % 256 if dt == 0: dt = 256 print('X.'*dt + '.'*(wid - dt*2)) print('X' + '.'*(wid - 1)) print('.'*wid) pv = x ```
output
1
14,740
6
29,481
Provide tags and a correct Python 3 solution for this coding contest problem. In this problem you will write a simple code generator for a 2D programming language derived from [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck). The code in this language is a rectangular grid of characters '.' and 'X'. The code is converted to a Brainfuck program as follows: the characters are read in the usual order (top to bottom, left to right), and each 'X' character is converted a Brainfuck instruction to be executed. The instruction is defined by the left, top and right neighbors of the 'X' character using the following conversion table: <image> You are given a string. Output a program in the described language which prints this string. You can download the language interpreter used for judging here: <https://assets.codeforces.com/rounds/952/puzzling-interpreter.cpp> (use C++11 to compile the code). Note several implementation details: * The first step of the language interpretation is conversion to a Brainfuck program, which is then executed. * The code must be rectangular, with all lines of the same length. It can have at most 10,000 lines and 10,000 columns, and can have at most 500,000 'X' characters. * The code has toroidal topology, i.e. the 'X' on the first line will have top neighbor in the last line. * Brainfuck interpreter has 30000 memory cells which store integers from 0 to 255 with increment/decrement done modulo 256. * Console input (, command) is allowed in Brainfuck code but has no effect when executed. Input The input consists of a single string of characters with ASCII codes between 33 ('!') and 122 ('z'), inclusive. The length of the string is between 1 and 10 characters, inclusive. Output Output a program in the described language which, when executed, will print the given message. Example Input $$$ Output .......X....... ......XXX...... .....XXXXX..... ....XXXXXXX.... ...XXXXXXXXX... ..XXXXXXXXXXX.. .XXXXXXXXXXXXX. ............... X.............X X.............. X.............. X.............. Note The example corresponds to the following Brainfuck program: - >+< >+++< >+++++< >+++++++< >+++++++++< >+++++++++++< < > . . . The triangular block decrements the first memory cell and sets the value of the second memory cell to 36 - the ASCII code of '$' character. The next line after the triangular block moves the memory pointer to the second memory cell, and the next three lines print the '$' character three times.
instruction
0
14,741
6
29,482
Tags: constructive algorithms Correct Solution: ``` import sys s = input() #f = open('out.txt', 'w') f = sys.stdout n = 0 d = '\x00' for c in s: n = ord(c) - ord(d) #print(n, file=sys.stderr) if (n < 0): for i in range(-n): if i % 2 == 0: print('X....', file=f) else: print('.X...', file=f) elif n > 0: for i in range(n): print('..X..', file=f) print('.XXX.', file=f) print('XXXXX', file=f) print('.....', file=f) print('X....', file=f) print('.....', file=f) print('X...X', file=f) print('X....', file=f) print('.....', file=f) d = c f.close() ```
output
1
14,741
6
29,483
Provide tags and a correct Python 3 solution for this coding contest problem. In this problem you will write a simple code generator for a 2D programming language derived from [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck). The code in this language is a rectangular grid of characters '.' and 'X'. The code is converted to a Brainfuck program as follows: the characters are read in the usual order (top to bottom, left to right), and each 'X' character is converted a Brainfuck instruction to be executed. The instruction is defined by the left, top and right neighbors of the 'X' character using the following conversion table: <image> You are given a string. Output a program in the described language which prints this string. You can download the language interpreter used for judging here: <https://assets.codeforces.com/rounds/952/puzzling-interpreter.cpp> (use C++11 to compile the code). Note several implementation details: * The first step of the language interpretation is conversion to a Brainfuck program, which is then executed. * The code must be rectangular, with all lines of the same length. It can have at most 10,000 lines and 10,000 columns, and can have at most 500,000 'X' characters. * The code has toroidal topology, i.e. the 'X' on the first line will have top neighbor in the last line. * Brainfuck interpreter has 30000 memory cells which store integers from 0 to 255 with increment/decrement done modulo 256. * Console input (, command) is allowed in Brainfuck code but has no effect when executed. Input The input consists of a single string of characters with ASCII codes between 33 ('!') and 122 ('z'), inclusive. The length of the string is between 1 and 10 characters, inclusive. Output Output a program in the described language which, when executed, will print the given message. Example Input $$$ Output .......X....... ......XXX...... .....XXXXX..... ....XXXXXXX.... ...XXXXXXXXX... ..XXXXXXXXXXX.. .XXXXXXXXXXXXX. ............... X.............X X.............. X.............. X.............. Note The example corresponds to the following Brainfuck program: - >+< >+++< >+++++< >+++++++< >+++++++++< >+++++++++++< < > . . . The triangular block decrements the first memory cell and sets the value of the second memory cell to 36 - the ASCII code of '$' character. The next line after the triangular block moves the memory pointer to the second memory cell, and the next three lines print the '$' character three times.
instruction
0
14,742
6
29,484
Tags: constructive algorithms Correct Solution: ``` s = [ord(x) for x in input()] val = 0 add2 = '...\n.XX\nXXX' sub1 = '...\n.X.' for ch in s: delta = ch - val + 1 if delta > 0: if delta % 3 == 1: print(add2) print(sub1) delta -= 1 elif delta % 3 == 2: print(add2) delta -= 2 if delta >= 3: tmp = '...' + '\nXXX' * (delta // 3 + 1) print(tmp) elif delta < 0: tmp = '...' + ('\n' + sub1) * -delta print(tmp) print('...') print('.X.') print('.X.') print('...') val = ch ```
output
1
14,742
6
29,485
Provide tags and a correct Python 3 solution for this coding contest problem. In this problem you will write a simple code generator for a 2D programming language derived from [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck). The code in this language is a rectangular grid of characters '.' and 'X'. The code is converted to a Brainfuck program as follows: the characters are read in the usual order (top to bottom, left to right), and each 'X' character is converted a Brainfuck instruction to be executed. The instruction is defined by the left, top and right neighbors of the 'X' character using the following conversion table: <image> You are given a string. Output a program in the described language which prints this string. You can download the language interpreter used for judging here: <https://assets.codeforces.com/rounds/952/puzzling-interpreter.cpp> (use C++11 to compile the code). Note several implementation details: * The first step of the language interpretation is conversion to a Brainfuck program, which is then executed. * The code must be rectangular, with all lines of the same length. It can have at most 10,000 lines and 10,000 columns, and can have at most 500,000 'X' characters. * The code has toroidal topology, i.e. the 'X' on the first line will have top neighbor in the last line. * Brainfuck interpreter has 30000 memory cells which store integers from 0 to 255 with increment/decrement done modulo 256. * Console input (, command) is allowed in Brainfuck code but has no effect when executed. Input The input consists of a single string of characters with ASCII codes between 33 ('!') and 122 ('z'), inclusive. The length of the string is between 1 and 10 characters, inclusive. Output Output a program in the described language which, when executed, will print the given message. Example Input $$$ Output .......X....... ......XXX...... .....XXXXX..... ....XXXXXXX.... ...XXXXXXXXX... ..XXXXXXXXXXX.. .XXXXXXXXXXXXX. ............... X.............X X.............. X.............. X.............. Note The example corresponds to the following Brainfuck program: - >+< >+++< >+++++< >+++++++< >+++++++++< >+++++++++++< < > . . . The triangular block decrements the first memory cell and sets the value of the second memory cell to 36 - the ASCII code of '$' character. The next line after the triangular block moves the memory pointer to the second memory cell, and the next three lines print the '$' character three times.
instruction
0
14,743
6
29,486
Tags: constructive algorithms Correct Solution: ``` print(*['\n'.join([*['...\n.X.' for i in range(256 - x)], '.X.', *['...\n.X.' for i in range(x)]]) for x in map(ord, input())], sep='\n') ```
output
1
14,743
6
29,487
Provide tags and a correct Python 3 solution for this coding contest problem. In this problem you will write a simple code generator for a 2D programming language derived from [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck). The code in this language is a rectangular grid of characters '.' and 'X'. The code is converted to a Brainfuck program as follows: the characters are read in the usual order (top to bottom, left to right), and each 'X' character is converted a Brainfuck instruction to be executed. The instruction is defined by the left, top and right neighbors of the 'X' character using the following conversion table: <image> You are given a string. Output a program in the described language which prints this string. You can download the language interpreter used for judging here: <https://assets.codeforces.com/rounds/952/puzzling-interpreter.cpp> (use C++11 to compile the code). Note several implementation details: * The first step of the language interpretation is conversion to a Brainfuck program, which is then executed. * The code must be rectangular, with all lines of the same length. It can have at most 10,000 lines and 10,000 columns, and can have at most 500,000 'X' characters. * The code has toroidal topology, i.e. the 'X' on the first line will have top neighbor in the last line. * Brainfuck interpreter has 30000 memory cells which store integers from 0 to 255 with increment/decrement done modulo 256. * Console input (, command) is allowed in Brainfuck code but has no effect when executed. Input The input consists of a single string of characters with ASCII codes between 33 ('!') and 122 ('z'), inclusive. The length of the string is between 1 and 10 characters, inclusive. Output Output a program in the described language which, when executed, will print the given message. Example Input $$$ Output .......X....... ......XXX...... .....XXXXX..... ....XXXXXXX.... ...XXXXXXXXX... ..XXXXXXXXXXX.. .XXXXXXXXXXXXX. ............... X.............X X.............. X.............. X.............. Note The example corresponds to the following Brainfuck program: - >+< >+++< >+++++< >+++++++< >+++++++++< >+++++++++++< < > . . . The triangular block decrements the first memory cell and sets the value of the second memory cell to 36 - the ASCII code of '$' character. The next line after the triangular block moves the memory pointer to the second memory cell, and the next three lines print the '$' character three times.
instruction
0
14,744
6
29,488
Tags: constructive algorithms Correct Solution: ``` # python3 import math WIDTH = 170 def add(n): if n == 1: add(2) add(255) else: while n: k = min(n, WIDTH - 1) n -= k print('.' * WIDTH) print('X' * (k - 1) + '.' * (WIDTH - k) + 'X') print('X' * WIDTH) def print_mem2(): print('.' * WIDTH) print('X' + '.' * (WIDTH - 2) + 'X') print('X' + '.' * (WIDTH - 1)) # main mem2 = 0 for symbol in map(ord, input()): add((symbol - mem2) % 256) print_mem2() mem2 = symbol ```
output
1
14,744
6
29,489
Provide tags and a correct Python 3 solution for this coding contest problem. In this problem you will write a simple code generator for a 2D programming language derived from [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck). The code in this language is a rectangular grid of characters '.' and 'X'. The code is converted to a Brainfuck program as follows: the characters are read in the usual order (top to bottom, left to right), and each 'X' character is converted a Brainfuck instruction to be executed. The instruction is defined by the left, top and right neighbors of the 'X' character using the following conversion table: <image> You are given a string. Output a program in the described language which prints this string. You can download the language interpreter used for judging here: <https://assets.codeforces.com/rounds/952/puzzling-interpreter.cpp> (use C++11 to compile the code). Note several implementation details: * The first step of the language interpretation is conversion to a Brainfuck program, which is then executed. * The code must be rectangular, with all lines of the same length. It can have at most 10,000 lines and 10,000 columns, and can have at most 500,000 'X' characters. * The code has toroidal topology, i.e. the 'X' on the first line will have top neighbor in the last line. * Brainfuck interpreter has 30000 memory cells which store integers from 0 to 255 with increment/decrement done modulo 256. * Console input (, command) is allowed in Brainfuck code but has no effect when executed. Input The input consists of a single string of characters with ASCII codes between 33 ('!') and 122 ('z'), inclusive. The length of the string is between 1 and 10 characters, inclusive. Output Output a program in the described language which, when executed, will print the given message. Example Input $$$ Output .......X....... ......XXX...... .....XXXXX..... ....XXXXXXX.... ...XXXXXXXXX... ..XXXXXXXXXXX.. .XXXXXXXXXXXXX. ............... X.............X X.............. X.............. X.............. Note The example corresponds to the following Brainfuck program: - >+< >+++< >+++++< >+++++++< >+++++++++< >+++++++++++< < > . . . The triangular block decrements the first memory cell and sets the value of the second memory cell to 36 - the ASCII code of '$' character. The next line after the triangular block moves the memory pointer to the second memory cell, and the next three lines print the '$' character three times.
instruction
0
14,745
6
29,490
Tags: constructive algorithms Correct Solution: ``` s = input() for c in s: for i in range(256 - ord(c)): print("...\n.X.") print(".X.") for i in range(ord(c)): print("...\n.X.") ```
output
1
14,745
6
29,491