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 a correct Python 3 solution for this coding contest problem.
We, the researchers who discovered and investigated the ancient nation Iwashiro, finally discovered the temple in the center of Iwashiro. A lithograph dedicated to the god of Iwashiro was stored in the temple. On the lithograph, two strings were written, one for each sentence and one for the spell.
In Iwashiro, how many times a spell appears in a sentence has an important meaning. However, it is considered that all the characters contained in the spell appear in order, and some of them appear in the sentence in a discrete manner once. For example, if the sentence is "abab" and the spell is "ab", then "ab" appears three times in "abab", including non-continuous ones (three ways: abab, abab, and abab).
Create a program that prints how many times a spell appears in a sentence when it is given a sentence and a spell.
Input
The input is given in the following format.
t
b b
The first line is given the string t that represents the text written on the lithograph. The second line is given the string b that represents the spell written on the lithograph. Both strings are composed of only lowercase letters and have a length of 1 or more and 1000 or less.
Output
Prints how many times a spell appears in a sentence on one line. However, the value to be output can be very large, so instead output the remainder divided by 1,000,000,007.
Examples
Input
abab
ab
Output
3
Input
aaaabaaaabaaaabaaaab
aaaaa
Output
4368
Input
data
structure
Output
0 | instruction | 0 | 55,546 | 6 | 111,092 |
"Correct Solution:
```
t = input()
b = input()
table = [[0 for i in range(len(t))] for j in range(len(b))]
if len(t) > len(b):
if t[0] == b[0]:
table[0][0] = 1
for i in range(1, len(t)):
if t[i] == b[0]:
table[0][i] = table[0][i-1] + 1
else:
table[0][i] = table[0][i-1]
for i in range(1, len(b)):
if b[i] == t[i]:
table[i][i] = table[i-1][i-1]
for j in range(i+1, len(t)):
if b[i] == t[j]:
table[i][j] = table[i-1][j-1] + table[i][j-1]
else:
table[i][j] = table[i][j-1]
print(table[len(b)-1][len(t)-1] % 1000000007)
elif len(t) == len(b):
if t == b:
print(1)
else:
print(0)
else:
print(0)
``` | output | 1 | 55,546 | 6 | 111,093 |
Provide a correct Python 3 solution for this coding contest problem.
We, the researchers who discovered and investigated the ancient nation Iwashiro, finally discovered the temple in the center of Iwashiro. A lithograph dedicated to the god of Iwashiro was stored in the temple. On the lithograph, two strings were written, one for each sentence and one for the spell.
In Iwashiro, how many times a spell appears in a sentence has an important meaning. However, it is considered that all the characters contained in the spell appear in order, and some of them appear in the sentence in a discrete manner once. For example, if the sentence is "abab" and the spell is "ab", then "ab" appears three times in "abab", including non-continuous ones (three ways: abab, abab, and abab).
Create a program that prints how many times a spell appears in a sentence when it is given a sentence and a spell.
Input
The input is given in the following format.
t
b b
The first line is given the string t that represents the text written on the lithograph. The second line is given the string b that represents the spell written on the lithograph. Both strings are composed of only lowercase letters and have a length of 1 or more and 1000 or less.
Output
Prints how many times a spell appears in a sentence on one line. However, the value to be output can be very large, so instead output the remainder divided by 1,000,000,007.
Examples
Input
abab
ab
Output
3
Input
aaaabaaaabaaaabaaaab
aaaaa
Output
4368
Input
data
structure
Output
0 | instruction | 0 | 55,547 | 6 | 111,094 |
"Correct Solution:
```
def main():
MOD = 1000000007
s,t = input(),input()
n,m = len(s),len(t)
dp = [[0 for i in range(m+1)] for j in range(n+1)]
dp[0][0] = 1
for i in range(n):
for j in range(m-1,-1,-1):
dp[i+1][j] += dp[i][j]
dp[i+1][j] %= MOD
if s[i] == t[j]:
dp[i+1][j+1] += dp[i][j]
dp[i+1][j+1] %= MOD
sum = 0
for i in range(n+1):
sum += dp[i][m]
print(sum%MOD)
if __name__ == "__main__":
main()
``` | output | 1 | 55,547 | 6 | 111,095 |
Provide a correct Python 3 solution for this coding contest problem.
We, the researchers who discovered and investigated the ancient nation Iwashiro, finally discovered the temple in the center of Iwashiro. A lithograph dedicated to the god of Iwashiro was stored in the temple. On the lithograph, two strings were written, one for each sentence and one for the spell.
In Iwashiro, how many times a spell appears in a sentence has an important meaning. However, it is considered that all the characters contained in the spell appear in order, and some of them appear in the sentence in a discrete manner once. For example, if the sentence is "abab" and the spell is "ab", then "ab" appears three times in "abab", including non-continuous ones (three ways: abab, abab, and abab).
Create a program that prints how many times a spell appears in a sentence when it is given a sentence and a spell.
Input
The input is given in the following format.
t
b b
The first line is given the string t that represents the text written on the lithograph. The second line is given the string b that represents the spell written on the lithograph. Both strings are composed of only lowercase letters and have a length of 1 or more and 1000 or less.
Output
Prints how many times a spell appears in a sentence on one line. However, the value to be output can be very large, so instead output the remainder divided by 1,000,000,007.
Examples
Input
abab
ab
Output
3
Input
aaaabaaaabaaaabaaaab
aaaaa
Output
4368
Input
data
structure
Output
0 | instruction | 0 | 55,548 | 6 | 111,096 |
"Correct Solution:
```
t = input()
b = input()
MOD = 10**9 + 7
cnts = [0]*(len(b)+1)
cnts[0] = 1
for c in t:
for i in range(len(b)-1, -1, -1):
if c == b[i]:
cnts[i+1] = (cnts[i+1] + cnts[i]) % MOD
print(cnts[-1])
``` | output | 1 | 55,548 | 6 | 111,097 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We, the researchers who discovered and investigated the ancient nation Iwashiro, finally discovered the temple in the center of Iwashiro. A lithograph dedicated to the god of Iwashiro was stored in the temple. On the lithograph, two strings were written, one for each sentence and one for the spell.
In Iwashiro, how many times a spell appears in a sentence has an important meaning. However, it is considered that all the characters contained in the spell appear in order, and some of them appear in the sentence in a discrete manner once. For example, if the sentence is "abab" and the spell is "ab", then "ab" appears three times in "abab", including non-continuous ones (three ways: abab, abab, and abab).
Create a program that prints how many times a spell appears in a sentence when it is given a sentence and a spell.
Input
The input is given in the following format.
t
b b
The first line is given the string t that represents the text written on the lithograph. The second line is given the string b that represents the spell written on the lithograph. Both strings are composed of only lowercase letters and have a length of 1 or more and 1000 or less.
Output
Prints how many times a spell appears in a sentence on one line. However, the value to be output can be very large, so instead output the remainder divided by 1,000,000,007.
Examples
Input
abab
ab
Output
3
Input
aaaabaaaabaaaabaaaab
aaaaa
Output
4368
Input
data
structure
Output
0
Submitted Solution:
```
def main():
MOD = 1000000007
s,t = input(),input()
n,m = len(s),len(t)
dp = [[0 for i in range(m+1)] for j in range(n+1)]
dp[0][0] = 1
for i in range(n):
for j in range(m-1,-1,-1):
dp[i+1][j] += dp[i][j]
dp[i+1][j] %= MOD
if s[i] == t[j]:
dp[i+1][j+1] += dp[i][j]
dp[i+1][j+1] %= MOD
sum = 0
for i in range(n+1):
sum += dp[i][m]
print(sum)
if __name__ == "__main__":
main()
``` | instruction | 0 | 55,549 | 6 | 111,098 |
No | output | 1 | 55,549 | 6 | 111,099 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kaavi, the mysterious fortune teller, deeply believes that one's fate is inevitable and unavoidable. Of course, she makes her living by predicting others' future. While doing divination, Kaavi believes that magic spells can provide great power for her to see the future.
<image>
Kaavi has a string T of length m and all the strings with the prefix T are magic spells. Kaavi also has a string S of length n and an empty string A.
During the divination, Kaavi needs to perform a sequence of operations. There are two different operations:
* Delete the first character of S and add it at the front of A.
* Delete the first character of S and add it at the back of A.
Kaavi can perform no more than n operations. To finish the divination, she wants to know the number of different operation sequences to make A a magic spell (i.e. with the prefix T). As her assistant, can you help her? The answer might be huge, so Kaavi only needs to know the answer modulo 998 244 353.
Two operation sequences are considered different if they are different in length or there exists an i that their i-th operation is different.
A substring is a contiguous sequence of characters within a string. A prefix of a string S is a substring of S that occurs at the beginning of S.
Input
The first line contains a string S of length n (1 β€ n β€ 3000).
The second line contains a string T of length m (1 β€ m β€ n).
Both strings contain only lowercase Latin letters.
Output
The output contains only one integer β the answer modulo 998 244 353.
Examples
Input
abab
ba
Output
12
Input
defineintlonglong
signedmain
Output
0
Input
rotator
rotator
Output
4
Input
cacdcdbbbb
bdcaccdbbb
Output
24
Note
The first test:
<image>
The red ones are the magic spells. In the first operation, Kaavi can either add the first character "a" at the front or the back of A, although the results are the same, they are considered as different operations. So the answer is 6Γ2=12.
Submitted Solution:
```
from sys import stdin, stdout
def kaavi_and_magic_spell(S, T):
MOD = 998244353
n = len(S)
m = len(T)
dp = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
if comp(S, T, 0, i):
dp[i][i] = 1
for l in range(2, n+1):
for i in range(n - l + 1):
if comp(S, T, l-1, i):
# front
dp[i][i+l-1] += dp[i+1][i+l-1]
dp[i][i+l-1] %= MOD
if comp(S, T, l-1, i+l-1):
# back
dp[i][i+l-1] += dp[i][i+l-2]
dp[i][i+l-1] %= MOD
r = 0
for j in range(m-1, n):
r += dp[0][j]
r %= MOD
r *= 2
r %= MOD
return r
def comp(S, T, i, j):
if j >= len(T):
return True
return S[i] == T[j]
S = stdin.readline().strip()
T = stdin.readline().strip()
r = kaavi_and_magic_spell(S, T)
stdout.write(str(r) + '\n')
``` | instruction | 0 | 55,758 | 6 | 111,516 |
Yes | output | 1 | 55,758 | 6 | 111,517 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Friday is Polycarpus' favourite day of the week. Not because it is followed by the weekend, but because the lessons on Friday are 2 IT lessons, 2 math lessons and 2 literature lessons. Of course, Polycarpus has prepared to all of them, unlike his buddy Innocentius. Innocentius spent all evening playing his favourite game Fur2 and didn't have enough time to do the literature task. As Innocentius didn't want to get an F, he decided to do the task and read the book called "Storm and Calm" during the IT and Math lessons (he never used to have problems with these subjects). When the IT teacher Mr. Watkins saw this, he decided to give Innocentius another task so that the boy concentrated more on the lesson and less β on the staff that has nothing to do with IT.
Mr. Watkins said that a palindrome is a string that can be read the same way in either direction, from the left to the right and from the right to the left. A concatenation of strings a, b is a string ab that results from consecutive adding of string b to string a. Of course, Innocentius knew it all but the task was much harder than he could have imagined. Mr. Watkins asked change in the "Storm and Calm" the minimum number of characters so that the text of the book would also be a concatenation of no more than k palindromes. Innocentius can't complete the task and therefore asks you to help him.
Input
The first input line contains a non-empty string s which is the text of "Storm and Calm" (without spaces). The length of the string s does not exceed 500 characters. String s consists of uppercase and lowercase Latin letters. The second line contains a single number k (1 β€ k β€ |s|, where |s| represents the length of the string s).
Output
Print on the first line the minimum number of changes that Innocentius will have to make. Print on the second line the string consisting of no more than k palindromes. Each palindrome should be non-empty and consist of uppercase and lowercase Latin letters. Use the character "+" (ASCII-code 43) to separate consecutive palindromes. If there exist several solutions, print any of them.
The letters' case does matter, that is an uppercase letter is not considered equivalent to the corresponding lowercase letter.
Examples
Input
abacaba
1
Output
0
abacaba
Input
abdcaba
2
Output
1
abdcdba
Input
abdcaba
5
Output
0
a+b+d+c+aba
Input
abacababababbcbabcd
3
Output
1
abacaba+babab+bcbabcb
Submitted Solution:
```
from sys import stdin, stdout
s = stdin.readline().strip().lower()
count = [0 for i in range(len(s))]
cnt = 0
d = {}
for i in range(len(s)):
if s[i] in 'eaoiu':
count[i] += -1 + cnt
else:
count[i] += 2 + cnt
cnt = count[i]
for i in range(len(count) - 1, -1, -1):
if count[i] not in d:
d[count[i]] = i
ans = 0
for i in range(len(count)):
for v in d:
if v > count[i]:
ans = max(ans, d[v] - i + 1)
if len(s) == 1 and s[0] not in 'aeoiu':
ans = 1
if not ans:
stdout.write('No solution')
else:
cnt = 0
m = ans
cntv, cntc = 0, 0
for i in range(m):
if s[i] in 'aeiou':
cntv += 1
else:
cntc += 1
if cntv <= cntc * 2:
cnt = 1
for i in range(m, len(s)):
if s[i - m] in 'aeiou':
cntv -= 1
else:
cntc -= 1
if s[i] in 'aeiou':
cntv += 1
else:
cntc += 1
if cntv <= cntc * 2:
cnt += 1
stdout.write(str(ans) + ' ' + str(cnt))
``` | instruction | 0 | 55,777 | 6 | 111,554 |
No | output | 1 | 55,777 | 6 | 111,555 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.
Input
The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.
The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.
It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.
Output
If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them.
Examples
Input
AC|T
L
Output
AC|TL
Input
|ABC
XYZ
Output
XYZ|ABC
Input
W|T
F
Output
Impossible
Input
ABC|
D
Output
Impossible | instruction | 0 | 55,948 | 6 | 111,896 |
Tags: greedy, implementation
Correct Solution:
```
a,b=input().split('|')
u=input()
x=len(u)
A=len(a)
B=len(b)
t=A+B+x
if abs(B-A)<=x and t%2==0:
if t%2==0:
t=t/2
A=int(abs(t-A))
a+=u[0:A]
b+=u[A:]
else:
t=t//2
A=int(abs(t-A))
a+=u[0:A]
b+=u[A:x-1]
print(a,end='')
print("|",end='')
print(b)
else:
print("Impossible")
``` | output | 1 | 55,948 | 6 | 111,897 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.
Input
The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.
The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.
It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.
Output
If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them.
Examples
Input
AC|T
L
Output
AC|TL
Input
|ABC
XYZ
Output
XYZ|ABC
Input
W|T
F
Output
Impossible
Input
ABC|
D
Output
Impossible | instruction | 0 | 55,949 | 6 | 111,898 |
Tags: greedy, implementation
Correct Solution:
```
"""
βββ βββββββ βββ βββββββ βββββββ βββ ββββββ
βββββββββββββββ βββββββββββββββββββββββββββββ
ββββββ ββββββ ββββββββββββββββββββββββββββ
ββββββ ββββββ βββββββ βββββββββ βββ βββββββ
βββββββββββββββ βββββββββββββββββ βββ βββββββ
βββ βββββββ βββ ββββββββ βββββββ βββ ββββββ
βββββββ ββββββ βββββββββββ βββ βββββββ βββββββ
ββββββββββββββ βββββββββββ ββββββββββββββββββββ
βββ βββββββββ βββββββββββββββββββ ββββββ βββ
βββ βββββββββ βββββββββββββββββββ ββββββ βββ
ββββββββββββββββββββββββββββββ ββββββββββββββββββββ
βββββββ ββββββββββββββββββββββ βββ βββββββ βββββββ
"""
s = input()
l = input()
s = s.split("|")
if len(s[0]) == len(s[1]) and len(l) % 2 == 1 or max(len(s[0]), len(s[1])) - min(len(s[ 0]), len(s[1])) > len(l) or max(len(s[0]), len(s[1])) - min(len(s[0]), len(s[1])) < len(l) and (len(l) - max(len(s[0]), len(s[1])) - min(len(s[0]), len(s[1]))) % 2 == 1:
print("Impossible")
elif len(s[0]) == len(s[1]) and len(l) % 2 == 0:
s[0] = l[ : len(l) // 2] + s[0]
s[1] += l[len(l) // 2 : ]
print(s[0] + "|" + s[1])
else:
if len(s[0]) < len(s[1]):
if len(s[1]) - len(s[0]) != len(l):
b = len(s[0])
s[0] += l[ : len(s[1]) - len(s[0])]
l = l[len(s[1]) - b: ]
else:
s[0] = l[ : len(s[1]) - len(s[0])] + s[0]
l = []
if len(l) != 0:
s[0] += l[ : len(l) // 2]
s[1] += l[len(l) // 2 : ]
print(s[0] + "|" + s[1])
else:
if len(s[0]) - len(s[1]) != len(l):
b = len(s[1])
s[1] += l[ : len(s[0]) - len(s[1])]
l = l[len(s[0]) - b: ]
else:
s[1] = l[ : len(s[0]) - len(s[1])] + s[1]
l = []
if len(l) != 0:
s[1] += l[ : len(l) // 2]
s[0] += l[len(l) // 2 : ]
print(s[0] + "|" + s[1])
``` | output | 1 | 55,949 | 6 | 111,899 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.
Input
The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.
The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.
It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.
Output
If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them.
Examples
Input
AC|T
L
Output
AC|TL
Input
|ABC
XYZ
Output
XYZ|ABC
Input
W|T
F
Output
Impossible
Input
ABC|
D
Output
Impossible | instruction | 0 | 55,950 | 6 | 111,900 |
Tags: greedy, implementation
Correct Solution:
```
__author__ = 'Adela'
def main():
# code
w = [k for k in input().split('|')]
l = len(w[0])
r = len(w[1])
rem = input()
total = (l+r+len(rem))
if total % 2 == 0:
if l <= total/2 and r <= total/2:
total = int(total/2)
print(w[0], rem[:total-l], '|', w[1], rem[total-l:], sep='')
return
print("Impossible")
if __name__ == "__main__":
main()
``` | output | 1 | 55,950 | 6 | 111,901 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.
Input
The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.
The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.
It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.
Output
If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them.
Examples
Input
AC|T
L
Output
AC|TL
Input
|ABC
XYZ
Output
XYZ|ABC
Input
W|T
F
Output
Impossible
Input
ABC|
D
Output
Impossible | instruction | 0 | 55,951 | 6 | 111,902 |
Tags: greedy, implementation
Correct Solution:
```
def checkG(g):
return g%2==0
x=input()
g=input()
n=len(g)
l=x.find('|')
r=len(x)-x.find('|')-1
if r==l:
if checkG(n):
print(x[:l]+g[:int(n/2)]+'|'+x[l+1:]+g[int(n/2):])
else:
print("Impossible")
else:
d=abs(r-l)
if n<d:
print("Impossible")
exit()
if checkG(n-abs(l-r)):
if l<r:
print(x[:l]+g[:d+int((n-d)/2)]+'|'+x[l+1:]+g[d+int((n-d)/2):])
else:
print(x[:l]+g[:int((n-d)/2)]+'|'+x[l+1:]+g[int((n-d)/2):])
else:
print("Impossible")
``` | output | 1 | 55,951 | 6 | 111,903 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.
Input
The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.
The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.
It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.
Output
If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them.
Examples
Input
AC|T
L
Output
AC|TL
Input
|ABC
XYZ
Output
XYZ|ABC
Input
W|T
F
Output
Impossible
Input
ABC|
D
Output
Impossible | instruction | 0 | 55,952 | 6 | 111,904 |
Tags: greedy, implementation
Correct Solution:
```
(a, b) = input().split('|')
c = input()
i = 0
while len(c) > 0:
if len(a) < len(b):
a += c[0]
else:
b += c[0]
c = c[1::]
if len(a) == len(b):
print(a + '|' + b)
else:
print("Impossible")
``` | output | 1 | 55,952 | 6 | 111,905 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.
Input
The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.
The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.
It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.
Output
If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them.
Examples
Input
AC|T
L
Output
AC|TL
Input
|ABC
XYZ
Output
XYZ|ABC
Input
W|T
F
Output
Impossible
Input
ABC|
D
Output
Impossible | instruction | 0 | 55,953 | 6 | 111,906 |
Tags: greedy, implementation
Correct Solution:
```
s = input()
t = input()
ass = s.split("|")
al= len(s)+len(t)-1
if al %2 or len(ass[0])>al//2 or len(ass[1])>al//2:
print("Impossible")
exit(0)
lt = list(t)
ml = al//2- len(ass[0])
ass[0]+=t[:ml]
ass[1]+=t[ml:]
print(ass[0]+"|"+ass[1])
``` | output | 1 | 55,953 | 6 | 111,907 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.
Input
The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.
The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.
It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.
Output
If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them.
Examples
Input
AC|T
L
Output
AC|TL
Input
|ABC
XYZ
Output
XYZ|ABC
Input
W|T
F
Output
Impossible
Input
ABC|
D
Output
Impossible | instruction | 0 | 55,954 | 6 | 111,908 |
Tags: greedy, implementation
Correct Solution:
```
def main():
current = input().strip().split("|")
unused = input().strip()
lengths = [ len(x) for x in current ]
ll,lr,lu=min(lengths[0],lengths[1]),max(lengths[0],lengths[1]),len(unused)
r = None
if (ll+lr+lu)%2==1 or ll+lu<lr:
r = "Impossible"
else:
lmid = (ll+lr+lu)>>1
lb,rb = list(),list()
i = 0
while len(lb)+len(current[0])<lmid:
lb.append(unused[i])
i+=1
while len(rb)+len(current[1])<lmid:
rb.append(unused[i])
i+=1
r = current[0]+''.join(lb)+"|"+current[1]+''.join(rb)
print(r)
main()
``` | output | 1 | 55,954 | 6 | 111,909 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.
Input
The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.
The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.
It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.
Output
If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them.
Examples
Input
AC|T
L
Output
AC|TL
Input
|ABC
XYZ
Output
XYZ|ABC
Input
W|T
F
Output
Impossible
Input
ABC|
D
Output
Impossible | instruction | 0 | 55,955 | 6 | 111,910 |
Tags: greedy, implementation
Correct Solution:
```
l,r = input().split('|')
q = input()
for i in q:
if len(l)>len(r):
r+=i
elif len(l)<len(r):
l+=i
else:
l+=i
if len(l)==len(r):
print(l+"|"+r)
else:
print('Impossible')
``` | output | 1 | 55,955 | 6 | 111,911 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
Input
The first line contains two integers, n and m (1 β€ n β€ 3000, 1 β€ m β€ 3000) β the number of words in the professor's lecture and the number of words in each of these languages.
The following m lines contain the words. The i-th line contains two strings ai, bi meaning that the word ai belongs to the first language, the word bi belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains n space-separated strings c1, c2, ..., cn β the text of the lecture. It is guaranteed that each of the strings ci belongs to the set of strings {a1, a2, ... am}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output
Output exactly n words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
Examples
Input
4 3
codeforces codesecrof
contest round
letter message
codeforces contest letter contest
Output
codeforces round letter round
Input
5 3
joll wuqrd
euzf un
hbnyiyc rsoqqveh
hbnyiyc joll joll euzf joll
Output
hbnyiyc joll joll un joll | instruction | 0 | 56,003 | 6 | 112,006 |
Tags: implementation, strings
Correct Solution:
```
n, m = map(int, input().split())
a= {}
for i in range(m):
n, m = input().split()
a[n] = m
st = input()
#print(st)
st1 = ''
for i in st.split():
#print(i)
if(len(a[i]) < len(i)):
st1 += a[i] + " "
else:
st1 += i + " "
print(st1)
``` | output | 1 | 56,003 | 6 | 112,007 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
Input
The first line contains two integers, n and m (1 β€ n β€ 3000, 1 β€ m β€ 3000) β the number of words in the professor's lecture and the number of words in each of these languages.
The following m lines contain the words. The i-th line contains two strings ai, bi meaning that the word ai belongs to the first language, the word bi belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains n space-separated strings c1, c2, ..., cn β the text of the lecture. It is guaranteed that each of the strings ci belongs to the set of strings {a1, a2, ... am}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output
Output exactly n words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
Examples
Input
4 3
codeforces codesecrof
contest round
letter message
codeforces contest letter contest
Output
codeforces round letter round
Input
5 3
joll wuqrd
euzf un
hbnyiyc rsoqqveh
hbnyiyc joll joll euzf joll
Output
hbnyiyc joll joll un joll | instruction | 0 | 56,004 | 6 | 112,008 |
Tags: implementation, strings
Correct Solution:
```
#!/usr/bin/env python
# coding: utf-8
# In[2]:
n,m=map(int,input().split())
d=dict()
while m:
a,b=input().split()
la=len(a)
lb=len(b)
if la<=lb:
d[a]=a
else:
d[a]=b
m-=1
text=input().split()
ans=[]
for i in text:
ans.append(d[i])
print(' '.join(ans))
# In[ ]:
``` | output | 1 | 56,004 | 6 | 112,009 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
Input
The first line contains two integers, n and m (1 β€ n β€ 3000, 1 β€ m β€ 3000) β the number of words in the professor's lecture and the number of words in each of these languages.
The following m lines contain the words. The i-th line contains two strings ai, bi meaning that the word ai belongs to the first language, the word bi belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains n space-separated strings c1, c2, ..., cn β the text of the lecture. It is guaranteed that each of the strings ci belongs to the set of strings {a1, a2, ... am}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output
Output exactly n words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
Examples
Input
4 3
codeforces codesecrof
contest round
letter message
codeforces contest letter contest
Output
codeforces round letter round
Input
5 3
joll wuqrd
euzf un
hbnyiyc rsoqqveh
hbnyiyc joll joll euzf joll
Output
hbnyiyc joll joll un joll | instruction | 0 | 56,005 | 6 | 112,010 |
Tags: implementation, strings
Correct Solution:
```
n,m = map(int,input().split())
dc = {}
for i in range(m):
a = input().split()
dc[a[0]] = a[1]
mat = input().split()
for word in mat:
if (len(word)>len(dc[word])):
print(dc[word],end = " ")
else:
print(word , end = " ")
``` | output | 1 | 56,005 | 6 | 112,011 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
Input
The first line contains two integers, n and m (1 β€ n β€ 3000, 1 β€ m β€ 3000) β the number of words in the professor's lecture and the number of words in each of these languages.
The following m lines contain the words. The i-th line contains two strings ai, bi meaning that the word ai belongs to the first language, the word bi belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains n space-separated strings c1, c2, ..., cn β the text of the lecture. It is guaranteed that each of the strings ci belongs to the set of strings {a1, a2, ... am}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output
Output exactly n words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
Examples
Input
4 3
codeforces codesecrof
contest round
letter message
codeforces contest letter contest
Output
codeforces round letter round
Input
5 3
joll wuqrd
euzf un
hbnyiyc rsoqqveh
hbnyiyc joll joll euzf joll
Output
hbnyiyc joll joll un joll | instruction | 0 | 56,006 | 6 | 112,012 |
Tags: implementation, strings
Correct Solution:
```
n, m = map(int, input().split())
words = dict()
for i in range(m):
w1, w2 = map(str, input().split())
w = w1
if len(w2) < len(w1):
w = w2
words[w1] = w
words[w2] = w
data = input().split()
for i in range(n):
print(words[data[i]], end = " ")
``` | output | 1 | 56,006 | 6 | 112,013 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
Input
The first line contains two integers, n and m (1 β€ n β€ 3000, 1 β€ m β€ 3000) β the number of words in the professor's lecture and the number of words in each of these languages.
The following m lines contain the words. The i-th line contains two strings ai, bi meaning that the word ai belongs to the first language, the word bi belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains n space-separated strings c1, c2, ..., cn β the text of the lecture. It is guaranteed that each of the strings ci belongs to the set of strings {a1, a2, ... am}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output
Output exactly n words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
Examples
Input
4 3
codeforces codesecrof
contest round
letter message
codeforces contest letter contest
Output
codeforces round letter round
Input
5 3
joll wuqrd
euzf un
hbnyiyc rsoqqveh
hbnyiyc joll joll euzf joll
Output
hbnyiyc joll joll un joll | instruction | 0 | 56,007 | 6 | 112,014 |
Tags: implementation, strings
Correct Solution:
```
## 499B
(n, m) = (int(_) for _ in input().split(' '))
dictionary = {}
for _ in range(m):
(a, b) = input().split(' ')
dictionary[a] = b
output = []
for word in input().split():
if len(word) <= len(dictionary[word]):
output.append(word)
else:
output.append(dictionary[word])
print(" ".join(output))
``` | output | 1 | 56,007 | 6 | 112,015 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
Input
The first line contains two integers, n and m (1 β€ n β€ 3000, 1 β€ m β€ 3000) β the number of words in the professor's lecture and the number of words in each of these languages.
The following m lines contain the words. The i-th line contains two strings ai, bi meaning that the word ai belongs to the first language, the word bi belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains n space-separated strings c1, c2, ..., cn β the text of the lecture. It is guaranteed that each of the strings ci belongs to the set of strings {a1, a2, ... am}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output
Output exactly n words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
Examples
Input
4 3
codeforces codesecrof
contest round
letter message
codeforces contest letter contest
Output
codeforces round letter round
Input
5 3
joll wuqrd
euzf un
hbnyiyc rsoqqveh
hbnyiyc joll joll euzf joll
Output
hbnyiyc joll joll un joll | instruction | 0 | 56,008 | 6 | 112,016 |
Tags: implementation, strings
Correct Solution:
```
g=input()
n,m=[int(x) for x in g.split()]
dic={}
lis=[]
for i in range(m):
r=input()
r1,r2=r.split()
if len(r1)<=len(r2):
dic[r1]=r1
dic[r2]=r1
else:
dic[r1]=r2
dic[r2]=r2
t=input()
for x in t.split():
lis.append(x)
result=""
for x in lis:
result=result+dic[x]+" "
print(result)
``` | output | 1 | 56,008 | 6 | 112,017 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
Input
The first line contains two integers, n and m (1 β€ n β€ 3000, 1 β€ m β€ 3000) β the number of words in the professor's lecture and the number of words in each of these languages.
The following m lines contain the words. The i-th line contains two strings ai, bi meaning that the word ai belongs to the first language, the word bi belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains n space-separated strings c1, c2, ..., cn β the text of the lecture. It is guaranteed that each of the strings ci belongs to the set of strings {a1, a2, ... am}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output
Output exactly n words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
Examples
Input
4 3
codeforces codesecrof
contest round
letter message
codeforces contest letter contest
Output
codeforces round letter round
Input
5 3
joll wuqrd
euzf un
hbnyiyc rsoqqveh
hbnyiyc joll joll euzf joll
Output
hbnyiyc joll joll un joll | instruction | 0 | 56,009 | 6 | 112,018 |
Tags: implementation, strings
Correct Solution:
```
def f(l,a):
for i in range(0,len(l),2):
if l[i]==a:
if len(a)>len(l[i+1]):
# print(0)
return l[i+1]
else:
# print(1)
return a
n,m=map(int,input().split())
l=[]
for i in range(m):
l1=list(input().split())
l.append(l1[0])
l.append(l1[1])
# print(min(len(l1)))
# t=[]
s=list(input().split())
for i in range(n):
print(f(l,s[i]),end=" ")
``` | output | 1 | 56,009 | 6 | 112,019 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
Input
The first line contains two integers, n and m (1 β€ n β€ 3000, 1 β€ m β€ 3000) β the number of words in the professor's lecture and the number of words in each of these languages.
The following m lines contain the words. The i-th line contains two strings ai, bi meaning that the word ai belongs to the first language, the word bi belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.
The next line contains n space-separated strings c1, c2, ..., cn β the text of the lecture. It is guaranteed that each of the strings ci belongs to the set of strings {a1, a2, ... am}.
All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output
Output exactly n words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
Examples
Input
4 3
codeforces codesecrof
contest round
letter message
codeforces contest letter contest
Output
codeforces round letter round
Input
5 3
joll wuqrd
euzf un
hbnyiyc rsoqqveh
hbnyiyc joll joll euzf joll
Output
hbnyiyc joll joll un joll | instruction | 0 | 56,010 | 6 | 112,020 |
Tags: implementation, strings
Correct Solution:
```
from collections import defaultdict
d=defaultdict(list)
n,m=map(int,input().split())
for i in range(m):
x,y=map(str,input().split())
if len(x)>len(y):
d[x].append(y)
else:
d[x].append(x)
s=list(map(str,input().split()))
for i in range(n):
print(*d[s[i]],end=" ")
``` | output | 1 | 56,010 | 6 | 112,021 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A", "T", "G", "C". A DNA strand is a sequence of nucleotides. Scientists decided to track evolution of a rare species, which DNA strand was string s initially.
Evolution of the species is described as a sequence of changes in the DNA. Every change is a change of some nucleotide, for example, the following change can happen in DNA strand "AAGC": the second nucleotide can change to "T" so that the resulting DNA strand is "ATGC".
Scientists know that some segments of the DNA strand can be affected by some unknown infections. They can represent an infection as a sequence of nucleotides. Scientists are interested if there are any changes caused by some infections. Thus they sometimes want to know the value of impact of some infection to some segment of the DNA. This value is computed as follows:
* Let the infection be represented as a string e, and let scientists be interested in DNA strand segment starting from position l to position r, inclusive.
* Prefix of the string eee... (i.e. the string that consists of infinitely many repeats of string e) is written under the string s from position l to position r, inclusive.
* The value of impact is the number of positions where letter of string s coincided with the letter written under it.
Being a developer, Innokenty is interested in bioinformatics also, so the scientists asked him for help. Innokenty is busy preparing VK Cup, so he decided to delegate the problem to the competitors. Help the scientists!
Input
The first line contains the string s (1 β€ |s| β€ 105) that describes the initial DNA strand. It consists only of capital English letters "A", "T", "G" and "C".
The next line contains single integer q (1 β€ q β€ 105) β the number of events.
After that, q lines follow, each describes one event. Each of the lines has one of two formats:
* 1 x c, where x is an integer (1 β€ x β€ |s|), and c is a letter "A", "T", "G" or "C", which means that there is a change in the DNA: the nucleotide at position x is now c.
* 2 l r e, where l, r are integers (1 β€ l β€ r β€ |s|), and e is a string of letters "A", "T", "G" and "C" (1 β€ |e| β€ 10), which means that scientists are interested in the value of impact of infection e to the segment of DNA strand from position l to position r, inclusive.
Output
For each scientists' query (second type query) print a single integer in a new line β the value of impact of the infection on the DNA.
Examples
Input
ATGCATGC
4
2 1 8 ATGC
2 2 6 TTT
1 4 T
2 2 6 TA
Output
8
2
4
Input
GAGTTGTTAA
6
2 3 4 TATGGTG
1 1 T
1 6 G
2 5 9 AGTAATA
1 10 G
2 2 6 TTGT
Output
0
3
1
Note
Consider the first example. In the first query of second type all characters coincide, so the answer is 8. In the second query we compare string "TTTTT..." and the substring "TGCAT". There are two matches. In the third query, after the DNA change, we compare string "TATAT..."' with substring "TGTAT". There are 4 matches.
Submitted Solution:
```
while 1:
try:
l=list(map(int,input().split()))
n=l[0]
l.pop(0)
y=[]
f=0
for i in range(n-1):
x=abs(l[i]-l[i+1])
if x>=1 and x<n:
y.append(x)
else:
f=1
break
if f or len(y)!=len(set(y)) :
print('Not jolly')
else:
print('Jolly')
except:
break
``` | instruction | 0 | 56,106 | 6 | 112,212 |
No | output | 1 | 56,106 | 6 | 112,213 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A", "T", "G", "C". A DNA strand is a sequence of nucleotides. Scientists decided to track evolution of a rare species, which DNA strand was string s initially.
Evolution of the species is described as a sequence of changes in the DNA. Every change is a change of some nucleotide, for example, the following change can happen in DNA strand "AAGC": the second nucleotide can change to "T" so that the resulting DNA strand is "ATGC".
Scientists know that some segments of the DNA strand can be affected by some unknown infections. They can represent an infection as a sequence of nucleotides. Scientists are interested if there are any changes caused by some infections. Thus they sometimes want to know the value of impact of some infection to some segment of the DNA. This value is computed as follows:
* Let the infection be represented as a string e, and let scientists be interested in DNA strand segment starting from position l to position r, inclusive.
* Prefix of the string eee... (i.e. the string that consists of infinitely many repeats of string e) is written under the string s from position l to position r, inclusive.
* The value of impact is the number of positions where letter of string s coincided with the letter written under it.
Being a developer, Innokenty is interested in bioinformatics also, so the scientists asked him for help. Innokenty is busy preparing VK Cup, so he decided to delegate the problem to the competitors. Help the scientists!
Input
The first line contains the string s (1 β€ |s| β€ 105) that describes the initial DNA strand. It consists only of capital English letters "A", "T", "G" and "C".
The next line contains single integer q (1 β€ q β€ 105) β the number of events.
After that, q lines follow, each describes one event. Each of the lines has one of two formats:
* 1 x c, where x is an integer (1 β€ x β€ |s|), and c is a letter "A", "T", "G" or "C", which means that there is a change in the DNA: the nucleotide at position x is now c.
* 2 l r e, where l, r are integers (1 β€ l β€ r β€ |s|), and e is a string of letters "A", "T", "G" and "C" (1 β€ |e| β€ 10), which means that scientists are interested in the value of impact of infection e to the segment of DNA strand from position l to position r, inclusive.
Output
For each scientists' query (second type query) print a single integer in a new line β the value of impact of the infection on the DNA.
Examples
Input
ATGCATGC
4
2 1 8 ATGC
2 2 6 TTT
1 4 T
2 2 6 TA
Output
8
2
4
Input
GAGTTGTTAA
6
2 3 4 TATGGTG
1 1 T
1 6 G
2 5 9 AGTAATA
1 10 G
2 2 6 TTGT
Output
0
3
1
Note
Consider the first example. In the first query of second type all characters coincide, so the answer is 8. In the second query we compare string "TTTTT..." and the substring "TGCAT". There are two matches. In the third query, after the DNA change, we compare string "TATAT..."' with substring "TGTAT". There are 4 matches.
Submitted Solution:
```
from math import *
s=list(input())
for t in range(int(input())):
a=input().split()
if int(a[0])==1:
if len(a[2])>1:
k=int(a[1])
s=s[:k]+list(a[1])+s[k+1:]
else:
s[int(a[1])-1]=a[2]
else:
l=int(a[1])
r=int(a[2])
c=0
check=a[3].strip('.')
f=len(check)
if len(s)//f>1:
check*=round(len(s)/f)
y=0
if l==r:
if check[l-1]==s[r-1]:
print(t,1)
else:
print(t,0)
continue
else:
for i in range(l-1,r):
y+=1
if check[y-1]==s[i]:
c+=1
print(c)
``` | instruction | 0 | 56,107 | 6 | 112,214 |
No | output | 1 | 56,107 | 6 | 112,215 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A", "T", "G", "C". A DNA strand is a sequence of nucleotides. Scientists decided to track evolution of a rare species, which DNA strand was string s initially.
Evolution of the species is described as a sequence of changes in the DNA. Every change is a change of some nucleotide, for example, the following change can happen in DNA strand "AAGC": the second nucleotide can change to "T" so that the resulting DNA strand is "ATGC".
Scientists know that some segments of the DNA strand can be affected by some unknown infections. They can represent an infection as a sequence of nucleotides. Scientists are interested if there are any changes caused by some infections. Thus they sometimes want to know the value of impact of some infection to some segment of the DNA. This value is computed as follows:
* Let the infection be represented as a string e, and let scientists be interested in DNA strand segment starting from position l to position r, inclusive.
* Prefix of the string eee... (i.e. the string that consists of infinitely many repeats of string e) is written under the string s from position l to position r, inclusive.
* The value of impact is the number of positions where letter of string s coincided with the letter written under it.
Being a developer, Innokenty is interested in bioinformatics also, so the scientists asked him for help. Innokenty is busy preparing VK Cup, so he decided to delegate the problem to the competitors. Help the scientists!
Input
The first line contains the string s (1 β€ |s| β€ 105) that describes the initial DNA strand. It consists only of capital English letters "A", "T", "G" and "C".
The next line contains single integer q (1 β€ q β€ 105) β the number of events.
After that, q lines follow, each describes one event. Each of the lines has one of two formats:
* 1 x c, where x is an integer (1 β€ x β€ |s|), and c is a letter "A", "T", "G" or "C", which means that there is a change in the DNA: the nucleotide at position x is now c.
* 2 l r e, where l, r are integers (1 β€ l β€ r β€ |s|), and e is a string of letters "A", "T", "G" and "C" (1 β€ |e| β€ 10), which means that scientists are interested in the value of impact of infection e to the segment of DNA strand from position l to position r, inclusive.
Output
For each scientists' query (second type query) print a single integer in a new line β the value of impact of the infection on the DNA.
Examples
Input
ATGCATGC
4
2 1 8 ATGC
2 2 6 TTT
1 4 T
2 2 6 TA
Output
8
2
4
Input
GAGTTGTTAA
6
2 3 4 TATGGTG
1 1 T
1 6 G
2 5 9 AGTAATA
1 10 G
2 2 6 TTGT
Output
0
3
1
Note
Consider the first example. In the first query of second type all characters coincide, so the answer is 8. In the second query we compare string "TTTTT..." and the substring "TGCAT". There are two matches. In the third query, after the DNA change, we compare string "TATAT..."' with substring "TGTAT". There are 4 matches.
Submitted Solution:
```
a=input()
s=[]
s.extend(a)
print(s)
t=int(input())
while(t>0):
k=list(input().split())
c=[]
c.extend(k)
m=[]
m.extend(c[len(c)-1])
if(c[0]=='1'):
v=int(c[1])-1
s[v]=str(c[len(c)-1])
else:
n=0
ctr=0
l=int(c[1])-1
r=int(c[2])
for i in range(l,r):
if(s[i]==m[n]):
ctr+=1
n+=1
else:
n+=1
if(n==(len(m))):
n=0
print(ctr)
t-=1
``` | instruction | 0 | 56,108 | 6 | 112,216 |
No | output | 1 | 56,108 | 6 | 112,217 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|.
First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal.
After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 β€ l β€ i β€ r β€ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring.
Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically.
Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them.
Input
The first line contains the only integer n (1 β€ n β€ 100) β the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter.
Output
Output the only line β Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 β€ i β€ |a|), that ai < bi, and for any j (1 β€ j < i) aj = bj. |a| stands for the length of string a.
Examples
Input
3
bers
ucky
elu
PetrLoveLuckyNumbers
t
Output
PetrLovtTttttNumtttt
Input
4
hello
party
abefglghjdhfgj
IVan
petrsmatchwin
a
Output
petrsmatchwin
Input
2
aCa
cba
abAcaba
c
Output
abCacba | instruction | 0 | 56,150 | 6 | 112,300 |
Tags: implementation, strings
Correct Solution:
```
def main():
n = int(input())
forbidden = [input() for _ in range(n)]
res = input()
f = [0 for i in range(len(res))]
letter = input()
for i in range(n):
for j in range(len(res)):
if len(res[j:]) < len(forbidden[i]): break
if res[j: j + len(forbidden[i])].upper() == forbidden[i].upper():
for k in range(j, j + len(forbidden[i])):
f[k] = 1
ans = ""
for i in range(len(res)):
if (f[i] == 1):
if (res[i].upper() == letter.upper()):
if letter.upper() == 'A':
if res[i].isupper(): ans = ans + 'B'
else: ans = ans + 'b'
else:
if res[i].isupper(): ans = ans + 'A'
else: ans = ans + 'a'
else:
if res[i].isupper(): ans = ans + letter.upper()
else: ans = ans + letter
else: ans = ans + res[i]
print( ans)
if __name__ == '__main__':
main()
``` | output | 1 | 56,150 | 6 | 112,301 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|.
First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal.
After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 β€ l β€ i β€ r β€ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring.
Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically.
Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them.
Input
The first line contains the only integer n (1 β€ n β€ 100) β the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter.
Output
Output the only line β Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 β€ i β€ |a|), that ai < bi, and for any j (1 β€ j < i) aj = bj. |a| stands for the length of string a.
Examples
Input
3
bers
ucky
elu
PetrLoveLuckyNumbers
t
Output
PetrLovtTttttNumtttt
Input
4
hello
party
abefglghjdhfgj
IVan
petrsmatchwin
a
Output
petrsmatchwin
Input
2
aCa
cba
abAcaba
c
Output
abCacba | instruction | 0 | 56,151 | 6 | 112,302 |
Tags: implementation, strings
Correct Solution:
```
import sys
f = sys.stdin
#f = open("input.txt")
n = int(f.readline())
fbs = []
for i in range(n):
fbs.append(f.readline().strip())
s = f.readline().strip()
ch = f.readline().strip()
bChange = [0] * len(s)
for i in range(n):
idx = s.lower().find(fbs[i].lower())
while idx != -1:
bChange[idx:idx+len(fbs[i])] = [1] * len(fbs[i])
idx = s.lower().find(fbs[i].lower(), idx+1)
#print(s)
#print(bChange)
result = ['']*len(s)
for i in range(len(s)):
if bChange[i] == 1:
result[i] = ch
if result[i].upper() == s[i].upper():
if result[i].upper() == 'A':
result[i] = 'B'
else:
result[i] = 'A'
if s[i].isupper():
result[i] = result[i].upper()
else:
result[i] = result[i].lower()
else:
result[i] = s[i]
print("".join(result))
``` | output | 1 | 56,151 | 6 | 112,303 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|.
First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal.
After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 β€ l β€ i β€ r β€ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring.
Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically.
Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them.
Input
The first line contains the only integer n (1 β€ n β€ 100) β the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter.
Output
Output the only line β Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 β€ i β€ |a|), that ai < bi, and for any j (1 β€ j < i) aj = bj. |a| stands for the length of string a.
Examples
Input
3
bers
ucky
elu
PetrLoveLuckyNumbers
t
Output
PetrLovtTttttNumtttt
Input
4
hello
party
abefglghjdhfgj
IVan
petrsmatchwin
a
Output
petrsmatchwin
Input
2
aCa
cba
abAcaba
c
Output
abCacba | instruction | 0 | 56,152 | 6 | 112,304 |
Tags: implementation, strings
Correct Solution:
```
n = int(input())
b = []
for i in range(n):
b.append(input())
w = input()
let = input()
bad = [False for i in range(len(w))]
for i in range(len(w)):
mx = 0
for j in range(n):
if w[i:].lower().startswith(b[j].lower()):
mx = max(mx, len(b[j]))
for j in range(mx):
bad[i + j] = True
ans = ''
for i in range(len(w)):
if not bad[i]:
ans += w[i]
else:
if w[i].lower() == let:
newlet = 'a' if let != 'a' else 'b'
ans += newlet.lower() if w[i].lower() == w[i] else \
newlet.upper()
else:
ans += let if w[i].lower() == w[i] else let.upper()
print(ans)
``` | output | 1 | 56,152 | 6 | 112,305 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|.
First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal.
After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 β€ l β€ i β€ r β€ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring.
Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically.
Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them.
Input
The first line contains the only integer n (1 β€ n β€ 100) β the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter.
Output
Output the only line β Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 β€ i β€ |a|), that ai < bi, and for any j (1 β€ j < i) aj = bj. |a| stands for the length of string a.
Examples
Input
3
bers
ucky
elu
PetrLoveLuckyNumbers
t
Output
PetrLovtTttttNumtttt
Input
4
hello
party
abefglghjdhfgj
IVan
petrsmatchwin
a
Output
petrsmatchwin
Input
2
aCa
cba
abAcaba
c
Output
abCacba | instruction | 0 | 56,153 | 6 | 112,306 |
Tags: implementation, strings
Correct Solution:
```
#from bisect import bisect_left as bl #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br #c++ upperbound br(array,element)
#from __future__ import print_function, division #while using python2
# from itertools import accumulate
# from collections import defaultdict, Counter
def modinv(n,p):
return pow(n,p-2,p)
def main():
#sys.stdin = open('input.txt', 'r')
#sys.stdout = open('output.txt', 'w')
n = int(input())
forbidden = []
for i in range(n):
forbidden.append(input())
parent = input()
c = input()
to_be_replaced = set()
for key in forbidden:
s = parent.lower()
key = key.lower()
i = 0
while s[i:].find(key) != -1:
i = i + s[i:].find(key)
for j in range(i, i+len(key)):
to_be_replaced.add(j)
i += 1
# print(i)
# input()
# print("after key", key)
# print(to_be_replaced)
ans = []
for i in range(len(parent)):
cur = parent[i]
if i in to_be_replaced:
# print("cur =", cur)
if cur == c.lower() or cur == c.upper():
if c in 'aA':
if cur.islower():
ans.append('b')
else:
ans.append('B')
else:
if cur.islower():
ans.append('a')
else:
ans.append('A')
elif cur == cur.upper():
ans.append(c.upper())
elif cur == cur.lower():
ans.append(c.lower())
else:
ans.append(cur)
print("".join(ans))
#------------------ Python 2 and 3 footer by Pajenegod and c1729-----------------------------------------
py2 = round(0.5)
if py2:
from future_builtins import ascii, filter, hex, map, oct, zip
range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192
class FastIO(BytesIO):
newlines = 0
def __init__(self, file):
self._file = file
self._fd = file.fileno()
self.writable = "x" in file.mode or "w" in file.mode
self.write = super(FastIO, self).write if self.writable else None
def _fill(self):
s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
return s
def read(self):
while self._fill(): pass
return super(FastIO,self).read()
def readline(self):
while self.newlines == 0:
s = self._fill(); self.newlines = s.count(b"\n") + (not s)
self.newlines -= 1
return super(FastIO, self).readline()
def flush(self):
if self.writable:
os.write(self._fd, self.getvalue())
self.truncate(0), self.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
if py2:
self.write = self.buffer.write
self.read = self.buffer.read
self.readline = self.buffer.readline
else:
self.write = lambda s:self.buffer.write(s.encode('ascii'))
self.read = lambda:self.buffer.read().decode('ascii')
self.readline = lambda:self.buffer.readline().decode('ascii')
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
if __name__ == '__main__':
main()
``` | output | 1 | 56,153 | 6 | 112,307 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|.
First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal.
After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 β€ l β€ i β€ r β€ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring.
Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically.
Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them.
Input
The first line contains the only integer n (1 β€ n β€ 100) β the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter.
Output
Output the only line β Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 β€ i β€ |a|), that ai < bi, and for any j (1 β€ j < i) aj = bj. |a| stands for the length of string a.
Examples
Input
3
bers
ucky
elu
PetrLoveLuckyNumbers
t
Output
PetrLovtTttttNumtttt
Input
4
hello
party
abefglghjdhfgj
IVan
petrsmatchwin
a
Output
petrsmatchwin
Input
2
aCa
cba
abAcaba
c
Output
abCacba | instruction | 0 | 56,154 | 6 | 112,308 |
Tags: implementation, strings
Correct Solution:
```
from math import*
a=[list(input().lower()) for i in range(int(input()))]
s=input()
s0=list(s)
s=list(s.lower())
c=input()
C=chr(ord(c)-ord('a')+ord('A'))
r=['.']*len(s)
for t in a:
for i in range(len(s)-len(t)+1):
#print(s[i:i+len(t)],t)
if(s[i:i+len(t)]==t):
r[i:i+len(t)]=t
s=s0
for i in range(len(s)):
if r[i]!='.':
if ord(s[i])<=ord('Z'):
if s[i]==C:
if C=='A':
s[i]='B'
else:
s[i]='A'
else:
s[i]=C
else:
if s[i]==c:
if c=='a':
s[i]='b'
else:
s[i]='a'
else:
s[i]=c
print(*s,sep='')
``` | output | 1 | 56,154 | 6 | 112,309 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|.
First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal.
After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 β€ l β€ i β€ r β€ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring.
Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically.
Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them.
Input
The first line contains the only integer n (1 β€ n β€ 100) β the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter.
Output
Output the only line β Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 β€ i β€ |a|), that ai < bi, and for any j (1 β€ j < i) aj = bj. |a| stands for the length of string a.
Examples
Input
3
bers
ucky
elu
PetrLoveLuckyNumbers
t
Output
PetrLovtTttttNumtttt
Input
4
hello
party
abefglghjdhfgj
IVan
petrsmatchwin
a
Output
petrsmatchwin
Input
2
aCa
cba
abAcaba
c
Output
abCacba | instruction | 0 | 56,155 | 6 | 112,310 |
Tags: implementation, strings
Correct Solution:
```
import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def same(a, b):
return a.lower() == b.lower()
n = mint()
w = []
for i in range(n):
w.append(minp().lower())
s = minp()
g = [False]*len(s)
c = minp()
for i in w:
for j in range(len(s)-len(i)+1):
if s[j:j+len(i)].lower() == i:
for k in range(len(i)):
g[j+k] = True
r = ''
for i in range(len(s)):
if g[i]:
x = s[i]
if x == c.lower():
if c.lower() == 'a':
r += 'b'
else:
r += 'a'
elif x == c.upper():
if c.lower() == 'a':
r += 'B'
else:
r += 'A'
elif x.islower():
r += c.lower()
else:
r += c.upper()
else:
r += s[i]
print(r)
``` | output | 1 | 56,155 | 6 | 112,311 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|.
First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal.
After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 β€ l β€ i β€ r β€ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring.
Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically.
Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them.
Input
The first line contains the only integer n (1 β€ n β€ 100) β the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter.
Output
Output the only line β Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 β€ i β€ |a|), that ai < bi, and for any j (1 β€ j < i) aj = bj. |a| stands for the length of string a.
Examples
Input
3
bers
ucky
elu
PetrLoveLuckyNumbers
t
Output
PetrLovtTttttNumtttt
Input
4
hello
party
abefglghjdhfgj
IVan
petrsmatchwin
a
Output
petrsmatchwin
Input
2
aCa
cba
abAcaba
c
Output
abCacba | instruction | 0 | 56,156 | 6 | 112,312 |
Tags: implementation, strings
Correct Solution:
```
n=int(input())
a=[input() for i in range(n)]
w=input()
b=[False for i in range(len(w))]
c=input()
for i in range(len(w)):
z=0
for s in a:
if w[i:].lower().startswith(s.lower()):
z=max(z,len(s))
for j in range(i,i+z): b[j]=True
s=''
for i in range(len(w)):
if b[i]:
if w[i].lower()==c:
if c!='a':
d='a'
else:
d='b'
if w[i].lower()==w[i]:
s+=d.lower()
else:
s+=d.upper()
else:
if w[i].lower()==w[i]:
s+=c
else:
s+=c.upper()
else:
s+=w[i]
print(s)
``` | output | 1 | 56,156 | 6 | 112,313 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|.
First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal.
After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 β€ l β€ i β€ r β€ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring.
Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically.
Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them.
Input
The first line contains the only integer n (1 β€ n β€ 100) β the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter.
Output
Output the only line β Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 β€ i β€ |a|), that ai < bi, and for any j (1 β€ j < i) aj = bj. |a| stands for the length of string a.
Examples
Input
3
bers
ucky
elu
PetrLoveLuckyNumbers
t
Output
PetrLovtTttttNumtttt
Input
4
hello
party
abefglghjdhfgj
IVan
petrsmatchwin
a
Output
petrsmatchwin
Input
2
aCa
cba
abAcaba
c
Output
abCacba | instruction | 0 | 56,157 | 6 | 112,314 |
Tags: implementation, strings
Correct Solution:
```
n= int(input())#how many word
b = []
for i in range(n):
b.append(input())# put the word in a list
w = input()#what we whant to change
let = input()#which we change in to
bad=[]
for i in range(len(w)):
bad.append(True)
for i in range(len(w)):
mx = 0
for j in range(n):
if w[i:].lower().startswith(b[j].lower()):
mx =max(mx,len(b[j]))
for j in range(mx):
bad[i + j] = False
ans = ''
for i in range(len(w)):
if bad[i]:
ans += w[i]
else:
if w[i].lower() == let:
newlet = 'a' if let != 'a' else 'b'
ans += newlet.lower() if w[i].lower() == w[i] else \
newlet.upper()
else:
if w[i].lower() == w[i]:
ans += let
else:
ans+=let.upper()
print(ans)
# Made By Mostafa_Khaled
``` | output | 1 | 56,157 | 6 | 112,315 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an easier version of the problem E with smaller constraints.
Twilight Sparkle has received a new task from Princess Celestia. This time she asked to decipher the ancient scroll containing important knowledge of pony origin.
To hide the crucial information from evil eyes, pony elders cast a spell on the scroll. That spell adds exactly one letter in any place to each word it is cast on. To make the path to the knowledge more tangled elders chose some of words in the scroll and cast a spell on them.
Twilight Sparkle knows that the elders admired the order in all things so the scroll original scroll contained words in lexicographically non-decreasing order. She is asked to delete one letter from some of the words of the scroll (to undo the spell) to get some version of the original scroll.
Unfortunately, there may be more than one way to recover the ancient scroll. To not let the important knowledge slip by Twilight has to look through all variants of the original scroll and find the required one. To estimate the maximum time Twilight may spend on the work she needs to know the number of variants she has to look through. She asks you to find that number! Since that number can be very big, Twilight asks you to find it modulo 10^9+7.
It may occur that princess Celestia has sent a wrong scroll so the answer may not exist.
A string a is lexicographically smaller than a string b if and only if one of the following holds:
* a is a prefix of b, but a β b;
* in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
Input
The first line contains a single integer n (1 β€ n β€ 1000): the number of words in the scroll.
The i-th of the next n lines contains a string consisting of lowercase English letters: the i-th word in the scroll. The length of each word is more or equal than 1. The sum of lengths of words does not exceed 20000.
Output
Print one integer: the number of ways to get a version of the original from the scroll modulo 10^9+7.
Examples
Input
3
abcd
zaza
ataka
Output
4
Input
4
dfs
bfs
sms
mms
Output
8
Input
3
abc
bcd
a
Output
0
Input
6
lapochka
kartyshka
bigbabytape
morgenshtern
ssshhhiiittt
queen
Output
2028
Note
Notice that the elders could have written an empty word (but they surely cast a spell on it so it holds a length 1 now).
Submitted Solution:
```
def func(string):
return sorted([[string[:i]+string[i+1:], 0] for i in range(len(string)+1)], key = lambda x: x[0])
n = int(input())
strings = []
for i in range(n):
strings.append(input())
variationsNew = sorted([[strings[0][:i]+strings[0][i+1:], 1] for i in range(len(strings[0])+1)], key = lambda x: x[0])
try:
variationsNew.remove("")
except:
pass
for i in range(1,n):
variationsOld = variationsNew.copy()
variationsNew = func(strings[i])
try:
variationsNew.remove("")
except:
pass
for j, new in enumerate(variationsNew):
for k, old in enumerate(variationsOld):
if new[0]>=old[0]:
variationsNew[j][1] += variationsOld[k][1]
else:
break
print(sum([count for string, count in variationsNew]))
``` | instruction | 0 | 56,556 | 6 | 113,112 |
No | output | 1 | 56,556 | 6 | 113,113 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an easier version of the problem E with smaller constraints.
Twilight Sparkle has received a new task from Princess Celestia. This time she asked to decipher the ancient scroll containing important knowledge of pony origin.
To hide the crucial information from evil eyes, pony elders cast a spell on the scroll. That spell adds exactly one letter in any place to each word it is cast on. To make the path to the knowledge more tangled elders chose some of words in the scroll and cast a spell on them.
Twilight Sparkle knows that the elders admired the order in all things so the scroll original scroll contained words in lexicographically non-decreasing order. She is asked to delete one letter from some of the words of the scroll (to undo the spell) to get some version of the original scroll.
Unfortunately, there may be more than one way to recover the ancient scroll. To not let the important knowledge slip by Twilight has to look through all variants of the original scroll and find the required one. To estimate the maximum time Twilight may spend on the work she needs to know the number of variants she has to look through. She asks you to find that number! Since that number can be very big, Twilight asks you to find it modulo 10^9+7.
It may occur that princess Celestia has sent a wrong scroll so the answer may not exist.
A string a is lexicographically smaller than a string b if and only if one of the following holds:
* a is a prefix of b, but a β b;
* in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
Input
The first line contains a single integer n (1 β€ n β€ 1000): the number of words in the scroll.
The i-th of the next n lines contains a string consisting of lowercase English letters: the i-th word in the scroll. The length of each word is more or equal than 1. The sum of lengths of words does not exceed 20000.
Output
Print one integer: the number of ways to get a version of the original from the scroll modulo 10^9+7.
Examples
Input
3
abcd
zaza
ataka
Output
4
Input
4
dfs
bfs
sms
mms
Output
8
Input
3
abc
bcd
a
Output
0
Input
6
lapochka
kartyshka
bigbabytape
morgenshtern
ssshhhiiittt
queen
Output
2028
Note
Notice that the elders could have written an empty word (but they surely cast a spell on it so it holds a length 1 now).
Submitted Solution:
```
import sys
n = int(sys.stdin.readline().strip())
S = [""]
for i in range (0, n):
S.append(sys.stdin.readline().strip())
F1 = [1]
for i in range (0, n):
F2 = [0] * (len(S[i+1]) + 1)
if S[i] <= S[i+1]:
F2[0] = F2[0] + F1[0]
for j in range (0, len(F1) - 1):
if S[i][:j] + S[i][j+1:] <= S[i+1]:
F2[0] = F2[0] + F1[j+1]
for k in range (0, len(F2) - 1):
if S[i] <= S[i+1][:k] + S[i+1][k+1:]:
F2[k+1] = F2[k+1] + F1[0]
for j in range (0, len(F1) - 1):
for k in range (0, len(F2) - 1):
if S[i][:j] + S[i][j+1:] <= S[i+1][:k] + S[i+1][k+1:]:
F2[k+1] = F2[k+1] + F1[j+1]
F1 = F2
print(sum(F2))
``` | instruction | 0 | 56,557 | 6 | 113,114 |
No | output | 1 | 56,557 | 6 | 113,115 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an easier version of the problem E with smaller constraints.
Twilight Sparkle has received a new task from Princess Celestia. This time she asked to decipher the ancient scroll containing important knowledge of pony origin.
To hide the crucial information from evil eyes, pony elders cast a spell on the scroll. That spell adds exactly one letter in any place to each word it is cast on. To make the path to the knowledge more tangled elders chose some of words in the scroll and cast a spell on them.
Twilight Sparkle knows that the elders admired the order in all things so the scroll original scroll contained words in lexicographically non-decreasing order. She is asked to delete one letter from some of the words of the scroll (to undo the spell) to get some version of the original scroll.
Unfortunately, there may be more than one way to recover the ancient scroll. To not let the important knowledge slip by Twilight has to look through all variants of the original scroll and find the required one. To estimate the maximum time Twilight may spend on the work she needs to know the number of variants she has to look through. She asks you to find that number! Since that number can be very big, Twilight asks you to find it modulo 10^9+7.
It may occur that princess Celestia has sent a wrong scroll so the answer may not exist.
A string a is lexicographically smaller than a string b if and only if one of the following holds:
* a is a prefix of b, but a β b;
* in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
Input
The first line contains a single integer n (1 β€ n β€ 1000): the number of words in the scroll.
The i-th of the next n lines contains a string consisting of lowercase English letters: the i-th word in the scroll. The length of each word is more or equal than 1. The sum of lengths of words does not exceed 20000.
Output
Print one integer: the number of ways to get a version of the original from the scroll modulo 10^9+7.
Examples
Input
3
abcd
zaza
ataka
Output
4
Input
4
dfs
bfs
sms
mms
Output
8
Input
3
abc
bcd
a
Output
0
Input
6
lapochka
kartyshka
bigbabytape
morgenshtern
ssshhhiiittt
queen
Output
2028
Note
Notice that the elders could have written an empty word (but they surely cast a spell on it so it holds a length 1 now).
Submitted Solution:
```
def func(string):
return sorted([[string[:i]+string[i+1:], 0] for i in range(len(string)+1)])
n = int(input())
strings = []
for i in range(n):
strings.append(input())
variationsNew = sorted([[strings[0][:i]+strings[0][i+1:], 1] for i in range(len(strings[0])+1)])
for i in range(1,n):
variationsOld = variationsNew.copy()
variationsNew = func(strings[i])
for j, new in enumerate(variationsNew):
for k, old in enumerate(variationsOld):
#print(variationsOld, variationsNew)
if new[0]>=old[0]:
variationsNew[j][1] += variationsOld[k][1]
else:
break
'''else:
break
else:
variationsNew = [[string,count] if count!=0 else variationsNew[j][1] for string, count in variationsNew]'''
print(sum([count for string, count in variationsNew]))
``` | instruction | 0 | 56,558 | 6 | 113,116 |
No | output | 1 | 56,558 | 6 | 113,117 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an easier version of the problem E with smaller constraints.
Twilight Sparkle has received a new task from Princess Celestia. This time she asked to decipher the ancient scroll containing important knowledge of pony origin.
To hide the crucial information from evil eyes, pony elders cast a spell on the scroll. That spell adds exactly one letter in any place to each word it is cast on. To make the path to the knowledge more tangled elders chose some of words in the scroll and cast a spell on them.
Twilight Sparkle knows that the elders admired the order in all things so the scroll original scroll contained words in lexicographically non-decreasing order. She is asked to delete one letter from some of the words of the scroll (to undo the spell) to get some version of the original scroll.
Unfortunately, there may be more than one way to recover the ancient scroll. To not let the important knowledge slip by Twilight has to look through all variants of the original scroll and find the required one. To estimate the maximum time Twilight may spend on the work she needs to know the number of variants she has to look through. She asks you to find that number! Since that number can be very big, Twilight asks you to find it modulo 10^9+7.
It may occur that princess Celestia has sent a wrong scroll so the answer may not exist.
A string a is lexicographically smaller than a string b if and only if one of the following holds:
* a is a prefix of b, but a β b;
* in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
Input
The first line contains a single integer n (1 β€ n β€ 1000): the number of words in the scroll.
The i-th of the next n lines contains a string consisting of lowercase English letters: the i-th word in the scroll. The length of each word is more or equal than 1. The sum of lengths of words does not exceed 20000.
Output
Print one integer: the number of ways to get a version of the original from the scroll modulo 10^9+7.
Examples
Input
3
abcd
zaza
ataka
Output
4
Input
4
dfs
bfs
sms
mms
Output
8
Input
3
abc
bcd
a
Output
0
Input
6
lapochka
kartyshka
bigbabytape
morgenshtern
ssshhhiiittt
queen
Output
2028
Note
Notice that the elders could have written an empty word (but they surely cast a spell on it so it holds a length 1 now).
Submitted Solution:
```
T = int(input())
dp = []
nextdp = []
ss= []
def strgte(s2,i,s1,j):
idx1 = 0
idx2 = 0
while True:
if idx2 == i and i != len(s2):
idx2 += 1
if idx1 == j and j != len(s1):
idx1 += 1
#print(ord(s2[idx2]),ord(s1[idx1]))
if idx1 >= len(s1):
return True
if idx2 >= len(s2):
return False
if ord(s2[idx2]) < ord(s1[idx1]):
return False
if ord(s2[idx2]) > ord(s1[idx1]):
return True
idx1 += 1
idx2 += 1
#print(strgte("abcd",0,"abcde",1))
#print(strgte("bcd",0,"bcde",0))
#print(strgte("bcd",0,"bcd",0))
for case in range(T):
#i = int(input())
s = input()
ss.append(s)
#m,n = [int(x) for x in input().split()]
#ls = [int(x) for x in input().split()]
if case == 0:
dp = [1] * (len(s) + 1)
continue
for i in range(len(s)+1):
c = 0
for j in range(len(ss[-2])+1):
if strgte(s,i,ss[-2],j):
c += dp[j]
nextdp.append(c% (10**9+7))
#print(dp,nextdp)
if case == T-1:
break
dp = nextdp[:]
nextdp = []
#print(dp,nextdp)
#print(r)
print(sum(nextdp) % (10**9+7))
``` | instruction | 0 | 56,559 | 6 | 113,118 |
No | output | 1 | 56,559 | 6 | 113,119 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna and Dima bought a table of size n Γ m in the shop. Each cell of the table contains a single letter: "D", "I", "M", "A".
Inna loves Dima, so she wants to go through his name as many times as possible as she moves through the table. For that, Inna acts as follows:
1. initially, Inna chooses some cell of the table where letter "D" is written;
2. then Inna can move to some side-adjacent table cell that contains letter "I"; then from this cell she can go to one of the side-adjacent table cells that contains the written letter "M"; then she can go to a side-adjacent cell that contains letter "A". Then Inna assumes that she has gone through her sweetheart's name;
3. Inna's next move can be going to one of the side-adjacent table cells that contains letter "D" and then walk on through name DIMA in the similar manner. Inna never skips a letter. So, from the letter "D" she always goes to the letter "I", from the letter "I" she always goes the to letter "M", from the letter "M" she always goes to the letter "A", and from the letter "A" she always goes to the letter "D".
Depending on the choice of the initial table cell, Inna can go through name DIMA either an infinite number of times or some positive finite number of times or she can't go through his name once. Help Inna find out what maximum number of times she can go through name DIMA.
Input
The first line of the input contains two integers n and m (1 β€ n, m β€ 103).
Then follow n lines that describe Inna and Dima's table. Each line contains m characters. Each character is one of the following four characters: "D", "I", "M", "A".
Note that it is not guaranteed that the table contains at least one letter "D".
Output
If Inna cannot go through name DIMA once, print on a single line "Poor Dima!" without the quotes. If there is the infinite number of names DIMA Inna can go through, print "Poor Inna!" without the quotes. Otherwise print a single integer β the maximum number of times Inna can go through name DIMA.
Examples
Input
1 2
DI
Output
Poor Dima!
Input
2 2
MA
ID
Output
Poor Inna!
Input
5 5
DIMAD
DIMAI
DIMAM
DDMAA
AAMID
Output
4
Note
Notes to the samples:
In the first test sample, Inna cannot go through name DIMA a single time.
In the second test sample, Inna can go through the infinite number of words DIMA. For that, she should move in the clockwise direction starting from the lower right corner.
In the third test sample the best strategy is to start from the cell in the upper left corner of the table. Starting from this cell, Inna can go through name DIMA four times. | instruction | 0 | 56,683 | 6 | 113,366 |
Tags: dfs and similar, dp, graphs, implementation
Correct Solution:
```
import sys
n, m = map(int, input().split())
m += 1
d = {'I': 0, 'M': 1, 'A': 2, 'D': 3, '\n': -7}
t = list(map(d.get, sys.stdin.read())) + [-7] * m
p = [[] for q in t]
c = [0] * len(t)
for a in range(n * m):
for b in (a - m, a + m, a - 1, a + 1):
if abs(t[b] - t[a] + 1) == 2:
p[a].append(b)
c[b] += 1
s = [i for i, q in enumerate(c) if not q]
while s:
a = s.pop()
for b in p[a]:
t[b] = max(t[b], t[a] + 1)
c[b] -= 1
if c[b] == 0: s.append(b)
k = max(t) - 2 >> 2
print('Poor Inna!' if any(c) else k if k > 0 else 'Poor Dima!')
``` | output | 1 | 56,683 | 6 | 113,367 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna and Dima bought a table of size n Γ m in the shop. Each cell of the table contains a single letter: "D", "I", "M", "A".
Inna loves Dima, so she wants to go through his name as many times as possible as she moves through the table. For that, Inna acts as follows:
1. initially, Inna chooses some cell of the table where letter "D" is written;
2. then Inna can move to some side-adjacent table cell that contains letter "I"; then from this cell she can go to one of the side-adjacent table cells that contains the written letter "M"; then she can go to a side-adjacent cell that contains letter "A". Then Inna assumes that she has gone through her sweetheart's name;
3. Inna's next move can be going to one of the side-adjacent table cells that contains letter "D" and then walk on through name DIMA in the similar manner. Inna never skips a letter. So, from the letter "D" she always goes to the letter "I", from the letter "I" she always goes the to letter "M", from the letter "M" she always goes to the letter "A", and from the letter "A" she always goes to the letter "D".
Depending on the choice of the initial table cell, Inna can go through name DIMA either an infinite number of times or some positive finite number of times or she can't go through his name once. Help Inna find out what maximum number of times she can go through name DIMA.
Input
The first line of the input contains two integers n and m (1 β€ n, m β€ 103).
Then follow n lines that describe Inna and Dima's table. Each line contains m characters. Each character is one of the following four characters: "D", "I", "M", "A".
Note that it is not guaranteed that the table contains at least one letter "D".
Output
If Inna cannot go through name DIMA once, print on a single line "Poor Dima!" without the quotes. If there is the infinite number of names DIMA Inna can go through, print "Poor Inna!" without the quotes. Otherwise print a single integer β the maximum number of times Inna can go through name DIMA.
Examples
Input
1 2
DI
Output
Poor Dima!
Input
2 2
MA
ID
Output
Poor Inna!
Input
5 5
DIMAD
DIMAI
DIMAM
DDMAA
AAMID
Output
4
Note
Notes to the samples:
In the first test sample, Inna cannot go through name DIMA a single time.
In the second test sample, Inna can go through the infinite number of words DIMA. For that, she should move in the clockwise direction starting from the lower right corner.
In the third test sample the best strategy is to start from the cell in the upper left corner of the table. Starting from this cell, Inna can go through name DIMA four times. | instruction | 0 | 56,684 | 6 | 113,368 |
Tags: dfs and similar, dp, graphs, implementation
Correct Solution:
```
n, m = map(int, input().split())
m += 1
q = {'I': 0, 'M': 1, 'A': 2, 'D': 3}
t = []
for i in range(n):
t += map(q.get, input())
t.append(-7)
t += [-7] * m
p = [[] for q in t]
c = [0] * len(t)
for a in range(n * m):
for b in (a - m, a + m, a - 1, a + 1):
if abs(t[b] - t[a] + 1) == 2:
p[a].append(b)
c[b] += 1
s = [i for i, q in enumerate(c) if not q]
while s:
a = s.pop()
for b in p[a]:
t[b] = max(t[b], t[a] + 1)
c[b] -= 1
if c[b] == 0: s.append(b)
k = max(t) - 2 >> 2
print('Poor Inna!' if any(c) else k if k > 0 else 'Poor Dima!')
``` | output | 1 | 56,684 | 6 | 113,369 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna and Dima bought a table of size n Γ m in the shop. Each cell of the table contains a single letter: "D", "I", "M", "A".
Inna loves Dima, so she wants to go through his name as many times as possible as she moves through the table. For that, Inna acts as follows:
1. initially, Inna chooses some cell of the table where letter "D" is written;
2. then Inna can move to some side-adjacent table cell that contains letter "I"; then from this cell she can go to one of the side-adjacent table cells that contains the written letter "M"; then she can go to a side-adjacent cell that contains letter "A". Then Inna assumes that she has gone through her sweetheart's name;
3. Inna's next move can be going to one of the side-adjacent table cells that contains letter "D" and then walk on through name DIMA in the similar manner. Inna never skips a letter. So, from the letter "D" she always goes to the letter "I", from the letter "I" she always goes the to letter "M", from the letter "M" she always goes to the letter "A", and from the letter "A" she always goes to the letter "D".
Depending on the choice of the initial table cell, Inna can go through name DIMA either an infinite number of times or some positive finite number of times or she can't go through his name once. Help Inna find out what maximum number of times she can go through name DIMA.
Input
The first line of the input contains two integers n and m (1 β€ n, m β€ 103).
Then follow n lines that describe Inna and Dima's table. Each line contains m characters. Each character is one of the following four characters: "D", "I", "M", "A".
Note that it is not guaranteed that the table contains at least one letter "D".
Output
If Inna cannot go through name DIMA once, print on a single line "Poor Dima!" without the quotes. If there is the infinite number of names DIMA Inna can go through, print "Poor Inna!" without the quotes. Otherwise print a single integer β the maximum number of times Inna can go through name DIMA.
Examples
Input
1 2
DI
Output
Poor Dima!
Input
2 2
MA
ID
Output
Poor Inna!
Input
5 5
DIMAD
DIMAI
DIMAM
DDMAA
AAMID
Output
4
Note
Notes to the samples:
In the first test sample, Inna cannot go through name DIMA a single time.
In the second test sample, Inna can go through the infinite number of words DIMA. For that, she should move in the clockwise direction starting from the lower right corner.
In the third test sample the best strategy is to start from the cell in the upper left corner of the table. Starting from this cell, Inna can go through name DIMA four times. | instruction | 0 | 56,685 | 6 | 113,370 |
Tags: dfs and similar, dp, graphs, implementation
Correct Solution:
```
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
# from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
try:
# sys.setrecursionlimit(int(pow(10,6)))
sys.stdin = open("input.txt", "r")
# sys.stdout = open("../output.txt", "w")
except:
pass
n, m = L()
m += 1
q = {'I': 0, 'M': 1, 'A': 2, 'D': 3}
t = []
for i in range(n):
t += map(q.get, input())
t.append(-7)
t += [-7] * m
# print(t)
p = [[] for q in t]
c = [0] * len(t)
for a in range(n * m):
for b in (a - m, a + m, a - 1, a + 1):
if abs(t[b] - t[a] + 1) == 2:
p[a].append(b)
c[b] += 1
s = [i for i, q in enumerate(c) if not q]
while s:
a = s.pop()
for b in p[a]:
t[b] = max(t[b], t[a] + 1)
c[b] -= 1
if c[b] == 0: s.append(b)
k = max(t) - 2 >> 2
print('Poor Inna!' if any(c) else k if k > 0 else 'Poor Dima!')
endtime = time.time()
# print(f"Runtime of the program is {endtime - starttime}")
``` | output | 1 | 56,685 | 6 | 113,371 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Inna and Dima bought a table of size n Γ m in the shop. Each cell of the table contains a single letter: "D", "I", "M", "A".
Inna loves Dima, so she wants to go through his name as many times as possible as she moves through the table. For that, Inna acts as follows:
1. initially, Inna chooses some cell of the table where letter "D" is written;
2. then Inna can move to some side-adjacent table cell that contains letter "I"; then from this cell she can go to one of the side-adjacent table cells that contains the written letter "M"; then she can go to a side-adjacent cell that contains letter "A". Then Inna assumes that she has gone through her sweetheart's name;
3. Inna's next move can be going to one of the side-adjacent table cells that contains letter "D" and then walk on through name DIMA in the similar manner. Inna never skips a letter. So, from the letter "D" she always goes to the letter "I", from the letter "I" she always goes the to letter "M", from the letter "M" she always goes to the letter "A", and from the letter "A" she always goes to the letter "D".
Depending on the choice of the initial table cell, Inna can go through name DIMA either an infinite number of times or some positive finite number of times or she can't go through his name once. Help Inna find out what maximum number of times she can go through name DIMA.
Input
The first line of the input contains two integers n and m (1 β€ n, m β€ 103).
Then follow n lines that describe Inna and Dima's table. Each line contains m characters. Each character is one of the following four characters: "D", "I", "M", "A".
Note that it is not guaranteed that the table contains at least one letter "D".
Output
If Inna cannot go through name DIMA once, print on a single line "Poor Dima!" without the quotes. If there is the infinite number of names DIMA Inna can go through, print "Poor Inna!" without the quotes. Otherwise print a single integer β the maximum number of times Inna can go through name DIMA.
Examples
Input
1 2
DI
Output
Poor Dima!
Input
2 2
MA
ID
Output
Poor Inna!
Input
5 5
DIMAD
DIMAI
DIMAM
DDMAA
AAMID
Output
4
Note
Notes to the samples:
In the first test sample, Inna cannot go through name DIMA a single time.
In the second test sample, Inna can go through the infinite number of words DIMA. For that, she should move in the clockwise direction starting from the lower right corner.
In the third test sample the best strategy is to start from the cell in the upper left corner of the table. Starting from this cell, Inna can go through name DIMA four times.
Submitted Solution:
```
n, m = map(int, input().split())
m += 1
q = {'I': 0, 'M': 1, 'A': 2, 'D': 3}
t = []
for i in range(n):
t += map(q.get, input())
t.append(-7)
t += [-7] * m
p = [[] for q in t]
c = [0] * len(t)
for a in range(n * m):
for b in (a - m, a + m, a - 1, a + 1):
if abs(t[b] - t[a] + 1) == 2:
p[a].append(b)
c[b] += 1
s = [i for i, q in enumerate(c) if not q]
while s:
a = s.pop()
for b in p[a]:
t[b] = max(t[b], t[a] + 1)
c[b] -= 1
if c[b] == 0: s.append(b)
k = max(t) - 2 >> 2
print('Poor Inna!' if any(c) else k if k else 'Poor Dima!')
``` | instruction | 0 | 56,686 | 6 | 113,372 |
No | output | 1 | 56,686 | 6 | 113,373 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the Β«translationΒ». Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if he translated the word correctly.
Input
The first line contains word s, the second line contains word t. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output
If the word t is a word s, written reversely, print YES, otherwise print NO.
Examples
Input
code
edoc
Output
YES
Input
abb
aba
Output
NO
Input
code
code
Output
NO | instruction | 0 | 56,689 | 6 | 113,378 |
Tags: implementation, strings
Correct Solution:
```
i=input()
l=input()
j=len(l)
n=0
while n<j:
if i[n:n+1]!=l[j-n-1:j-n]:
print('NO')
exit()
n=n+1
print('YES')
``` | output | 1 | 56,689 | 6 | 113,379 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the Β«translationΒ». Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if he translated the word correctly.
Input
The first line contains word s, the second line contains word t. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output
If the word t is a word s, written reversely, print YES, otherwise print NO.
Examples
Input
code
edoc
Output
YES
Input
abb
aba
Output
NO
Input
code
code
Output
NO | instruction | 0 | 56,690 | 6 | 113,380 |
Tags: implementation, strings
Correct Solution:
```
if __name__=="__main__":
list1=input()
list2=input()
rev=[]
flag=0
for i in range(len(list1)-1,-1,-1):
rev.append(list1[i])
for i in range(0,len(rev)):
if rev[i]!=list2[i]:
flag=1
break
if flag==1:
print("NO")
else:
print("YES")
``` | output | 1 | 56,690 | 6 | 113,381 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the Β«translationΒ». Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if he translated the word correctly.
Input
The first line contains word s, the second line contains word t. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output
If the word t is a word s, written reversely, print YES, otherwise print NO.
Examples
Input
code
edoc
Output
YES
Input
abb
aba
Output
NO
Input
code
code
Output
NO | instruction | 0 | 56,691 | 6 | 113,382 |
Tags: implementation, strings
Correct Solution:
```
s_word = input()
t_word = input()
t_reword = ""
for w in t_word:
t_reword = w + t_reword
if s_word == t_reword:
print("YES")
else:
print("NO")
``` | output | 1 | 56,691 | 6 | 113,383 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the Β«translationΒ». Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if he translated the word correctly.
Input
The first line contains word s, the second line contains word t. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output
If the word t is a word s, written reversely, print YES, otherwise print NO.
Examples
Input
code
edoc
Output
YES
Input
abb
aba
Output
NO
Input
code
code
Output
NO | instruction | 0 | 56,692 | 6 | 113,384 |
Tags: implementation, strings
Correct Solution:
```
s=str(input())
b=str(input())
if s==b[::-1]:
print("YES")
elif(s==b):
print("NO")
else:
print("NO")
``` | output | 1 | 56,692 | 6 | 113,385 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the Β«translationΒ». Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if he translated the word correctly.
Input
The first line contains word s, the second line contains word t. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output
If the word t is a word s, written reversely, print YES, otherwise print NO.
Examples
Input
code
edoc
Output
YES
Input
abb
aba
Output
NO
Input
code
code
Output
NO | instruction | 0 | 56,693 | 6 | 113,386 |
Tags: implementation, strings
Correct Solution:
```
Berland = input()
Birland = input()
print("YES" if Berland == Birland[::-1] else "NO")
``` | output | 1 | 56,693 | 6 | 113,387 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the Β«translationΒ». Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if he translated the word correctly.
Input
The first line contains word s, the second line contains word t. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output
If the word t is a word s, written reversely, print YES, otherwise print NO.
Examples
Input
code
edoc
Output
YES
Input
abb
aba
Output
NO
Input
code
code
Output
NO | instruction | 0 | 56,694 | 6 | 113,388 |
Tags: implementation, strings
Correct Solution:
```
s=input()
t=input()
r=t[::-1]
if(r==s):
print('YES')
else:
print('NO')
``` | output | 1 | 56,694 | 6 | 113,389 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the Β«translationΒ». Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if he translated the word correctly.
Input
The first line contains word s, the second line contains word t. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output
If the word t is a word s, written reversely, print YES, otherwise print NO.
Examples
Input
code
edoc
Output
YES
Input
abb
aba
Output
NO
Input
code
code
Output
NO | instruction | 0 | 56,695 | 6 | 113,390 |
Tags: implementation, strings
Correct Solution:
```
s=input()
t=input()
a=t[::-1]
if a==s:
print('YES')
else:
print('NO')
``` | output | 1 | 56,695 | 6 | 113,391 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the Β«translationΒ». Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if he translated the word correctly.
Input
The first line contains word s, the second line contains word t. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output
If the word t is a word s, written reversely, print YES, otherwise print NO.
Examples
Input
code
edoc
Output
YES
Input
abb
aba
Output
NO
Input
code
code
Output
NO | instruction | 0 | 56,696 | 6 | 113,392 |
Tags: implementation, strings
Correct Solution:
```
import math
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())
a = input()
b = input()
a= list(a)
b = list(b)
f = 1
for i in range(len(a)):
if a[i] != b[len(b)-i-1]:
f= 0
break
if f:
print("YES")
else:
print("NO")
``` | output | 1 | 56,696 | 6 | 113,393 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.
You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).
Input
The first and only line consists of a string S ( 1 β€ |S| β€ 5 000 ). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
Output
Print "YES" or "NO", according to the condition.
Examples
Input
aaabccc
Output
YES
Input
bbacc
Output
NO
Input
aabc
Output
YES
Note
Consider first example: the number of 'c' is equal to the number of 'a'.
Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.
Consider third example: the number of 'c' is equal to the number of 'b'. | instruction | 0 | 56,908 | 6 | 113,816 |
Tags: implementation
Correct Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 16 21:09:05 2018
@author: harman
"""
def check_string(st):
i=0
while i!= (len(st)-1):
if (ord(st[i])>ord(st[i+1])):
return('NO')
else:
i += 1
if (((st.count('a')==st.count('c')) or (st.count('b')==st.count('c')))
and (len(st.split('b')) != 1) and (len(st.split('a')) != 1)):
return('YES')
else:
return('NO')
print(check_string(input()))
``` | output | 1 | 56,908 | 6 | 113,817 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.