message
stringlengths 2
23.8k
| message_type
stringclasses 2
values | message_id
int64 0
1
| conversation_id
int64 97
109k
| cluster
float64 0
0
| __index_level_0__
int64 194
217k
|
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input
The first line contains a single string s (1 β€ |s| β€ 103).
The second line contains a single integer k (0 β€ k β€ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Output
Print a single integer β the largest possible value of the resulting string DZY could get.
Examples
Input
abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
41
Note
In the test sample DZY can obtain "abcbbc", value = 1Β·1 + 2Β·2 + 3Β·2 + 4Β·2 + 5Β·2 + 6Β·2 = 41.
Submitted Solution:
```
S = list(map(lambda x: ord(x) - ord('a'), list(input())))
N = int(input())
W = list(map(int, input().split()))
S = S + [W.index(max(W))] * N
print(sum([(i + 1) * W[v] for i, v in enumerate(S)]))
```
|
instruction
| 0
| 102,436
| 0
| 204,872
|
Yes
|
output
| 1
| 102,436
| 0
| 204,873
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input
The first line contains a single string s (1 β€ |s| β€ 103).
The second line contains a single integer k (0 β€ k β€ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Output
Print a single integer β the largest possible value of the resulting string DZY could get.
Examples
Input
abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
41
Note
In the test sample DZY can obtain "abcbbc", value = 1Β·1 + 2Β·2 + 3Β·2 + 4Β·2 + 5Β·2 + 6Β·2 = 41.
Submitted Solution:
```
a=input();b=int(input());z=0;s=0;q=dict();f=97;o=1
for i in map(int,input().split()):q[chr(f)]=i;f+=1
for i in a:s+=(o*q[i]);o+=1;z=max(q.values());print(s+sum(i*z for i in range(o,o+b)))
```
|
instruction
| 0
| 102,437
| 0
| 204,874
|
No
|
output
| 1
| 102,437
| 0
| 204,875
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input
The first line contains a single string s (1 β€ |s| β€ 103).
The second line contains a single integer k (0 β€ k β€ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Output
Print a single integer β the largest possible value of the resulting string DZY could get.
Examples
Input
abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
41
Note
In the test sample DZY can obtain "abcbbc", value = 1Β·1 + 2Β·2 + 3Β·2 + 4Β·2 + 5Β·2 + 6Β·2 = 41.
Submitted Solution:
```
s=input()
k=int(input())
w=input()
#needed values
L=len(s)
sum=0
x=[]
wi=w.split()
for i in range(L):
x.append(wi[ord(s[i])-97])
sum+=int(x[i])*(i+1)
#needed values.
n=int(max(wi))
for i in range(k):
sum+=n*(i+L+1)
print(sum)
```
|
instruction
| 0
| 102,438
| 0
| 204,876
|
No
|
output
| 1
| 102,438
| 0
| 204,877
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input
The first line contains a single string s (1 β€ |s| β€ 103).
The second line contains a single integer k (0 β€ k β€ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Output
Print a single integer β the largest possible value of the resulting string DZY could get.
Examples
Input
abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
41
Note
In the test sample DZY can obtain "abcbbc", value = 1Β·1 + 2Β·2 + 3Β·2 + 4Β·2 + 5Β·2 + 6Β·2 = 41.
Submitted Solution:
```
letters = list(input())
l = len(letters)
k = int(input())
w = [int(x) for x in input().split()]
res = 0
maxW = max(w)
for i in range (l):
res += (i + 1) * w[ord(letters[i]) - ord('a')]
for i in range (k):
res += (k + i + 1) * maxW
print(res)
```
|
instruction
| 0
| 102,439
| 0
| 204,878
|
No
|
output
| 1
| 102,439
| 0
| 204,879
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
<image>
Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
Input
The first line contains a single string s (1 β€ |s| β€ 103).
The second line contains a single integer k (0 β€ k β€ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.
Output
Print a single integer β the largest possible value of the resulting string DZY could get.
Examples
Input
abc
3
1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output
41
Note
In the test sample DZY can obtain "abcbbc", value = 1Β·1 + 2Β·2 + 3Β·2 + 4Β·2 + 5Β·2 + 6Β·2 = 41.
Submitted Solution:
```
s = input()
k = int(input())
vals = list(map(int,input().split()))
alphabets = "abcdefghijklmnopqrstuvwxyz"
ss=alphabets[vals.index(max(vals))]
print(s+ss*k)
```
|
instruction
| 0
| 102,440
| 0
| 204,880
|
No
|
output
| 1
| 102,440
| 0
| 204,881
|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
* "010210" β "100210";
* "010210" β "001210";
* "010210" β "010120";
* "010210" β "010201".
Note than you cannot swap "02" β "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String a is lexicographically less than string b (if strings a and b have the same length) if there exists some position i (1 β€ i β€ |a|, where |s| is the length of the string s) such that for every j < i holds a_j = b_j, and a_i < b_i.
Input
The first line of the input contains the string s consisting only of characters '0', '1' and '2', its length is between 1 and 10^5 (inclusive).
Output
Print a single string β the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Examples
Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
|
instruction
| 0
| 102,885
| 0
| 205,770
|
Tags: greedy, implementation
Correct Solution:
```
a = input()
s = ""
final = ""
count = 0
for i in a:
if i=='1':
count+=1
else:
s+=i
s+='2'
i = s.find('2')
print(s[:i] + '1'*count + s[i:-1])
```
|
output
| 1
| 102,885
| 0
| 205,771
|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
* "010210" β "100210";
* "010210" β "001210";
* "010210" β "010120";
* "010210" β "010201".
Note than you cannot swap "02" β "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String a is lexicographically less than string b (if strings a and b have the same length) if there exists some position i (1 β€ i β€ |a|, where |s| is the length of the string s) such that for every j < i holds a_j = b_j, and a_i < b_i.
Input
The first line of the input contains the string s consisting only of characters '0', '1' and '2', its length is between 1 and 10^5 (inclusive).
Output
Print a single string β the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Examples
Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
|
instruction
| 0
| 102,886
| 0
| 205,772
|
Tags: greedy, implementation
Correct Solution:
```
a = input()
b = ''
i0 = 0
i1 = 0
i2 = 0
tmpi0 = 0
c = []
flag = False
for i in range(len(a)):
if a[i] == '1':
i1 += 1
elif i0 != 0 and a[i] == '2':
b += '0'*i0
i0 = 0
elif i2 != 0 and a[i] == '0':
b += '2'*i2
i2 = 0
if a[i] == '2':
i2 +=1
if a[i] == '0':
i0 += 1
b += '0'*i0 +'2'*i2
flag = True
for i in range(len(b)):
if flag and b[i] == '2':
flag = False
print('1'*i1+'2', end='')
i1 = 0
else:
print(b[i], end='')
print('1'*i1, end='')
```
|
output
| 1
| 102,886
| 0
| 205,773
|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
* "010210" β "100210";
* "010210" β "001210";
* "010210" β "010120";
* "010210" β "010201".
Note than you cannot swap "02" β "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String a is lexicographically less than string b (if strings a and b have the same length) if there exists some position i (1 β€ i β€ |a|, where |s| is the length of the string s) such that for every j < i holds a_j = b_j, and a_i < b_i.
Input
The first line of the input contains the string s consisting only of characters '0', '1' and '2', its length is between 1 and 10^5 (inclusive).
Output
Print a single string β the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Examples
Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
|
instruction
| 0
| 102,887
| 0
| 205,774
|
Tags: greedy, implementation
Correct Solution:
```
s=input()
one=s.count("1")
if one==0:print(s);exit()
ind=s.find("2")
ans=""
for i in range(len(s)):
if i==ind:ans+="1"*one
if s[i]=="1":continue
ans+=s[i]
if ind==-1:ans+="1"*one
print(ans)
```
|
output
| 1
| 102,887
| 0
| 205,775
|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
* "010210" β "100210";
* "010210" β "001210";
* "010210" β "010120";
* "010210" β "010201".
Note than you cannot swap "02" β "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String a is lexicographically less than string b (if strings a and b have the same length) if there exists some position i (1 β€ i β€ |a|, where |s| is the length of the string s) such that for every j < i holds a_j = b_j, and a_i < b_i.
Input
The first line of the input contains the string s consisting only of characters '0', '1' and '2', its length is between 1 and 10^5 (inclusive).
Output
Print a single string β the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Examples
Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
|
instruction
| 0
| 102,888
| 0
| 205,776
|
Tags: greedy, implementation
Correct Solution:
```
s=input()
l=len(s)
i=0
while(i<l and s[i]!='2'):
i+=1
a=sorted(s[0:i])
fir=[]
sec=[]
while(i<l):
if(s[i]=='1'):
fir+=[s[i]]
else:
sec+=[s[i]]
i+=1
r=a+fir+sec
print(''.join(r))
```
|
output
| 1
| 102,888
| 0
| 205,777
|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
* "010210" β "100210";
* "010210" β "001210";
* "010210" β "010120";
* "010210" β "010201".
Note than you cannot swap "02" β "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String a is lexicographically less than string b (if strings a and b have the same length) if there exists some position i (1 β€ i β€ |a|, where |s| is the length of the string s) such that for every j < i holds a_j = b_j, and a_i < b_i.
Input
The first line of the input contains the string s consisting only of characters '0', '1' and '2', its length is between 1 and 10^5 (inclusive).
Output
Print a single string β the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Examples
Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
|
instruction
| 0
| 102,889
| 0
| 205,778
|
Tags: greedy, implementation
Correct Solution:
```
def scanf(obj=list, type=int):
return obj(map(type, input().split()))
s = input()[-1::-1]
ans = ''
z = on = 0
for i in range(len(s)):
if s[i] == '0': z += 1
if s[i] == '1': on += 1
if s[i] == '2':
ans += '0' * z + '2'
z = 0
ans += '1' * on + '0' * z
print(ans[-1::-1])
```
|
output
| 1
| 102,889
| 0
| 205,779
|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
* "010210" β "100210";
* "010210" β "001210";
* "010210" β "010120";
* "010210" β "010201".
Note than you cannot swap "02" β "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String a is lexicographically less than string b (if strings a and b have the same length) if there exists some position i (1 β€ i β€ |a|, where |s| is the length of the string s) such that for every j < i holds a_j = b_j, and a_i < b_i.
Input
The first line of the input contains the string s consisting only of characters '0', '1' and '2', its length is between 1 and 10^5 (inclusive).
Output
Print a single string β the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Examples
Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
|
instruction
| 0
| 102,890
| 0
| 205,780
|
Tags: greedy, implementation
Correct Solution:
```
s=list(input())
s.append('2')
l=[]
c=s.count('1')
f=0
for i in range(len(s)):
if s[i]=='2' and f==0:
for j in range(c):
l.append('1')
f=1
l.append('2')
elif s[i]!='1':
l.append(s[i])
l=l[:len(s)-1]
print(''.join(l))
```
|
output
| 1
| 102,890
| 0
| 205,781
|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
* "010210" β "100210";
* "010210" β "001210";
* "010210" β "010120";
* "010210" β "010201".
Note than you cannot swap "02" β "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String a is lexicographically less than string b (if strings a and b have the same length) if there exists some position i (1 β€ i β€ |a|, where |s| is the length of the string s) such that for every j < i holds a_j = b_j, and a_i < b_i.
Input
The first line of the input contains the string s consisting only of characters '0', '1' and '2', its length is between 1 and 10^5 (inclusive).
Output
Print a single string β the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Examples
Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
|
instruction
| 0
| 102,891
| 0
| 205,782
|
Tags: greedy, implementation
Correct Solution:
```
s = list(input())
for i in range(len(s)):
s[i] = int(s[i])
n = len(s)
ans = [i for i in s if i == 0 or i == 2]
c1 = sum([1 for i in s if i == 1])
f2 = n
for i in range(len(ans)):
if ans[i] == 2:
f2 = i
break
ans1 = ans[:f2] +[1 for i in range(c1)] + ans[f2:]
print(''.join([str(i) for i in ans1]))
```
|
output
| 1
| 102,891
| 0
| 205,783
|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
* "010210" β "100210";
* "010210" β "001210";
* "010210" β "010120";
* "010210" β "010201".
Note than you cannot swap "02" β "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String a is lexicographically less than string b (if strings a and b have the same length) if there exists some position i (1 β€ i β€ |a|, where |s| is the length of the string s) such that for every j < i holds a_j = b_j, and a_i < b_i.
Input
The first line of the input contains the string s consisting only of characters '0', '1' and '2', its length is between 1 and 10^5 (inclusive).
Output
Print a single string β the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Examples
Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
|
instruction
| 0
| 102,892
| 0
| 205,784
|
Tags: greedy, implementation
Correct Solution:
```
s = input()
s = s + "2"
t = s.replace("1", '')
i = t.find("2")
print(t[:i] + "1"*s.count("1")+t[i:-1])
```
|
output
| 1
| 102,892
| 0
| 205,785
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
* "010210" β "100210";
* "010210" β "001210";
* "010210" β "010120";
* "010210" β "010201".
Note than you cannot swap "02" β "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String a is lexicographically less than string b (if strings a and b have the same length) if there exists some position i (1 β€ i β€ |a|, where |s| is the length of the string s) such that for every j < i holds a_j = b_j, and a_i < b_i.
Input
The first line of the input contains the string s consisting only of characters '0', '1' and '2', its length is between 1 and 10^5 (inclusive).
Output
Print a single string β the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Examples
Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
Submitted Solution:
```
s = input("")
num = 0
flag = False
for numero in s:
if numero == '1':
num += 1
if ('2' not in s or '0' not in s):
s = ''.join(sorted(s));
print(s)
quit()
for elemento in s:
if elemento == '0':
print('0', end='')
elif elemento == '2' and not flag == True:
for i in range(num):
print('1', end='')
flag = True
print('2', end='')
else:
if elemento == '1':
continue
if elemento == '2':
print('2', end='')
print("")
```
|
instruction
| 0
| 102,893
| 0
| 205,786
|
Yes
|
output
| 1
| 102,893
| 0
| 205,787
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
* "010210" β "100210";
* "010210" β "001210";
* "010210" β "010120";
* "010210" β "010201".
Note than you cannot swap "02" β "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String a is lexicographically less than string b (if strings a and b have the same length) if there exists some position i (1 β€ i β€ |a|, where |s| is the length of the string s) such that for every j < i holds a_j = b_j, and a_i < b_i.
Input
The first line of the input contains the string s consisting only of characters '0', '1' and '2', its length is between 1 and 10^5 (inclusive).
Output
Print a single string β the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Examples
Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
Submitted Solution:
```
from sys import stdin
from collections import deque
mod = 10**9 + 7
# def rl():
# return [int(w) for w in stdin.readline().split()]
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt,factorial,gcd,log2,inf,ceil
# map(int,input().split())
# # l = list(map(int,input().split()))
# from itertools import permutations
import heapq
# la = []
s = input()
n = len(s)
s+='2'
z = s.count('1')
ans = []
flag = 0
for i in range(len(s)):
if s[i] == '2' and flag == 0:
for j in range(z):
ans.append('1')
flag = 1
ans.append('2')
else:
if s[i]!='1':
ans.append(s[i])
ans = ans[:n]
print(''.join(ans))
```
|
instruction
| 0
| 102,894
| 0
| 205,788
|
Yes
|
output
| 1
| 102,894
| 0
| 205,789
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
* "010210" β "100210";
* "010210" β "001210";
* "010210" β "010120";
* "010210" β "010201".
Note than you cannot swap "02" β "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String a is lexicographically less than string b (if strings a and b have the same length) if there exists some position i (1 β€ i β€ |a|, where |s| is the length of the string s) such that for every j < i holds a_j = b_j, and a_i < b_i.
Input
The first line of the input contains the string s consisting only of characters '0', '1' and '2', its length is between 1 and 10^5 (inclusive).
Output
Print a single string β the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Examples
Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
Submitted Solution:
```
#J - Minimum Ternary String
def writeRestOfString(TS, result, indexOfFirstTwo):
size = len(TS)
for num in TS[indexOfFirstTwo:size]:
result += str(num)
return result
def removeAllOnesAfterFirstTwo(TS, indexOfFirstTwo):
i = indexOfFirstTwo
size = len(TS)
beginOfTS = TS[0:indexOfFirstTwo]
restOfTS = ""
while i < size:
if TS[i] != '1': restOfTS += str(TS[i])
i += 1
return beginOfTS + restOfTS
def countZerosAndOnes(TS, limit):
i = 0
zeros = 0
ones = 0
while i < limit:
if TS[i] == 1: ones += 1
else: zeros += 1
i += 1
return (zeros, ones)
def countOnes(TS, limit):
i = 0
ones = 0
while i < limit:
if TS[i] == 1: ones += 1
i += 1
return ones
def countZeros(TS, limit):
i = 0
zeros = 0
while i< limit:
if TS[i] == 0: zeros += 1
i += 1
return zeros
def writeZeros(result, zeros):
i = 1
while i <= zeros:
result += str(0)
i += 1
return result
def writeOnes(result, ones):
i = 1
while i <= ones:
result += str(1)
i += 1
return result
def checkForFirstTwo(TS):
i = 0
size = len(TS)
while(i < size):
if TS[i] == 2 or TS[i] == '2': return i
i += 1
return None
def changeStringWithOnlyOnesAndZeros(TS):
size = len(TS)
result = ""
(zeros, ones) = countZerosAndOnes(TS, size)
result = writeZeros(result,zeros)
result = writeOnes(result,ones)
return result
def changeString(TS, indexOfFirstTwo):
result = ""
size = len(TS)
zeros = countZeros(TS, indexOfFirstTwo)
ones = countOnes(TS, size)
result = writeZeros(result,zeros)
result = writeOnes(result,ones)
result = writeRestOfString(TS,result,indexOfFirstTwo)
indexOfFirstTwo = checkForFirstTwo(result)
result = removeAllOnesAfterFirstTwo(result, indexOfFirstTwo)
return result
def splitString(string):
characters = []
size = len(string)
i = 0
while(i < size):
characters.append(int(string[i]))
i += 1
return characters
ternaryString = input()
#print(ternaryString)
TSArray = splitString(ternaryString)
indexOfFirstTwo = checkForFirstTwo(TSArray)
if indexOfFirstTwo != None:
print(changeString(TSArray, indexOfFirstTwo))
else:
print(changeStringWithOnlyOnesAndZeros(TSArray))
```
|
instruction
| 0
| 102,895
| 0
| 205,790
|
Yes
|
output
| 1
| 102,895
| 0
| 205,791
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
* "010210" β "100210";
* "010210" β "001210";
* "010210" β "010120";
* "010210" β "010201".
Note than you cannot swap "02" β "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String a is lexicographically less than string b (if strings a and b have the same length) if there exists some position i (1 β€ i β€ |a|, where |s| is the length of the string s) such that for every j < i holds a_j = b_j, and a_i < b_i.
Input
The first line of the input contains the string s consisting only of characters '0', '1' and '2', its length is between 1 and 10^5 (inclusive).
Output
Print a single string β the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Examples
Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
Submitted Solution:
```
n=list(map(str,list(input())))
a=''
b=''
for i in n:
if i=='1':
a+='1'
else:
b+=i
n=b.find('2')
if n==-1:
print(b+a)
else:
print(b[:n]+a+b[n:])
```
|
instruction
| 0
| 102,896
| 0
| 205,792
|
Yes
|
output
| 1
| 102,896
| 0
| 205,793
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
* "010210" β "100210";
* "010210" β "001210";
* "010210" β "010120";
* "010210" β "010201".
Note than you cannot swap "02" β "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String a is lexicographically less than string b (if strings a and b have the same length) if there exists some position i (1 β€ i β€ |a|, where |s| is the length of the string s) such that for every j < i holds a_j = b_j, and a_i < b_i.
Input
The first line of the input contains the string s consisting only of characters '0', '1' and '2', its length is between 1 and 10^5 (inclusive).
Output
Print a single string β the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Examples
Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
Submitted Solution:
```
N = list(input())
N = [int(i) for i in N]
n = len(N)
for i in range(n-1,-1,-1):
if N[i]==2:
ones=0
j = i+1
while j<n and N[j]!=2:
if(N[j]==1):
ones+=1
j+=1
for aux in range(i,j):
if aux-i<ones:
N[aux]=1
else:
if aux == ones+i:
N[aux]=2
else:
N[aux]=0
print(N)
ones=0
for i in range(n):
if N[i]==2 or i == n-1:
for j in range(i-1,-1,-1):
if ones>0:
N[j]=1
ones-=1
else:
N[j]=0
break;
else:
if(N[i]==1):
ones+=1
N = [str(i) for i in N]
print(''.join(N))
```
|
instruction
| 0
| 102,897
| 0
| 205,794
|
No
|
output
| 1
| 102,897
| 0
| 205,795
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
* "010210" β "100210";
* "010210" β "001210";
* "010210" β "010120";
* "010210" β "010201".
Note than you cannot swap "02" β "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String a is lexicographically less than string b (if strings a and b have the same length) if there exists some position i (1 β€ i β€ |a|, where |s| is the length of the string s) such that for every j < i holds a_j = b_j, and a_i < b_i.
Input
The first line of the input contains the string s consisting only of characters '0', '1' and '2', its length is between 1 and 10^5 (inclusive).
Output
Print a single string β the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Examples
Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
Submitted Solution:
```
if __name__ == '__main__':
s=input()
len1=s.count('1')
index2=s.find('2')
temp=s[:index2]
zero=temp.count('0')
result='0'*zero+'1'*len1+s[index2:].replace('1','')
print(result)
```
|
instruction
| 0
| 102,898
| 0
| 205,796
|
No
|
output
| 1
| 102,898
| 0
| 205,797
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
* "010210" β "100210";
* "010210" β "001210";
* "010210" β "010120";
* "010210" β "010201".
Note than you cannot swap "02" β "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String a is lexicographically less than string b (if strings a and b have the same length) if there exists some position i (1 β€ i β€ |a|, where |s| is the length of the string s) such that for every j < i holds a_j = b_j, and a_i < b_i.
Input
The first line of the input contains the string s consisting only of characters '0', '1' and '2', its length is between 1 and 10^5 (inclusive).
Output
Print a single string β the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Examples
Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
Submitted Solution:
```
s = list(map(int, list(input())))
c = [0, 0, 0]
ans = list()
f = True
for el in s:
if el == 0 and c[2] > 0:
ans.append('0' * c[0])
if f:
ans.append('1' * s.count(1))
f = False
ans.append('2' * c[2])
c = [0, 0, 0]
if el != 1:
c[el] += 1
ans.append('0' * c[0])
ans.append('2' * c[2])
if f:
ans.insert(0, '1' * s.count(1))
f = False
print(''.join(ans))
```
|
instruction
| 0
| 102,899
| 0
| 205,798
|
No
|
output
| 1
| 102,899
| 0
| 205,799
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For example, for string "010210" we can perform the following moves:
* "010210" β "100210";
* "010210" β "001210";
* "010210" β "010120";
* "010210" β "010201".
Note than you cannot swap "02" β "20" and vice versa. You cannot perform any other operations with the given string excluding described above.
You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).
String a is lexicographically less than string b (if strings a and b have the same length) if there exists some position i (1 β€ i β€ |a|, where |s| is the length of the string s) such that for every j < i holds a_j = b_j, and a_i < b_i.
Input
The first line of the input contains the string s consisting only of characters '0', '1' and '2', its length is between 1 and 10^5 (inclusive).
Output
Print a single string β the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).
Examples
Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
Submitted Solution:
```
s = list(map(int, list(input())))
c = [0, 0, 0]
ans = list()
f = True
for el in s:
if el == 0 and c[2] > 0:
ans.append('0' * c[0])
if f:
ans.append('1' * s.count(1))
f = False
ans.append('2' * c[2])
c = [0, 0, 0]
if el != 1:
c[el] += 1
ans.append('0' * c[0])
ans.append('2' * c[2])
if f:
if 0 not in s:
ans.insert(0, '1' * s.count(1))
if 2 not in s:
ans.insert(-1, '1' * s.count(1))
f = False
print(''.join(ans))
```
|
instruction
| 0
| 102,900
| 0
| 205,800
|
No
|
output
| 1
| 102,900
| 0
| 205,801
|
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the length of the string.
You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.
If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).
Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Input
The first line of the input contains one string s consisting of at least 1 and at most 200 lowercase Latin letters.
The second line of the input contains one string t consisting of at least 1 and at most 200 lowercase Latin letters.
It is guaranteed that t is a subsequence of s.
Output
Print one integer β the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Examples
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
instruction
| 0
| 102,978
| 0
| 205,956
|
Tags: greedy, implementation
Correct Solution:
```
def subseq(s, t):
lenS = len(s)
lenT = len(t)
i = 0
j = 0
while i < lenS and j < lenT:
if s[i] == t[j]:
j += 1
i += 1
return lenT == j
s = input()
t = input()
lenS = len(s)
result = 0
for l in range(lenS):
for r in range(lenS):
s_without_sub = s[0:l]+s[r+1:]
if subseq(s_without_sub, t):
result = max(result, r - l + 1)
print(result)
```
|
output
| 1
| 102,978
| 0
| 205,957
|
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the length of the string.
You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.
If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).
Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Input
The first line of the input contains one string s consisting of at least 1 and at most 200 lowercase Latin letters.
The second line of the input contains one string t consisting of at least 1 and at most 200 lowercase Latin letters.
It is guaranteed that t is a subsequence of s.
Output
Print one integer β the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Examples
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
instruction
| 0
| 102,979
| 0
| 205,958
|
Tags: greedy, implementation
Correct Solution:
```
def find_sub(s, t):
k=0
for i in s:
if k==len(t):
break
if i==t[k]:
k=k+1
if k==len(t):
return True
else:
return False
def process(s, t):
res=0
for l in range(1, len(s)):
for i in range(len(s)-l+1):
j=i+l-1
if find_sub(''.join([s[k] for k in range(len(s)) if k<i or k > j ]), t):
res=max(res, l)
return res
s=input()
t=input()
print(process(s,t))
```
|
output
| 1
| 102,979
| 0
| 205,959
|
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the length of the string.
You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.
If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).
Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Input
The first line of the input contains one string s consisting of at least 1 and at most 200 lowercase Latin letters.
The second line of the input contains one string t consisting of at least 1 and at most 200 lowercase Latin letters.
It is guaranteed that t is a subsequence of s.
Output
Print one integer β the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Examples
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
instruction
| 0
| 102,980
| 0
| 205,960
|
Tags: greedy, implementation
Correct Solution:
```
s = input()
t = input()
n = len(t)
first = [0] * n
last = [0] * n
p = 0
i = 0
while(p<n):
if(s[i] == t[p]):
first[p] = i
p+=1
i+=1
p = n-1
i = len(s)-1
while(p>=0):
if(s[i] == t[p]):
last[p] = i
p-=1
i-=1
# print(first)
# print(last)
ans = max(last[0],len(s) - 1 -first[-1])
for i in range(n-1):
ans = max(ans,last[i+1] - first[i] - 1)
print(ans)
```
|
output
| 1
| 102,980
| 0
| 205,961
|
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the length of the string.
You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.
If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).
Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Input
The first line of the input contains one string s consisting of at least 1 and at most 200 lowercase Latin letters.
The second line of the input contains one string t consisting of at least 1 and at most 200 lowercase Latin letters.
It is guaranteed that t is a subsequence of s.
Output
Print one integer β the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Examples
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
instruction
| 0
| 102,981
| 0
| 205,962
|
Tags: greedy, implementation
Correct Solution:
```
import sys
from collections import defaultdict
def get_after(l,num):
low,high=0,len(l)-1
ans=len(l)
while low<=high:
mid=(low+high)//2
if l[mid]>num:
ans=min(ans,mid)
high=mid-1
else:
low=mid+1
return l[ans]
def get_before(l,num):
low,high=0,len(l)-1
ans=0
while low<=high:
mid=(low+high)//2
if l[mid]<num:
ans=max(ans,mid)
low=mid+1
else:
high=mid-1
return l[ans]
dic=defaultdict(list)
s=sys.stdin.readline()[:-1]
#s=input()
#print(s[200],'yeeees')
#print(s,'s')
t=sys.stdin.readline()[:-1]
#print(t,'t')
n=len(s)
for i in range(n):
dic[s[i]].append(i)
'''for i in sorted(dic):
print(i,'i', dic[i])'''
#print(dic,'dic')
n=len(t)
l=[0 for _ in range(n+2)]
l[0]=-1
l[-1]=len(s)
#print(len(s),'len(s)')
for i in range(n-1,-1,-1):
y=dic[t[i]][-1]
if y<l[i+2]:
l[i+1]=y
else:
y=get_before(dic[t[i]],l[i+2])
l[i+1]=y
last=l[i+1]
#print(l,'l')
ans=l[1]-l[0]-1
#print('------')
for i in range(n):
#print(l,'in for loop after',i,'i')
#print('-----')
y=dic[t[i]][0]
if y>l[i]:
l[i+1]=y
else:
y=get_after(dic[t[i]],l[i])
l[i+1]=y
ans=max(ans,l[i+2]-l[i+1]-1)
#print(l,'after')
ans=max(ans,l[-1]-l[-2]-1)
print(ans)
```
|
output
| 1
| 102,981
| 0
| 205,963
|
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the length of the string.
You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.
If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).
Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Input
The first line of the input contains one string s consisting of at least 1 and at most 200 lowercase Latin letters.
The second line of the input contains one string t consisting of at least 1 and at most 200 lowercase Latin letters.
It is guaranteed that t is a subsequence of s.
Output
Print one integer β the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Examples
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
instruction
| 0
| 102,982
| 0
| 205,964
|
Tags: greedy, implementation
Correct Solution:
```
big=input()
small=input()
ans=0
for i in range(0,len(big)):
for j in range(i,len(big)):
pos=0
for k in range(0,len(big)):
if k>=i and k<=j:
continue
if big[k]==small[pos]:
pos+=1
if pos==len(small):
ans=max(ans,j-i+1)
break
print(ans)
```
|
output
| 1
| 102,982
| 0
| 205,965
|
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the length of the string.
You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.
If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).
Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Input
The first line of the input contains one string s consisting of at least 1 and at most 200 lowercase Latin letters.
The second line of the input contains one string t consisting of at least 1 and at most 200 lowercase Latin letters.
It is guaranteed that t is a subsequence of s.
Output
Print one integer β the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Examples
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
instruction
| 0
| 102,983
| 0
| 205,966
|
Tags: greedy, implementation
Correct Solution:
```
s=str(input())
t=str(input())
def lka(i):
if i==0:return(0)
for j in range(len(s)-i+1):
if kayna(s[:j]+s[j+i:]):
return(i)
return(lka(i-1))
def kayna(s):
i=0
j=0
while i<len(t) and j<len(s):
if s[j]==t[i]:
i+=1
j+=1
else: j+=1
if i==len(t):return(True)
return(False)
print(lka(len(s)-len(t)))
```
|
output
| 1
| 102,983
| 0
| 205,967
|
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the length of the string.
You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.
If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).
Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Input
The first line of the input contains one string s consisting of at least 1 and at most 200 lowercase Latin letters.
The second line of the input contains one string t consisting of at least 1 and at most 200 lowercase Latin letters.
It is guaranteed that t is a subsequence of s.
Output
Print one integer β the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Examples
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
instruction
| 0
| 102,984
| 0
| 205,968
|
Tags: greedy, implementation
Correct Solution:
```
def check(s, t):
i = 0
j = 0
while i < len(s) and j < len(t):
if (s[i] == t[j]):
j += 1
i += 1
return j == len(t)
s = input()
t = input()
ans = 0
for i in range(len(s) + 1):
for j in range(i, len(s) + 1):
if (check(s[:i] + s[j:], t)):
ans = max(ans, j - i)
print(ans)
#JSR
```
|
output
| 1
| 102,984
| 0
| 205,969
|
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the length of the string.
You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.
If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).
Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Input
The first line of the input contains one string s consisting of at least 1 and at most 200 lowercase Latin letters.
The second line of the input contains one string t consisting of at least 1 and at most 200 lowercase Latin letters.
It is guaranteed that t is a subsequence of s.
Output
Print one integer β the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Examples
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
|
instruction
| 0
| 102,985
| 0
| 205,970
|
Tags: greedy, implementation
Correct Solution:
```
from sys import stdin
input = stdin.readline
s = input()
t = input()
n = len(t)
low = [0 for i in range(len(t))]
high = [0 for i in range(len(t))]
acc = 0
for i in range(n):
acc_t = t[i]
while acc_t != s[acc]: acc += 1
low[i] = acc
acc += 1
acc = len(s)-1
for i in range(len(t)):
acc_t = t[n-i-1]
while acc_t != s[acc]: acc -= 1
high[n-i-1] = acc
acc -= 1
res = max(high[0], len(s)-low[n-1]-1)
for i in range(n-1):
res = max(res, high[i+1]-low[i]-1)
print(res)
```
|
output
| 1
| 102,985
| 0
| 205,971
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the length of the string.
You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.
If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).
Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Input
The first line of the input contains one string s consisting of at least 1 and at most 200 lowercase Latin letters.
The second line of the input contains one string t consisting of at least 1 and at most 200 lowercase Latin letters.
It is guaranteed that t is a subsequence of s.
Output
Print one integer β the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Examples
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
Submitted Solution:
```
def f(s1, s2):
find_num = 0
find = s2[0]
i = 0
while find_num < len(s2):
while i < len(s1) and s1[i] != find:
i += 1
if i == len(s1):
return False
find_num += 1
if find_num != len(s2):
find = s2[find_num]
i += 1
return True
s1 = input()
s2 = input()
flag = False
for length in range(len(s1) - len(s2), -1, -1):
if flag:
break
for i in range(len(s1) - length + 1):
s3 = s1[:i] + s1[i + length:]
#print(s3, s2)
if f(s3, s2):
print(length)
flag = True
break
```
|
instruction
| 0
| 102,986
| 0
| 205,972
|
Yes
|
output
| 1
| 102,986
| 0
| 205,973
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the length of the string.
You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.
If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).
Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Input
The first line of the input contains one string s consisting of at least 1 and at most 200 lowercase Latin letters.
The second line of the input contains one string t consisting of at least 1 and at most 200 lowercase Latin letters.
It is guaranteed that t is a subsequence of s.
Output
Print one integer β the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Examples
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush
def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
def ctd(chr): return ord(chr)-ord("a")
mod = 998244353
INF = float('inf')
# ------------------------------
def main():
s = input()
t = input()
def c(num):
b = 0
prec = []
srec = []
for i in range(len(s)):
if s[i]==t[b]:
prec.append(i)
b+=1
if b==len(t): break
e = len(t)-1
for i in range(len(s)-1, -1, -1):
if s[i]==t[e]:
srec.append(i)
e-=1
if e==-1: break
srec = srec[::-1]
if srec[0]>=num or len(s)-prec[-1]-1>=num:
return True
for i in range(len(prec)-1):
if srec[i+1]-prec[i]-1>=num:
return True
return False
l, r = 0, len(s)-len(t)
while l<r:
m = (l+r+1)//2
ret = c(m)
if ret:
l = m
else:
r = m-1
print(l)
if __name__ == "__main__":
main()
```
|
instruction
| 0
| 102,987
| 0
| 205,974
|
Yes
|
output
| 1
| 102,987
| 0
| 205,975
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the length of the string.
You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.
If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).
Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Input
The first line of the input contains one string s consisting of at least 1 and at most 200 lowercase Latin letters.
The second line of the input contains one string t consisting of at least 1 and at most 200 lowercase Latin letters.
It is guaranteed that t is a subsequence of s.
Output
Print one integer β the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Examples
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
Submitted Solution:
```
s = input()
t = input()
ans = 0
for i in range(len(s)):
for j in range(i,len(s)+1):
tmp = s[:i]+s[j:]
# we need to check if we can get t from tmp
pos = 0
for e in tmp:
if e == t[pos]:
pos+=1
if pos == len(t):
ans = max(ans,j-i)
break
print(ans)
```
|
instruction
| 0
| 102,988
| 0
| 205,976
|
Yes
|
output
| 1
| 102,988
| 0
| 205,977
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the length of the string.
You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.
If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).
Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Input
The first line of the input contains one string s consisting of at least 1 and at most 200 lowercase Latin letters.
The second line of the input contains one string t consisting of at least 1 and at most 200 lowercase Latin letters.
It is guaranteed that t is a subsequence of s.
Output
Print one integer β the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Examples
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
Submitted Solution:
```
s=input()
t=input()
post=[len(t)]*len(s)
pre=[-1]*len(s)
def bins(val,low,high):
if(low>high):
return -1
global post,pre
mid=(low+high)//2
if val>=post[mid]:
return max(mid,bins(val,mid+1,high))
else:
return bins(val,low,mid-1)
j=-1
for i in range(len(s)):
if(j!=len(t)-1 and s[i]==t[j+1]):
j+=1
pre[i]=j
# print(pre)
j=len(t)
for i in range(len(s)-1,-1,-1):
if(j!=0 and s[i]==t[j-1]):
j-=1
post[i]=j
ans = 0
for l in range(-1,len(s)):
val=pre[l]
if l==-1:
val=-1
if val==len(t)-1:
ans=max(ans,len(s)-l-1)
continue
r=bins(val+1,l+1,len(s)-1)
if(r!=-1):
ans=max(ans,r-l-1)
print(ans)
```
|
instruction
| 0
| 102,989
| 0
| 205,978
|
Yes
|
output
| 1
| 102,989
| 0
| 205,979
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the length of the string.
You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.
If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).
Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Input
The first line of the input contains one string s consisting of at least 1 and at most 200 lowercase Latin letters.
The second line of the input contains one string t consisting of at least 1 and at most 200 lowercase Latin letters.
It is guaranteed that t is a subsequence of s.
Output
Print one integer β the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Examples
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
Submitted Solution:
```
from collections import deque
s = input()
t = input()
t = deque(t)
ans = 0;
checker = deque();
for i in range(len(t)-1):
checker.append(s[i])
for i in range(len(t)-1, len(s)):
checker.append(s[i])
if checker == t:
ans = max(ans, len(s)-1-i, i-len(t)+1)
else:
checker.popleft()
print(ans)
```
|
instruction
| 0
| 102,990
| 0
| 205,980
|
No
|
output
| 1
| 102,990
| 0
| 205,981
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the length of the string.
You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.
If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).
Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Input
The first line of the input contains one string s consisting of at least 1 and at most 200 lowercase Latin letters.
The second line of the input contains one string t consisting of at least 1 and at most 200 lowercase Latin letters.
It is guaranteed that t is a subsequence of s.
Output
Print one integer β the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Examples
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
Submitted Solution:
```
from sys import stdin,stdout
s=stdin.readline().strip()
t=stdin.readline().strip()
leftmost=[-1]
ptr1=ptr2=0
while ptr2<len(t):
if s[ptr1]==t[ptr2]:
leftmost.append(ptr1)
ptr1+=1;ptr2+=1
else:
ptr1+=1
rightmost=[]
ptr1=len(s)-1
ptr2=len(t)-1
while ptr2>=0:
if s[ptr1]==t[ptr2]:
rightmost.append(ptr1)
ptr1-=1;ptr2-=1
else:
ptr1-=1
rightmost.reverse();rightmost.append(len(s))
ans=-1
for i in range(len(leftmost)-1):
ans=max(ans,leftmost[i]+rightmost[i+1]-1)
stdout.write(str(ans)+"\n")
#print(leftmost)
#print(rightmost)
```
|
instruction
| 0
| 102,991
| 0
| 205,982
|
No
|
output
| 1
| 102,991
| 0
| 205,983
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the length of the string.
You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.
If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).
Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Input
The first line of the input contains one string s consisting of at least 1 and at most 200 lowercase Latin letters.
The second line of the input contains one string t consisting of at least 1 and at most 200 lowercase Latin letters.
It is guaranteed that t is a subsequence of s.
Output
Print one integer β the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Examples
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
Submitted Solution:
```
s=input()
t=input()
l=len(s)
pos=s.find(t)
print(max(pos,l-(pos+len(t))))
```
|
instruction
| 0
| 102,992
| 0
| 205,984
|
No
|
output
| 1
| 102,992
| 0
| 205,985
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the length of the string.
You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).
For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".
You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.
If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).
Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Input
The first line of the input contains one string s consisting of at least 1 and at most 200 lowercase Latin letters.
The second line of the input contains one string t consisting of at least 1 and at most 200 lowercase Latin letters.
It is guaranteed that t is a subsequence of s.
Output
Print one integer β the maximum possible length of the substring you can remove so that t is still a subsequence of s.
Examples
Input
bbaba
bb
Output
3
Input
baaba
ab
Output
2
Input
abcde
abcde
Output
0
Input
asdfasdf
fasd
Output
3
Submitted Solution:
```
def process(a,b):
left=len(a)-len(b)-a.find(b)
# print(a.find(b))
right=len(a)-len(b)-a[::-1].find(b[::-1])
# print(a[::-1].find(b[::-1]))
return max(left,right)
a=input()
b=input()
print(process(a,b))
```
|
instruction
| 0
| 102,993
| 0
| 205,986
|
No
|
output
| 1
| 102,993
| 0
| 205,987
|
Provide tags and a correct Python 3 solution for this coding contest problem.
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.
Ahcl wants to construct a beautiful string. He has a string s, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!
More formally, after replacing all characters '?', the condition s_i β s_{i+1} should be satisfied for all 1 β€ i β€ |s| - 1, where |s| is the length of the string s.
Input
The first line contains positive integer t (1 β€ t β€ 1000) β the number of test cases. Next t lines contain the descriptions of test cases.
Each line contains a non-empty string s consisting of only characters 'a', 'b', 'c' and '?'.
It is guaranteed that in each test case a string s has at least one character '?'. The sum of lengths of strings s in all test cases does not exceed 10^5.
Output
For each test case given in the input print the answer in the following format:
* If it is impossible to create a beautiful string, print "-1" (without quotes);
* Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.
Example
Input
3
a???cb
a??bbc
a?b?c
Output
ababcb
-1
acbac
Note
In the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.
In the second test case, it is impossible to create a beautiful string, because the 4-th and 5-th characters will be always equal.
In the third test case, the only answer is "acbac".
|
instruction
| 0
| 103,026
| 0
| 206,052
|
Tags: constructive algorithms, greedy
Correct Solution:
```
d = {'a', 'b', 'c'}
for _ in range(int(input())):
s = input()
if s.find('aa') != -1 or s.find('bb') != -1 or s.find('cc') != -1:
print(-1)
elif s == '?':
print('a')
else:
s = list(s)
if s[0] == '?':
if s[1] in d:
for c in d:
if c != s[1]:
s[0] = c
break
else:
s[0] = 'a'
if s[-1] == '?':
if s[-2] in d:
for c in d:
if c != s[-2]:
s[-1] = c
break
else:
s[-1] = 'a'
for i in range(1, len(s) - 1):
if s[i] == '?':
if s[i + 1] == '?':
for c in d:
if c != s[i - 1]:
s[i] = c
else:
s[i] = (d ^ set([s[i - 1], s[i + 1]])).pop()
print(''.join(s))
```
|
output
| 1
| 103,026
| 0
| 206,053
|
Provide tags and a correct Python 3 solution for this coding contest problem.
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.
Ahcl wants to construct a beautiful string. He has a string s, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!
More formally, after replacing all characters '?', the condition s_i β s_{i+1} should be satisfied for all 1 β€ i β€ |s| - 1, where |s| is the length of the string s.
Input
The first line contains positive integer t (1 β€ t β€ 1000) β the number of test cases. Next t lines contain the descriptions of test cases.
Each line contains a non-empty string s consisting of only characters 'a', 'b', 'c' and '?'.
It is guaranteed that in each test case a string s has at least one character '?'. The sum of lengths of strings s in all test cases does not exceed 10^5.
Output
For each test case given in the input print the answer in the following format:
* If it is impossible to create a beautiful string, print "-1" (without quotes);
* Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.
Example
Input
3
a???cb
a??bbc
a?b?c
Output
ababcb
-1
acbac
Note
In the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.
In the second test case, it is impossible to create a beautiful string, because the 4-th and 5-th characters will be always equal.
In the third test case, the only answer is "acbac".
|
instruction
| 0
| 103,027
| 0
| 206,054
|
Tags: constructive algorithms, greedy
Correct Solution:
```
import sys
import collections
from collections import Counter
import itertools
import math
import timeit
#input = sys.stdin.readline
#########################
# imgur.com/Pkt7iIf.png #
#########################
def sieve(n):
if n < 2: return list()
prime = [True for _ in range(n + 1)]
p = 3
while p * p <= n:
if prime[p]:
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 2
r = [2]
for p in range(3, n + 1, 2):
if prime[p]:
r.append(p)
return r
def divs(n, start=1):
divisors = []
for i in range(start, int(math.sqrt(n) + 1)):
if n % i == 0:
if n / i == i:
divisors.append(i)
else:
divisors.extend([i, n // i])
return divisors
def divn(n, primes):
divs_number = 1
for i in primes:
if n == 1:
return divs_number
t = 1
while n % i == 0:
t += 1
n //= i
divs_number *= t
def flin(d, x, default = -1):
left = right = -1
for i in range(len(d)):
if d[i] == x:
if left == -1: left = i
right = i
if left == -1:
return (default, default)
else:
return (left, right)
def ceil(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def prr(a, sep=' '): print(sep.join(map(str, a)))
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
t = ii()
for _ in range(t):
s = f'?{input()}?'
s = [x for x in s]
f = 1
for i in range(1, len(s) - 1):
if s[i] != '?' and (s[i - 1] == s[i] or s[i] == s[i + 1]):
f = 0
break
elif s[i] == '?':
pojiloi_setik = {'a', 'b', 'c'} - {s[i - 1], s[i + 1]}
s[i] = pojiloi_setik.pop()
prr(s[1:-1], '') if f else print(-1)
```
|
output
| 1
| 103,027
| 0
| 206,055
|
Provide tags and a correct Python 3 solution for this coding contest problem.
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.
Ahcl wants to construct a beautiful string. He has a string s, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!
More formally, after replacing all characters '?', the condition s_i β s_{i+1} should be satisfied for all 1 β€ i β€ |s| - 1, where |s| is the length of the string s.
Input
The first line contains positive integer t (1 β€ t β€ 1000) β the number of test cases. Next t lines contain the descriptions of test cases.
Each line contains a non-empty string s consisting of only characters 'a', 'b', 'c' and '?'.
It is guaranteed that in each test case a string s has at least one character '?'. The sum of lengths of strings s in all test cases does not exceed 10^5.
Output
For each test case given in the input print the answer in the following format:
* If it is impossible to create a beautiful string, print "-1" (without quotes);
* Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.
Example
Input
3
a???cb
a??bbc
a?b?c
Output
ababcb
-1
acbac
Note
In the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.
In the second test case, it is impossible to create a beautiful string, because the 4-th and 5-th characters will be always equal.
In the third test case, the only answer is "acbac".
|
instruction
| 0
| 103,028
| 0
| 206,056
|
Tags: constructive algorithms, greedy
Correct Solution:
```
t=int(input())
for i in range(t):
st=input()
ans=''
fl = False
for i in range(len(st)-1):
if st[i]!="?":
ans+=st[i]
if i!=0:
if st[i-1]==st[i]:
fl = True
break
else:
if i>=1:
if ans[i-1]=="a":
if st[i+1]!="b":
ans+="b"
else:
ans+="c"
elif ans[i-1]=="b":
if st[i+1]!="a":
ans+="a"
else:
ans+="c"
elif ans[i-1]=="c":
if st[i+1]!="a":
ans+="a"
else:
ans+="b"
else:
if st[i+1]=="a":
ans+="b"
elif st[i+1]=="b":
ans+="c"
else:
ans+="a"
if len(st)>1 and st[-1]==st[-2] and st[-1]!="?":
fl=True
if fl:
print(-1)
continue
if st[-1]=="?":
if len(st)==1:
print("a")
else:
if ans[-1]=="a":
ans+="b"
elif ans[-1]=="b":
ans+="c"
else:
ans+="a"
print(ans)
else:
ans+=st[-1]
print(ans)
```
|
output
| 1
| 103,028
| 0
| 206,057
|
Provide tags and a correct Python 3 solution for this coding contest problem.
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.
Ahcl wants to construct a beautiful string. He has a string s, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!
More formally, after replacing all characters '?', the condition s_i β s_{i+1} should be satisfied for all 1 β€ i β€ |s| - 1, where |s| is the length of the string s.
Input
The first line contains positive integer t (1 β€ t β€ 1000) β the number of test cases. Next t lines contain the descriptions of test cases.
Each line contains a non-empty string s consisting of only characters 'a', 'b', 'c' and '?'.
It is guaranteed that in each test case a string s has at least one character '?'. The sum of lengths of strings s in all test cases does not exceed 10^5.
Output
For each test case given in the input print the answer in the following format:
* If it is impossible to create a beautiful string, print "-1" (without quotes);
* Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.
Example
Input
3
a???cb
a??bbc
a?b?c
Output
ababcb
-1
acbac
Note
In the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.
In the second test case, it is impossible to create a beautiful string, because the 4-th and 5-th characters will be always equal.
In the third test case, the only answer is "acbac".
|
instruction
| 0
| 103,029
| 0
| 206,058
|
Tags: constructive algorithms, greedy
Correct Solution:
```
lis=['a','b','c']
for _ in range(int(input())):
s=list(input())
f,i=0,0
if(len(s)==1 and s[0]=='?'):
print('a')
continue
if(s[0]=='?'):
for k in range(0,3):
if(s[1]!=lis[k]):
s[0]=lis[k]
else:
i=i+1
if(len(s)==1):
ss=''
print(ss.join(s))
continue
i=0
for j in range(0,len(s)-1):
if(s[j]==s[j+1] and s[j]!='?' and s[j+1]!='?'):
print(-1)
f=1
break
elif(s[j]=='?'):
i=0
for k in range(0,3):
if(lis[k]!=s[(j-1)] and lis[k]!=s[j+1]):
s[j]=lis[k]
else:
i=i+1
if(f==1):
f=0
continue
else:
if(s[len(s)-1]=='?'):
i=0
for k in range(0,3):
if(s[len(s)-2]!=lis[k]):
s[len(s)-1]=lis[k]
else:
i=i+1
ss=""
print(ss.join(s))
```
|
output
| 1
| 103,029
| 0
| 206,059
|
Provide tags and a correct Python 3 solution for this coding contest problem.
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.
Ahcl wants to construct a beautiful string. He has a string s, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!
More formally, after replacing all characters '?', the condition s_i β s_{i+1} should be satisfied for all 1 β€ i β€ |s| - 1, where |s| is the length of the string s.
Input
The first line contains positive integer t (1 β€ t β€ 1000) β the number of test cases. Next t lines contain the descriptions of test cases.
Each line contains a non-empty string s consisting of only characters 'a', 'b', 'c' and '?'.
It is guaranteed that in each test case a string s has at least one character '?'. The sum of lengths of strings s in all test cases does not exceed 10^5.
Output
For each test case given in the input print the answer in the following format:
* If it is impossible to create a beautiful string, print "-1" (without quotes);
* Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.
Example
Input
3
a???cb
a??bbc
a?b?c
Output
ababcb
-1
acbac
Note
In the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.
In the second test case, it is impossible to create a beautiful string, because the 4-th and 5-th characters will be always equal.
In the third test case, the only answer is "acbac".
|
instruction
| 0
| 103,030
| 0
| 206,060
|
Tags: constructive algorithms, greedy
Correct Solution:
```
t = int(input())
while t:
t += -1
s = input()
s = list(s)
s.insert(0, '0')
s.append('0')
s.append('1')
ch = 1
for i in range(1, len(s) - 1):
if s[i] == '?':
if s[i - 1] != 'a' and s[i + 1] != 'a': s[i] = 'a'
elif s[i - 1] != 'b' and s[i + 1] != 'b': s[i] = 'b'
else: s[i] = 'c'
if s[i] == s[i + 1]:
ch = 0
break
if ch == 0: print(-1)
else:
s = ''.join(s)
print(s[1: len(s) - 2])
```
|
output
| 1
| 103,030
| 0
| 206,061
|
Provide tags and a correct Python 3 solution for this coding contest problem.
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.
Ahcl wants to construct a beautiful string. He has a string s, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!
More formally, after replacing all characters '?', the condition s_i β s_{i+1} should be satisfied for all 1 β€ i β€ |s| - 1, where |s| is the length of the string s.
Input
The first line contains positive integer t (1 β€ t β€ 1000) β the number of test cases. Next t lines contain the descriptions of test cases.
Each line contains a non-empty string s consisting of only characters 'a', 'b', 'c' and '?'.
It is guaranteed that in each test case a string s has at least one character '?'. The sum of lengths of strings s in all test cases does not exceed 10^5.
Output
For each test case given in the input print the answer in the following format:
* If it is impossible to create a beautiful string, print "-1" (without quotes);
* Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.
Example
Input
3
a???cb
a??bbc
a?b?c
Output
ababcb
-1
acbac
Note
In the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.
In the second test case, it is impossible to create a beautiful string, because the 4-th and 5-th characters will be always equal.
In the third test case, the only answer is "acbac".
|
instruction
| 0
| 103,031
| 0
| 206,062
|
Tags: constructive algorithms, greedy
Correct Solution:
```
t=int(input())
for i in range(t):
s=input()
if "aa" in s or "bb" in s or "cc" in s:
print(-1)
elif len(s)==1 and s[0]=="?":
print("a")
else:
s=list(s)
for j in range(len(s)):
if s[j]=="?":
if j!=0 and j!=len(s)-1:
if s[j-1]!="a" and s[j+1]!="a":s[j]="a"
elif s[j-1]!="b" and s[j+1]!="b":s[j]="b"
elif s[j-1]!="c" and s[j+1]!="c":s[j]="c"
elif j==0:
if s[j+1]!="a":s[j]="a"
elif s[j+1]!="b":s[j]="b"
elif s[j+1]!="c":s[j]="c"
elif j==len(s)-1:
if s[j-1]!="a":s[j]="a"
elif s[j-1]!="b":s[j]="b"
elif s[j-1]!="c":s[j]="c"
print(*s,sep="")
```
|
output
| 1
| 103,031
| 0
| 206,063
|
Provide tags and a correct Python 3 solution for this coding contest problem.
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.
Ahcl wants to construct a beautiful string. He has a string s, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!
More formally, after replacing all characters '?', the condition s_i β s_{i+1} should be satisfied for all 1 β€ i β€ |s| - 1, where |s| is the length of the string s.
Input
The first line contains positive integer t (1 β€ t β€ 1000) β the number of test cases. Next t lines contain the descriptions of test cases.
Each line contains a non-empty string s consisting of only characters 'a', 'b', 'c' and '?'.
It is guaranteed that in each test case a string s has at least one character '?'. The sum of lengths of strings s in all test cases does not exceed 10^5.
Output
For each test case given in the input print the answer in the following format:
* If it is impossible to create a beautiful string, print "-1" (without quotes);
* Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.
Example
Input
3
a???cb
a??bbc
a?b?c
Output
ababcb
-1
acbac
Note
In the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.
In the second test case, it is impossible to create a beautiful string, because the 4-th and 5-th characters will be always equal.
In the third test case, the only answer is "acbac".
|
instruction
| 0
| 103,032
| 0
| 206,064
|
Tags: constructive algorithms, greedy
Correct Solution:
```
#code
def solution(a,b):
s=['a','b','c']
s=set(s)
t=[a,b]
s1= s-set(t)
s1=list(s1)
return (s1[0])
def checkString(s):
if(len(s)==1):
return "a"
for i in range(len(s)):
if(s[i]=='?'):
if(i==0):
if(s[i+1]=='?'):
s[i]='a'
else:
s[i]=solution(s[i+1],'a')
elif(i==len(s)-1):
s[i]=solution(s[i-1],'a')
elif(s[i+1]=='?'):
s[i]=solution(s[i-1],'a')
else:
s[i]=solution(s[i-1],s[i+1])
else:
if(i+1 != len(s) and s[i]==s[i+1]):
return -1
return s
# print(s)
for _ in range(int(input())):
s=input()
st=checkString(list(s))
if(st==-1):
print(-1)
else:
print(''.join(st))
```
|
output
| 1
| 103,032
| 0
| 206,065
|
Provide tags and a correct Python 3 solution for this coding contest problem.
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.
Ahcl wants to construct a beautiful string. He has a string s, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!
More formally, after replacing all characters '?', the condition s_i β s_{i+1} should be satisfied for all 1 β€ i β€ |s| - 1, where |s| is the length of the string s.
Input
The first line contains positive integer t (1 β€ t β€ 1000) β the number of test cases. Next t lines contain the descriptions of test cases.
Each line contains a non-empty string s consisting of only characters 'a', 'b', 'c' and '?'.
It is guaranteed that in each test case a string s has at least one character '?'. The sum of lengths of strings s in all test cases does not exceed 10^5.
Output
For each test case given in the input print the answer in the following format:
* If it is impossible to create a beautiful string, print "-1" (without quotes);
* Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.
Example
Input
3
a???cb
a??bbc
a?b?c
Output
ababcb
-1
acbac
Note
In the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.
In the second test case, it is impossible to create a beautiful string, because the 4-th and 5-th characters will be always equal.
In the third test case, the only answer is "acbac".
|
instruction
| 0
| 103,033
| 0
| 206,066
|
Tags: constructive algorithms, greedy
Correct Solution:
```
def dryrun(s):
for i in range(1,len(s)):
if(s[i]!='?'):
if(s[i-1]==s[i]):
return 0
return 1
def replaceq(l,r):
re = ''
if(l==0 and r==0):
re+='a'
elif(l!=0 and r!=0):
if(l==r=='a'):
re+='b'
elif(l==r=='b'):
re+='c'
elif(l==r=='c'):
re+='a'
elif((l=='c' and r=='b') or (l=='b' and r=='c')):
re+='a'
elif((l=='a' and r=='b') or (l=='b' and r=='a')):
re+='c'
elif((l=='a' and r=='c') or (l=='c' and r=='a')):
re+='b'
elif(l==0):
if(r=='a'):
re+='b'
elif(r=='b'):
re+='c'
elif(r=='c'):
re+='a'
elif(r==0):
if(l=='a'):
re+='b'
elif(l=='b'):
re+='c'
elif(l=='c'):
re+='a'
return re
t=int(input())
for _ in range(t):
s = input()
ns = []
if(dryrun(s)):
for i in range(len(s)):
if(s[i]=="?"):
l = 0 if i==0 else ns[i-1]
r = 0 if (i==len(s)-1 or s[i+1]=="?") else s[i+1]
ns.append(replaceq(l,r))
else:
ns.append(s[i])
print(''.join(ns))
else:
print(-1)
```
|
output
| 1
| 103,033
| 0
| 206,067
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.
Ahcl wants to construct a beautiful string. He has a string s, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!
More formally, after replacing all characters '?', the condition s_i β s_{i+1} should be satisfied for all 1 β€ i β€ |s| - 1, where |s| is the length of the string s.
Input
The first line contains positive integer t (1 β€ t β€ 1000) β the number of test cases. Next t lines contain the descriptions of test cases.
Each line contains a non-empty string s consisting of only characters 'a', 'b', 'c' and '?'.
It is guaranteed that in each test case a string s has at least one character '?'. The sum of lengths of strings s in all test cases does not exceed 10^5.
Output
For each test case given in the input print the answer in the following format:
* If it is impossible to create a beautiful string, print "-1" (without quotes);
* Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.
Example
Input
3
a???cb
a??bbc
a?b?c
Output
ababcb
-1
acbac
Note
In the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.
In the second test case, it is impossible to create a beautiful string, because the 4-th and 5-th characters will be always equal.
In the third test case, the only answer is "acbac".
Submitted Solution:
```
t=int(input())
for q in range(t):
r={'a':'b','b':'c','c':'a'}
s=list(input())
n=len(s)
c=0
flag=0
for i in range(0,n):
if s[i]!='?':
if i>=1 and s[i]==s[i-1]:
flag=1
break
elif s[i]=='?':
if i==0:
s[i]='a'
else:
s[i]=r[s[i-1]]
if i<n-1:
if s[i]==s[i+1]:
s[i]=r[s[i]]
if flag==1:
print(-1)
else:
print("".join(s))
```
|
instruction
| 0
| 103,034
| 0
| 206,068
|
Yes
|
output
| 1
| 103,034
| 0
| 206,069
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.
Ahcl wants to construct a beautiful string. He has a string s, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!
More formally, after replacing all characters '?', the condition s_i β s_{i+1} should be satisfied for all 1 β€ i β€ |s| - 1, where |s| is the length of the string s.
Input
The first line contains positive integer t (1 β€ t β€ 1000) β the number of test cases. Next t lines contain the descriptions of test cases.
Each line contains a non-empty string s consisting of only characters 'a', 'b', 'c' and '?'.
It is guaranteed that in each test case a string s has at least one character '?'. The sum of lengths of strings s in all test cases does not exceed 10^5.
Output
For each test case given in the input print the answer in the following format:
* If it is impossible to create a beautiful string, print "-1" (without quotes);
* Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.
Example
Input
3
a???cb
a??bbc
a?b?c
Output
ababcb
-1
acbac
Note
In the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.
In the second test case, it is impossible to create a beautiful string, because the 4-th and 5-th characters will be always equal.
In the third test case, the only answer is "acbac".
Submitted Solution:
```
t = int(input())
all = ['a', 'b', 'c']
for _ in range(t):
s = input()
out = []
for i in range(len(s) - 1):
if s[i] != '?' and s[i] == s[i + 1]:
print(-1)
break
else:
if len(s) > 1:
for i in range(len(s)):
ans = ''
if i == 0:
if s[i] == '?':
ans = 'a' if s[i + 1] != 'a' else 'b'
elif i == len(s) - 1:
if s[i] == '?':
ans = 'a' if out[i - 1] != 'a' else 'b'
else:
if s[i] == '?':
ans = list(set(all) - set([out[i-1], s[i+1]]))[0]
if ans == '':
out.append(s[i])
else:
out.append(ans)
else:
out = ['a']
print(''.join(out))
```
|
instruction
| 0
| 103,035
| 0
| 206,070
|
Yes
|
output
| 1
| 103,035
| 0
| 206,071
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.
Ahcl wants to construct a beautiful string. He has a string s, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!
More formally, after replacing all characters '?', the condition s_i β s_{i+1} should be satisfied for all 1 β€ i β€ |s| - 1, where |s| is the length of the string s.
Input
The first line contains positive integer t (1 β€ t β€ 1000) β the number of test cases. Next t lines contain the descriptions of test cases.
Each line contains a non-empty string s consisting of only characters 'a', 'b', 'c' and '?'.
It is guaranteed that in each test case a string s has at least one character '?'. The sum of lengths of strings s in all test cases does not exceed 10^5.
Output
For each test case given in the input print the answer in the following format:
* If it is impossible to create a beautiful string, print "-1" (without quotes);
* Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.
Example
Input
3
a???cb
a??bbc
a?b?c
Output
ababcb
-1
acbac
Note
In the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.
In the second test case, it is impossible to create a beautiful string, because the 4-th and 5-th characters will be always equal.
In the third test case, the only answer is "acbac".
Submitted Solution:
```
t=int(input())
for x in range(t):
a=list(input())
if len(a)>=2 and a[0]=='?':
if a[1]=='a':
a[0]='b'
elif a[1]=='b':
a[0]='a'
elif a[1]=='c':
a[0]='b'
elif a[1]=='?':
a[0]='a'
elif a[0]=='?':
a[0]='a'
for x in range(1,len(a)-1):
if a[x]=='?':
g=a[x-1]+a[x+1]
if g=='ab' or g=='ba':
a[x]='c'
elif g=='ac' or g=='ca':
a[x]='b'
elif g=='bc' or g=='cb':
a[x]='a'
if g=='aa':
a[x]='b'
elif g=='bb':
a[x]='a'
elif g=='cc':
a[x]='b'
if g=='a?':
a[x]='b'
elif g=='b?':
a[x]='a'
elif g=='c?':
a[x]='b'
if len(a)>=2 and a[-1]=='?':
if a[-2]=='a':
a[-1]='b'
elif a[-2]=='b':
a[-1]='a'
elif a[-2]=='c':
a[-1]='b'
elif a[-2]=='?':
a[-1]='a'
elif a[-1]=='?':
a[-1]='a'
t=True
for x in range(len(a)-1):
if a[x]==a[x+1]:
t=False
if t:print(''.join(a))
else:print(-1)
```
|
instruction
| 0
| 103,036
| 0
| 206,072
|
Yes
|
output
| 1
| 103,036
| 0
| 206,073
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.
Ahcl wants to construct a beautiful string. He has a string s, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!
More formally, after replacing all characters '?', the condition s_i β s_{i+1} should be satisfied for all 1 β€ i β€ |s| - 1, where |s| is the length of the string s.
Input
The first line contains positive integer t (1 β€ t β€ 1000) β the number of test cases. Next t lines contain the descriptions of test cases.
Each line contains a non-empty string s consisting of only characters 'a', 'b', 'c' and '?'.
It is guaranteed that in each test case a string s has at least one character '?'. The sum of lengths of strings s in all test cases does not exceed 10^5.
Output
For each test case given in the input print the answer in the following format:
* If it is impossible to create a beautiful string, print "-1" (without quotes);
* Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.
Example
Input
3
a???cb
a??bbc
a?b?c
Output
ababcb
-1
acbac
Note
In the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.
In the second test case, it is impossible to create a beautiful string, because the 4-th and 5-th characters will be always equal.
In the third test case, the only answer is "acbac".
Submitted Solution:
```
def abc(s: str):
if not s:
return s
l = len(s)
if l == 1:
if s == '?':
return 'a'
else:
return s
s = list(s)
for i in range(l-1):
if s[i] == s[i+1] and s[i] != '?':
return '-1'
for i in range(l):
if s[i] != '?':
continue
if i == 0:
if s[1] == '?':
s[0] = 'a'
elif s[1] == 'a':
s[0] = 'b'
else:
s[0] = 'a'
continue
if i == l-1:
if s[-2] == '?':
s[-1] = 'a'
elif s[-2] == 'a':
s[-1] = 'b'
else:
s[-1] = 'a'
continue
for j in ['a', 'b', 'c']:
if j != s[i-1] and j != s[i+1]:
s[i] = j
break
return ''.join(s)
n = int(input())
out = []
for i in range(n):
s = input()
out.append(abc(s))
for i in out:
print(i)
```
|
instruction
| 0
| 103,037
| 0
| 206,074
|
Yes
|
output
| 1
| 103,037
| 0
| 206,075
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.
Ahcl wants to construct a beautiful string. He has a string s, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!
More formally, after replacing all characters '?', the condition s_i β s_{i+1} should be satisfied for all 1 β€ i β€ |s| - 1, where |s| is the length of the string s.
Input
The first line contains positive integer t (1 β€ t β€ 1000) β the number of test cases. Next t lines contain the descriptions of test cases.
Each line contains a non-empty string s consisting of only characters 'a', 'b', 'c' and '?'.
It is guaranteed that in each test case a string s has at least one character '?'. The sum of lengths of strings s in all test cases does not exceed 10^5.
Output
For each test case given in the input print the answer in the following format:
* If it is impossible to create a beautiful string, print "-1" (without quotes);
* Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.
Example
Input
3
a???cb
a??bbc
a?b?c
Output
ababcb
-1
acbac
Note
In the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.
In the second test case, it is impossible to create a beautiful string, because the 4-th and 5-th characters will be always equal.
In the third test case, the only answer is "acbac".
Submitted Solution:
```
n=int(input())
for i in range(n):
s=str(input())
s=list(s)
if(len(s)==1):
if(s[0]=='?'):
print('a')
else:
print(s[0])
else:
flag=0
for j in range(0,len(s)-1):
if(s[j]!='?' and s[j]==s[j+1]):
flag=1
break
if(flag==1):
print(-1)
else:
e=''
for k in range(0,len(s)):
if(s[k]!='?'):
e=e+s[k]
elif(s[k]=='?' and k==0):
if(s[k+1]=='a'):
e=e+'b'
elif(s[k+1]=='b'):
e=e+'c'
else:
e=e+'a'
elif(s[k]=='?' and k==len(s)-1):
if(s[k-1]=='a'):
e=e+'b'
elif(s[k-1]=='b'):
e=e+'c'
else:
e=e+'a'
else:
l=[]
l.append(s[k+1])
l.append(s[k-1])
if('a' not in l):
e=e+'a'
s[k]='a'
elif('b' not in l):
e=e+'b'
s[k]='b'
elif('c' not in l):
e=e+'c'
s[k]='c'
print(e)
```
|
instruction
| 0
| 103,038
| 0
| 206,076
|
No
|
output
| 1
| 103,038
| 0
| 206,077
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.