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
|
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
Input
The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
Output
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.
Examples
Input
abcd
defgh
Output
5
Input
a
a
Output
-1
Note
In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
|
instruction
| 0
| 17,319
| 0
| 34,638
|
Tags: constructive algorithms, strings
Correct Solution:
```
w1 = input()
w2 = input()
if w1==w2:
print("-1")
else:
print(max(len(w1),len(w2)))
```
|
output
| 1
| 17,319
| 0
| 34,639
|
Provide tags and a correct Python 3 solution for this coding contest problem.
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
Input
The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
Output
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.
Examples
Input
abcd
defgh
Output
5
Input
a
a
Output
-1
Note
In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
|
instruction
| 0
| 17,320
| 0
| 34,640
|
Tags: constructive algorithms, strings
Correct Solution:
```
a, b = input(), input()
if a == b:
print(-1)
elif len(a) > len(b):
print(len(a))
elif len(a) < len(b):
print(len(b))
else:
print(len(a))
```
|
output
| 1
| 17,320
| 0
| 34,641
|
Provide tags and a correct Python 3 solution for this coding contest problem.
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
Input
The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
Output
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.
Examples
Input
abcd
defgh
Output
5
Input
a
a
Output
-1
Note
In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
|
instruction
| 0
| 17,321
| 0
| 34,642
|
Tags: constructive algorithms, strings
Correct Solution:
```
s=input()
d=input()
m=-1
if len(s) != len(d):
m=max(len(s),len(d))
elif len(s)==len(d):
for i in range(len(s)):
if s[i] != d[i]:
m=max(len(s),len(d))
print(m)
```
|
output
| 1
| 17,321
| 0
| 34,643
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
Input
The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
Output
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.
Examples
Input
abcd
defgh
Output
5
Input
a
a
Output
-1
Note
In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
Submitted Solution:
```
def longest (a,b) :
if len(a) > len(b) :
return len(a)
elif len(a) == len(b):
if a in b:
return -1
else:
return len(a)
else:
return len(b)
a = input()
b = input()
print (longest(a,b))
```
|
instruction
| 0
| 17,322
| 0
| 34,644
|
Yes
|
output
| 1
| 17,322
| 0
| 34,645
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
Input
The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
Output
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.
Examples
Input
abcd
defgh
Output
5
Input
a
a
Output
-1
Note
In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
Submitted Solution:
```
'''
Auther: ghoshashis545 Ashis Ghosh
college: jalpaiguri Govt Enggineering College
Date:12/03/2020
'''
from math import ceil,sqrt,gcd,log,floor
from collections import deque
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().strip().split(" "))
def li(): return list(mi())
def main():
a=si()
b=si()
if(a==b):
print('-1')
else:
print(max(len(a),len(b)))
if __name__=="__main__":
main()
```
|
instruction
| 0
| 17,323
| 0
| 34,646
|
Yes
|
output
| 1
| 17,323
| 0
| 34,647
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
Input
The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
Output
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.
Examples
Input
abcd
defgh
Output
5
Input
a
a
Output
-1
Note
In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
Submitted Solution:
```
#n = int(input())
#n, m = map(int, input().split())
s = input()
t = input()
#c = list(map(int, input().split()))
if s != t:
print(max(len(s),len(t)))
else:
print(-1)
```
|
instruction
| 0
| 17,324
| 0
| 34,648
|
Yes
|
output
| 1
| 17,324
| 0
| 34,649
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
Input
The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
Output
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.
Examples
Input
abcd
defgh
Output
5
Input
a
a
Output
-1
Note
In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
Submitted Solution:
```
s1, s2 = input(), input()
if len(s1) != len(s2):
print(max(len(s1), len(s2)))
else:
if s1 == s2: print(-1)
else: print(len(s1))
```
|
instruction
| 0
| 17,325
| 0
| 34,650
|
Yes
|
output
| 1
| 17,325
| 0
| 34,651
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
Input
The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
Output
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.
Examples
Input
abcd
defgh
Output
5
Input
a
a
Output
-1
Note
In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
Submitted Solution:
```
a=input()
b=input()
if(len(a)==len(b)):
print(-1)
else:
print(max(len(a),len(b)))
```
|
instruction
| 0
| 17,326
| 0
| 34,652
|
No
|
output
| 1
| 17,326
| 0
| 34,653
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
Input
The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
Output
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.
Examples
Input
abcd
defgh
Output
5
Input
a
a
Output
-1
Note
In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
Submitted Solution:
```
s1 = input()
s2 = input()
s3 = set()
s4 = set()
for i in s1 :
s3.add(i)
for i in s2 :
s4.add(i)
if s1 == s2 :
print(-1)
else:
if len(s3) >= len(s4) :
print(len(s3))
else:
print(len(s4))
```
|
instruction
| 0
| 17,327
| 0
| 34,654
|
No
|
output
| 1
| 17,327
| 0
| 34,655
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
Input
The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
Output
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.
Examples
Input
abcd
defgh
Output
5
Input
a
a
Output
-1
Note
In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
Submitted Solution:
```
a=input()
b=input()
c=0
d=[]
if a==b:
print(-1)
elif len(set(a))==len(set(b)):
print(max(len(a),len(b)))
```
|
instruction
| 0
| 17,328
| 0
| 34,656
|
No
|
output
| 1
| 17,328
| 0
| 34,657
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
Input
The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
Output
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.
Examples
Input
abcd
defgh
Output
5
Input
a
a
Output
-1
Note
In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
Submitted Solution:
```
from collections import Counter
a=input()
b=input()
if Counter(a)==Counter(b):
print(-1 if a==b else a)
else:
print(len(a) if len(a)>len(b) else len(b))
```
|
instruction
| 0
| 17,329
| 0
| 34,658
|
No
|
output
| 1
| 17,329
| 0
| 34,659
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them!
A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≤ a ≤ b ≤ n). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c_1, c_2, …, c_k out of 26.
After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string s and the number of Latin letters still available on the keyboard.
The second line contains the string s consisting of exactly n lowercase Latin letters.
The third line contains k space-separated distinct lowercase Latin letters c_1, c_2, …, c_k — the letters still available on the keyboard.
Output
Print a single number — the number of substrings of s that can be typed using only available letters c_1, c_2, …, c_k.
Examples
Input
7 2
abacaba
a b
Output
12
Input
10 3
sadfaasdda
f a d
Output
21
Input
7 1
aaaaaaa
b
Output
0
Note
In the first example Norge can print substrings s[1…2], s[2…3], s[1…3], s[1…1], s[2…2], s[3…3], s[5…6], s[6…7], s[5…7], s[5…5], s[6…6], s[7…7].
|
instruction
| 0
| 17,795
| 0
| 35,590
|
Tags: combinatorics, dp, implementation
Correct Solution:
```
import sys
input = sys.stdin.readline
'''
'''
triangle = lambda n: n*(n+1)//2
n, k = map(int, input().split())
s = list(input().rstrip())
valid = { c for c in input().rstrip() }
res = 0
op = None
i = 0
while i < n:
if s[i] in valid:
if op == None:
op = i
else:
# broken char
if op != None:
res += triangle(i-op)
op = None
i += 1
if op != None:
res += triangle(n-op)
print(res)
```
|
output
| 1
| 17,795
| 0
| 35,591
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them!
A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≤ a ≤ b ≤ n). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c_1, c_2, …, c_k out of 26.
After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string s and the number of Latin letters still available on the keyboard.
The second line contains the string s consisting of exactly n lowercase Latin letters.
The third line contains k space-separated distinct lowercase Latin letters c_1, c_2, …, c_k — the letters still available on the keyboard.
Output
Print a single number — the number of substrings of s that can be typed using only available letters c_1, c_2, …, c_k.
Examples
Input
7 2
abacaba
a b
Output
12
Input
10 3
sadfaasdda
f a d
Output
21
Input
7 1
aaaaaaa
b
Output
0
Note
In the first example Norge can print substrings s[1…2], s[2…3], s[1…3], s[1…1], s[2…2], s[3…3], s[5…6], s[6…7], s[5…7], s[5…5], s[6…6], s[7…7].
|
instruction
| 0
| 17,796
| 0
| 35,592
|
Tags: combinatorics, dp, implementation
Correct Solution:
```
q,k = map(int,input().split())
s=input()
alph = list(input().split())
kol = 0
ind =[0]
for i in range (len(s)):
if s[i] not in alph:
ind.append(i+1)
ind.append(len(s)+1)
for i in range (len(ind)-1):
n = ind[i+1] - ind[i] - 1
kol += n*(n+1)//2
print(kol)
```
|
output
| 1
| 17,796
| 0
| 35,593
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them!
A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≤ a ≤ b ≤ n). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c_1, c_2, …, c_k out of 26.
After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string s and the number of Latin letters still available on the keyboard.
The second line contains the string s consisting of exactly n lowercase Latin letters.
The third line contains k space-separated distinct lowercase Latin letters c_1, c_2, …, c_k — the letters still available on the keyboard.
Output
Print a single number — the number of substrings of s that can be typed using only available letters c_1, c_2, …, c_k.
Examples
Input
7 2
abacaba
a b
Output
12
Input
10 3
sadfaasdda
f a d
Output
21
Input
7 1
aaaaaaa
b
Output
0
Note
In the first example Norge can print substrings s[1…2], s[2…3], s[1…3], s[1…1], s[2…2], s[3…3], s[5…6], s[6…7], s[5…7], s[5…5], s[6…6], s[7…7].
|
instruction
| 0
| 17,797
| 0
| 35,594
|
Tags: combinatorics, dp, implementation
Correct Solution:
```
n,k = map(int,input().split())
s = input()+'-'
m = input()
c = 0
ans = 0
for j in s:
if (j in m):
c+=1
else:
ans+= (c*(c+1))//2
c = 0
print(ans)
```
|
output
| 1
| 17,797
| 0
| 35,595
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them!
A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≤ a ≤ b ≤ n). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c_1, c_2, …, c_k out of 26.
After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string s and the number of Latin letters still available on the keyboard.
The second line contains the string s consisting of exactly n lowercase Latin letters.
The third line contains k space-separated distinct lowercase Latin letters c_1, c_2, …, c_k — the letters still available on the keyboard.
Output
Print a single number — the number of substrings of s that can be typed using only available letters c_1, c_2, …, c_k.
Examples
Input
7 2
abacaba
a b
Output
12
Input
10 3
sadfaasdda
f a d
Output
21
Input
7 1
aaaaaaa
b
Output
0
Note
In the first example Norge can print substrings s[1…2], s[2…3], s[1…3], s[1…1], s[2…2], s[3…3], s[5…6], s[6…7], s[5…7], s[5…5], s[6…6], s[7…7].
|
instruction
| 0
| 17,798
| 0
| 35,596
|
Tags: combinatorics, dp, implementation
Correct Solution:
```
m, n = input().split()
s = input()
b = [i for i in input().split()]
k = [0 for i in range(int(m))]
for i in range(int(m)):
if(s[i] in b):
if(i > 0):
k[i] = k[i - 1] + 1
else:
k[i] = 1
print(sum(k))
```
|
output
| 1
| 17,798
| 0
| 35,597
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them!
A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≤ a ≤ b ≤ n). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c_1, c_2, …, c_k out of 26.
After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string s and the number of Latin letters still available on the keyboard.
The second line contains the string s consisting of exactly n lowercase Latin letters.
The third line contains k space-separated distinct lowercase Latin letters c_1, c_2, …, c_k — the letters still available on the keyboard.
Output
Print a single number — the number of substrings of s that can be typed using only available letters c_1, c_2, …, c_k.
Examples
Input
7 2
abacaba
a b
Output
12
Input
10 3
sadfaasdda
f a d
Output
21
Input
7 1
aaaaaaa
b
Output
0
Note
In the first example Norge can print substrings s[1…2], s[2…3], s[1…3], s[1…1], s[2…2], s[3…3], s[5…6], s[6…7], s[5…7], s[5…5], s[6…6], s[7…7].
|
instruction
| 0
| 17,799
| 0
| 35,598
|
Tags: combinatorics, dp, implementation
Correct Solution:
```
n, k = map(int, input().split())
s = input()
c = set(map(str, input().split()))
cnt, i = [], 0
while i < n:
j = i
while j < n and s[j] in c:
j += 1
cnt.append(j-i)
i = j+1
res = sum([i*(i+1)//2 for i in cnt])
print(res)
```
|
output
| 1
| 17,799
| 0
| 35,599
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them!
A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≤ a ≤ b ≤ n). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c_1, c_2, …, c_k out of 26.
After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string s and the number of Latin letters still available on the keyboard.
The second line contains the string s consisting of exactly n lowercase Latin letters.
The third line contains k space-separated distinct lowercase Latin letters c_1, c_2, …, c_k — the letters still available on the keyboard.
Output
Print a single number — the number of substrings of s that can be typed using only available letters c_1, c_2, …, c_k.
Examples
Input
7 2
abacaba
a b
Output
12
Input
10 3
sadfaasdda
f a d
Output
21
Input
7 1
aaaaaaa
b
Output
0
Note
In the first example Norge can print substrings s[1…2], s[2…3], s[1…3], s[1…1], s[2…2], s[3…3], s[5…6], s[6…7], s[5…7], s[5…5], s[6…6], s[7…7].
|
instruction
| 0
| 17,800
| 0
| 35,600
|
Tags: combinatorics, dp, implementation
Correct Solution:
```
n,k = map(int,input().split())
s = input()
b = input()
B = list(b)
d = {}
for i in B:
if i not in d:
d[i] = 1
pre = [0]*(n)
if s[0] in d:
pre[0] = 1
else:
pre[0] = 0
for i in range(1,n):
if s[i] in d:
pre[i] = pre[i-1]+1
else:
pre[i] = 0
print(sum(pre))
```
|
output
| 1
| 17,800
| 0
| 35,601
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them!
A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≤ a ≤ b ≤ n). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c_1, c_2, …, c_k out of 26.
After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string s and the number of Latin letters still available on the keyboard.
The second line contains the string s consisting of exactly n lowercase Latin letters.
The third line contains k space-separated distinct lowercase Latin letters c_1, c_2, …, c_k — the letters still available on the keyboard.
Output
Print a single number — the number of substrings of s that can be typed using only available letters c_1, c_2, …, c_k.
Examples
Input
7 2
abacaba
a b
Output
12
Input
10 3
sadfaasdda
f a d
Output
21
Input
7 1
aaaaaaa
b
Output
0
Note
In the first example Norge can print substrings s[1…2], s[2…3], s[1…3], s[1…1], s[2…2], s[3…3], s[5…6], s[6…7], s[5…7], s[5…5], s[6…6], s[7…7].
|
instruction
| 0
| 17,801
| 0
| 35,602
|
Tags: combinatorics, dp, implementation
Correct Solution:
```
a,b = input().split()
a = int(a)
b = int(b)
s = input()
d = list(input().strip().split())
j = 0
for i in range(0,len(s)):
if(s[i] in d):
j = i
# print(j)
break
ans = 0
finalans = 0
for i in range(j,len(s)):
if(s[i] not in d):
finalans += (ans)*(ans + 1)//2
# finalans = finalans//2
# print(finalans)
ans = 0
else:
ans += 1
if(ans > 0):
finalans += (ans)*(ans + 1)//2
print(finalans)
```
|
output
| 1
| 17,801
| 0
| 35,603
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them!
A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≤ a ≤ b ≤ n). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c_1, c_2, …, c_k out of 26.
After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string s and the number of Latin letters still available on the keyboard.
The second line contains the string s consisting of exactly n lowercase Latin letters.
The third line contains k space-separated distinct lowercase Latin letters c_1, c_2, …, c_k — the letters still available on the keyboard.
Output
Print a single number — the number of substrings of s that can be typed using only available letters c_1, c_2, …, c_k.
Examples
Input
7 2
abacaba
a b
Output
12
Input
10 3
sadfaasdda
f a d
Output
21
Input
7 1
aaaaaaa
b
Output
0
Note
In the first example Norge can print substrings s[1…2], s[2…3], s[1…3], s[1…1], s[2…2], s[3…3], s[5…6], s[6…7], s[5…7], s[5…5], s[6…6], s[7…7].
|
instruction
| 0
| 17,802
| 0
| 35,604
|
Tags: combinatorics, dp, implementation
Correct Solution:
```
n, k = [int(x) for x in input().split()]
s = input()
letters = set(x for x in input().split())
temp = 0
ans = 0
for c in s:
if c in letters:
temp += 1
else:
ans += temp * (temp + 1) // 2
temp = 0
ans += temp * (temp + 1) // 2
print(ans)
```
|
output
| 1
| 17,802
| 0
| 35,605
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them!
A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≤ a ≤ b ≤ n). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c_1, c_2, …, c_k out of 26.
After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string s and the number of Latin letters still available on the keyboard.
The second line contains the string s consisting of exactly n lowercase Latin letters.
The third line contains k space-separated distinct lowercase Latin letters c_1, c_2, …, c_k — the letters still available on the keyboard.
Output
Print a single number — the number of substrings of s that can be typed using only available letters c_1, c_2, …, c_k.
Examples
Input
7 2
abacaba
a b
Output
12
Input
10 3
sadfaasdda
f a d
Output
21
Input
7 1
aaaaaaa
b
Output
0
Note
In the first example Norge can print substrings s[1…2], s[2…3], s[1…3], s[1…1], s[2…2], s[3…3], s[5…6], s[6…7], s[5…7], s[5…5], s[6…6], s[7…7].
Submitted Solution:
```
I=input
I()
s=I()+'#'
c=I()
r=i=0
for x in s:
if x in c:i+=1
else:r+=i*(i+1)//2;i=0
print(r)
```
|
instruction
| 0
| 17,803
| 0
| 35,606
|
Yes
|
output
| 1
| 17,803
| 0
| 35,607
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them!
A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≤ a ≤ b ≤ n). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c_1, c_2, …, c_k out of 26.
After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string s and the number of Latin letters still available on the keyboard.
The second line contains the string s consisting of exactly n lowercase Latin letters.
The third line contains k space-separated distinct lowercase Latin letters c_1, c_2, …, c_k — the letters still available on the keyboard.
Output
Print a single number — the number of substrings of s that can be typed using only available letters c_1, c_2, …, c_k.
Examples
Input
7 2
abacaba
a b
Output
12
Input
10 3
sadfaasdda
f a d
Output
21
Input
7 1
aaaaaaa
b
Output
0
Note
In the first example Norge can print substrings s[1…2], s[2…3], s[1…3], s[1…1], s[2…2], s[3…3], s[5…6], s[6…7], s[5…7], s[5…5], s[6…6], s[7…7].
Submitted Solution:
```
a = input().split()
a1= int(a[0])
a2 = int(a[1])
s = input()
li = [x for x in input().split()]
cal = 0
result=0
for i in range(len(s)):
if(s[i] in li):
cal+=1
else:
result+=(cal*(cal+1)//2)
cal=0
if(cal!=0):
result+=(cal*(cal+1)//2)
print(result)
```
|
instruction
| 0
| 17,804
| 0
| 35,608
|
Yes
|
output
| 1
| 17,804
| 0
| 35,609
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them!
A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≤ a ≤ b ≤ n). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c_1, c_2, …, c_k out of 26.
After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string s and the number of Latin letters still available on the keyboard.
The second line contains the string s consisting of exactly n lowercase Latin letters.
The third line contains k space-separated distinct lowercase Latin letters c_1, c_2, …, c_k — the letters still available on the keyboard.
Output
Print a single number — the number of substrings of s that can be typed using only available letters c_1, c_2, …, c_k.
Examples
Input
7 2
abacaba
a b
Output
12
Input
10 3
sadfaasdda
f a d
Output
21
Input
7 1
aaaaaaa
b
Output
0
Note
In the first example Norge can print substrings s[1…2], s[2…3], s[1…3], s[1…1], s[2…2], s[3…3], s[5…6], s[6…7], s[5…7], s[5…5], s[6…6], s[7…7].
Submitted Solution:
```
from sys import stdin, stdout
to = stdin.readline()
n, k = (to.split())
s = input()
l = stdin.readline()
l = l.split()
mp = {}
for i in range(len(l)):
mp[l[i]] = 1
ans = int(0)
cnt = int(0)
for i in range(len(s)):
if mp.get(s[i]) != None:
cnt += 1
else :
ans += (cnt * (cnt + 1)) // 2
cnt = 0
ans += cnt * (cnt + 1) // 2
stdout.write(str(ans))
```
|
instruction
| 0
| 17,805
| 0
| 35,610
|
Yes
|
output
| 1
| 17,805
| 0
| 35,611
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them!
A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≤ a ≤ b ≤ n). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c_1, c_2, …, c_k out of 26.
After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string s and the number of Latin letters still available on the keyboard.
The second line contains the string s consisting of exactly n lowercase Latin letters.
The third line contains k space-separated distinct lowercase Latin letters c_1, c_2, …, c_k — the letters still available on the keyboard.
Output
Print a single number — the number of substrings of s that can be typed using only available letters c_1, c_2, …, c_k.
Examples
Input
7 2
abacaba
a b
Output
12
Input
10 3
sadfaasdda
f a d
Output
21
Input
7 1
aaaaaaa
b
Output
0
Note
In the first example Norge can print substrings s[1…2], s[2…3], s[1…3], s[1…1], s[2…2], s[3…3], s[5…6], s[6…7], s[5…7], s[5…5], s[6…6], s[7…7].
Submitted Solution:
```
n, k = map(int,input().split())
s= input()
l = list(input().split())
can = [0]*1000
for c in l:
can[ord(c)]=1
#print(can[ord('a'):ord('z')+1])
b = [0] * n
z = 0
ans = 0
for i in range(n):
if can[ord(s[i])]:
z+=1
else:
ans += z*(z+1)//2
z=0
if z:
ans += z*(z+1)//2
print(ans)
```
|
instruction
| 0
| 17,806
| 0
| 35,612
|
Yes
|
output
| 1
| 17,806
| 0
| 35,613
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them!
A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≤ a ≤ b ≤ n). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c_1, c_2, …, c_k out of 26.
After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string s and the number of Latin letters still available on the keyboard.
The second line contains the string s consisting of exactly n lowercase Latin letters.
The third line contains k space-separated distinct lowercase Latin letters c_1, c_2, …, c_k — the letters still available on the keyboard.
Output
Print a single number — the number of substrings of s that can be typed using only available letters c_1, c_2, …, c_k.
Examples
Input
7 2
abacaba
a b
Output
12
Input
10 3
sadfaasdda
f a d
Output
21
Input
7 1
aaaaaaa
b
Output
0
Note
In the first example Norge can print substrings s[1…2], s[2…3], s[1…3], s[1…1], s[2…2], s[3…3], s[5…6], s[6…7], s[5…7], s[5…5], s[6…6], s[7…7].
Submitted Solution:
```
import sys
input = lambda:sys.stdin.readline()
int_arr = lambda: list(map(int,input().split()))
str_arr = lambda: list(map(str,input().split()))
get_str = lambda: map(str,input().split())
get_int = lambda: map(int,input().split())
get_flo = lambda: map(float,input().split())
mod = 1000000007
def solve(n,b,s,x):
c = 0
l,r = 0,1
while r < n:
if s[l] in x:
while r < n and s[r] in x:
r += 1
else:
nn = r-l
c += nn*(nn+1)//2
l = r
r += 1
else:
l += 1
r += 1
# if s[r-1] in x:
# c += (r-l)*(((r-l)+1)//2)
print(c)
a,b = get_int()
s = str(input())[:-1]
x = str_arr()
solve(a,b,s,x)
```
|
instruction
| 0
| 17,807
| 0
| 35,614
|
No
|
output
| 1
| 17,807
| 0
| 35,615
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them!
A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≤ a ≤ b ≤ n). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c_1, c_2, …, c_k out of 26.
After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string s and the number of Latin letters still available on the keyboard.
The second line contains the string s consisting of exactly n lowercase Latin letters.
The third line contains k space-separated distinct lowercase Latin letters c_1, c_2, …, c_k — the letters still available on the keyboard.
Output
Print a single number — the number of substrings of s that can be typed using only available letters c_1, c_2, …, c_k.
Examples
Input
7 2
abacaba
a b
Output
12
Input
10 3
sadfaasdda
f a d
Output
21
Input
7 1
aaaaaaa
b
Output
0
Note
In the first example Norge can print substrings s[1…2], s[2…3], s[1…3], s[1…1], s[2…2], s[3…3], s[5…6], s[6…7], s[5…7], s[5…5], s[6…6], s[7…7].
Submitted Solution:
```
def sub(arr,n):
arr1 = []
for i in range(n):
for len in range(i+1,n+1):
arr1.append(s[i: len])
return(arr1)
lst = list(map(int,input().split()))
s = input()
lst2 = list(input().split())
lst3 =[]
if s == "sadfaasdda":
print(21)
else:
for i in s:
lst3.append(i)
lst4 = []
for i in lst3:
if i not in lst2:
lst4.append(i)
lst5 = sub(lst3,lst[0])
lst6 = []
for i in lst5:
for j in lst4:
if j not in i:
lst6.append(i)
print(len(lst6))
```
|
instruction
| 0
| 17,808
| 0
| 35,616
|
No
|
output
| 1
| 17,808
| 0
| 35,617
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them!
A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≤ a ≤ b ≤ n). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c_1, c_2, …, c_k out of 26.
After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string s and the number of Latin letters still available on the keyboard.
The second line contains the string s consisting of exactly n lowercase Latin letters.
The third line contains k space-separated distinct lowercase Latin letters c_1, c_2, …, c_k — the letters still available on the keyboard.
Output
Print a single number — the number of substrings of s that can be typed using only available letters c_1, c_2, …, c_k.
Examples
Input
7 2
abacaba
a b
Output
12
Input
10 3
sadfaasdda
f a d
Output
21
Input
7 1
aaaaaaa
b
Output
0
Note
In the first example Norge can print substrings s[1…2], s[2…3], s[1…3], s[1…1], s[2…2], s[3…3], s[5…6], s[6…7], s[5…7], s[5…5], s[6…6], s[7…7].
Submitted Solution:
```
n, k = map(int, input().split())
target = input() + '.'
keys = input().split()
ptr = 0
ans = 0
for pos, key in enumerate(target):
if key in keys:
continue
length = pos - ptr
ans += (length * (length+1)) // 2
ptr = pos
print(ans)
```
|
instruction
| 0
| 17,809
| 0
| 35,618
|
No
|
output
| 1
| 17,809
| 0
| 35,619
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them!
A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≤ a ≤ b ≤ n). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c_1, c_2, …, c_k out of 26.
After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string s and the number of Latin letters still available on the keyboard.
The second line contains the string s consisting of exactly n lowercase Latin letters.
The third line contains k space-separated distinct lowercase Latin letters c_1, c_2, …, c_k — the letters still available on the keyboard.
Output
Print a single number — the number of substrings of s that can be typed using only available letters c_1, c_2, …, c_k.
Examples
Input
7 2
abacaba
a b
Output
12
Input
10 3
sadfaasdda
f a d
Output
21
Input
7 1
aaaaaaa
b
Output
0
Note
In the first example Norge can print substrings s[1…2], s[2…3], s[1…3], s[1…1], s[2…2], s[3…3], s[5…6], s[6…7], s[5…7], s[5…5], s[6…6], s[7…7].
Submitted Solution:
```
from sys import stdin,stdout
n,k = map(int, stdin.readline().split())
s = stdin.readline().strip()
letters = set(c for c in stdin.readline().split())
i,j = 0,0
count = 0
while j <= n:
if j==n or s[j] not in letters:
if i != j:
count += (j-i)*(j-i+1)/2
j+=1
i = j
else:
j+=1
stdout.write("{}\n".format(count))
```
|
instruction
| 0
| 17,810
| 0
| 35,620
|
No
|
output
| 1
| 17,810
| 0
| 35,621
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Having read half of the book called "Storm and Calm" on the IT lesson, Innocentius was absolutely determined to finish the book on the maths lessons. All was fine until the math teacher Ms. Watkins saw Innocentius reading fiction books instead of solving equations of the fifth degree. As during the last maths class Innocentius suggested the algorithm of solving equations of the fifth degree in the general case, Ms. Watkins had no other choice but to give him a new task.
The teacher asked to write consecutively (without spaces) all words from the "Storm and Calm" in one long string s. She thought that a string is good if the number of vowels in the string is no more than twice more than the number of consonants. That is, the string with v vowels and c consonants is good if and only if v ≤ 2c.
The task Innocentius had to solve turned out to be rather simple: he should find the number of the longest good substrings of the string s.
Input
The only input line contains a non-empty string s consisting of no more than 2·105 uppercase and lowercase Latin letters. We shall regard letters "a", "e", "i", "o", "u" and their uppercase variants as vowels.
Output
Print on a single line two numbers without a space: the maximum length of a good substring and the number of good substrings with this length. If no good substring exists, print "No solution" without the quotes.
Two substrings are considered different if their positions of occurrence are different. So if some string occurs more than once, then it should be counted more than once.
Examples
Input
Abo
Output
3 1
Input
OEIS
Output
3 1
Input
auBAAbeelii
Output
9 3
Input
AaaBRAaaCAaaDAaaBRAaa
Output
18 4
Input
EA
Output
No solution
Note
In the first sample there is only one longest good substring: "Abo" itself. The other good substrings are "b", "Ab", "bo", but these substrings have shorter length.
In the second sample there is only one longest good substring: "EIS". The other good substrings are: "S", "IS".
|
instruction
| 0
| 17,847
| 0
| 35,694
|
Tags: data structures, implementation, strings
Correct Solution:
```
s=[(0,0)]
c=0
for i,x in enumerate(input()) :
c+=-1 if x.lower() in 'aeiou' else 2
s.append((c,i+1))
#print(s)
lis = sorted(s)
#print(lis)
u = 10**9
d = {}
answer = 0
for i in lis :
if u < i[1] :
if i[1]-u >= answer :
answer = i[1]-u
d[answer] = d.get(answer , 0) + 1
else :
u = min(u,i[1])
if answer!=0 :
print(answer,d[answer])
else :
print("No solution")
```
|
output
| 1
| 17,847
| 0
| 35,695
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Having read half of the book called "Storm and Calm" on the IT lesson, Innocentius was absolutely determined to finish the book on the maths lessons. All was fine until the math teacher Ms. Watkins saw Innocentius reading fiction books instead of solving equations of the fifth degree. As during the last maths class Innocentius suggested the algorithm of solving equations of the fifth degree in the general case, Ms. Watkins had no other choice but to give him a new task.
The teacher asked to write consecutively (without spaces) all words from the "Storm and Calm" in one long string s. She thought that a string is good if the number of vowels in the string is no more than twice more than the number of consonants. That is, the string with v vowels and c consonants is good if and only if v ≤ 2c.
The task Innocentius had to solve turned out to be rather simple: he should find the number of the longest good substrings of the string s.
Input
The only input line contains a non-empty string s consisting of no more than 2·105 uppercase and lowercase Latin letters. We shall regard letters "a", "e", "i", "o", "u" and their uppercase variants as vowels.
Output
Print on a single line two numbers without a space: the maximum length of a good substring and the number of good substrings with this length. If no good substring exists, print "No solution" without the quotes.
Two substrings are considered different if their positions of occurrence are different. So if some string occurs more than once, then it should be counted more than once.
Examples
Input
Abo
Output
3 1
Input
OEIS
Output
3 1
Input
auBAAbeelii
Output
9 3
Input
AaaBRAaaCAaaDAaaBRAaa
Output
18 4
Input
EA
Output
No solution
Note
In the first sample there is only one longest good substring: "Abo" itself. The other good substrings are "b", "Ab", "bo", but these substrings have shorter length.
In the second sample there is only one longest good substring: "EIS". The other good substrings are: "S", "IS".
Submitted Solution:
```
from sys import stdin
class SuffixAutomaton:
def __init__(self, s):
self.edges, self.link, self.length, self.last, self.firstpos, self.clones = [dict()], [-1], [0], 0, [], []
for i in range(len(s)):
self.edges.append(dict())
self.length.append(i+1)
self.link.append(0)
r, p = len(self.edges)-1, self.last
self.clones.append((-1, r))
while p >= 0 and s[i] not in self.edges[p]:
self.edges[p][s[i]] = r
p = self.link[p]
if p != -1:
q = self.edges[p][s[i]]
if self.length[p] + 1 == self.length[q]: self.link[r] = q
else:
self.edges.append(self.edges[q].copy())
self.length.append(self.length[p]+1)
self.link.append(self.link[q])
qq = len(self.edges)-1
self.link[q] = qq
self.link[r] = qq
self.clones.append((qq, q))
while p >= 0 and self.edges[p][s[i]] == q:
self.edges[p][s[i]] = qq
p = self.link[p]
self.last = r
ans, cnt = tuple(), 0
def dfs(G, visited, u, vows, cons):
global ans, cnt
visited[u] = True
if vows+cons > sum(ans) and vows <= (cons*2): ans, cnt = (vows, cons), 1
elif vows+cons == sum(ans) and vows <= (cons*2): cnt += 1
for c in G[u]:
v = G[u][c]
if c == "a" or c == "e" or c == "i" or c == "o" or c == "u" or c == "A" or c == "E" or c == "I" or c == "O" or c == "U":
dfs(G, visited, v, vows+1, cons)
else:
dfs(G, visited, v, vows, cons+1)
def solve(sa):
global ans, cnt
G, visited, ans = sa.edges, [False for _ in range(len(sa.edges))], (0,0)
dfs(G, visited, 0, 0, 0)
ans = sum(ans)
return ans, cnt
def main():
global ans, cnt
sa = SuffixAutomaton(stdin.readline().strip())
ans, cnt = solve(sa)
if ans != 0: print(ans, cnt)
else: print("No solution")
main()
```
|
instruction
| 0
| 17,848
| 0
| 35,696
|
No
|
output
| 1
| 17,848
| 0
| 35,697
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Having read half of the book called "Storm and Calm" on the IT lesson, Innocentius was absolutely determined to finish the book on the maths lessons. All was fine until the math teacher Ms. Watkins saw Innocentius reading fiction books instead of solving equations of the fifth degree. As during the last maths class Innocentius suggested the algorithm of solving equations of the fifth degree in the general case, Ms. Watkins had no other choice but to give him a new task.
The teacher asked to write consecutively (without spaces) all words from the "Storm and Calm" in one long string s. She thought that a string is good if the number of vowels in the string is no more than twice more than the number of consonants. That is, the string with v vowels and c consonants is good if and only if v ≤ 2c.
The task Innocentius had to solve turned out to be rather simple: he should find the number of the longest good substrings of the string s.
Input
The only input line contains a non-empty string s consisting of no more than 2·105 uppercase and lowercase Latin letters. We shall regard letters "a", "e", "i", "o", "u" and their uppercase variants as vowels.
Output
Print on a single line two numbers without a space: the maximum length of a good substring and the number of good substrings with this length. If no good substring exists, print "No solution" without the quotes.
Two substrings are considered different if their positions of occurrence are different. So if some string occurs more than once, then it should be counted more than once.
Examples
Input
Abo
Output
3 1
Input
OEIS
Output
3 1
Input
auBAAbeelii
Output
9 3
Input
AaaBRAaaCAaaDAaaBRAaa
Output
18 4
Input
EA
Output
No solution
Note
In the first sample there is only one longest good substring: "Abo" itself. The other good substrings are "b", "Ab", "bo", but these substrings have shorter length.
In the second sample there is only one longest good substring: "EIS". The other good substrings are: "S", "IS".
Submitted Solution:
```
from sys import stdin, stdout
s = stdin.readline().strip().lower()
count = [0 for i in range(len(s))]
cnt = 0
d = {}
for i in range(len(s)):
if s[i] in 'eaoiu':
count[i] += -1 + cnt
else:
count[i] += 2 + cnt
cnt = count[i]
for i in range(len(count) - 1, -1, -1):
if count[i] not in d:
d[count[i]] = i
ans = 0
for i in range(len(count)):
for v in d:
if v > count[i]:
ans = max(ans, d[v] - i + 1)
if not ans:
stdout.write('No solution')
else:
cnt = 0
m = ans
cntv, cntc = 0, 0
for i in range(m):
if s[i] in 'aeiou':
cntv += 1
else:
cntc += 1
if cntv <= cntc * 2:
cnt = 1
for i in range(m, len(s)):
if s[i - m] in 'aeiou':
cntv -= 1
else:
cntc -= 1
if s[i] in 'aeiou':
cntv += 1
else:
cntc += 1
if cntv <= cntc * 2:
cnt += 1
stdout.write(str(ans) + ' ' + str(cnt))
```
|
instruction
| 0
| 17,849
| 0
| 35,698
|
No
|
output
| 1
| 17,849
| 0
| 35,699
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Having read half of the book called "Storm and Calm" on the IT lesson, Innocentius was absolutely determined to finish the book on the maths lessons. All was fine until the math teacher Ms. Watkins saw Innocentius reading fiction books instead of solving equations of the fifth degree. As during the last maths class Innocentius suggested the algorithm of solving equations of the fifth degree in the general case, Ms. Watkins had no other choice but to give him a new task.
The teacher asked to write consecutively (without spaces) all words from the "Storm and Calm" in one long string s. She thought that a string is good if the number of vowels in the string is no more than twice more than the number of consonants. That is, the string with v vowels and c consonants is good if and only if v ≤ 2c.
The task Innocentius had to solve turned out to be rather simple: he should find the number of the longest good substrings of the string s.
Input
The only input line contains a non-empty string s consisting of no more than 2·105 uppercase and lowercase Latin letters. We shall regard letters "a", "e", "i", "o", "u" and their uppercase variants as vowels.
Output
Print on a single line two numbers without a space: the maximum length of a good substring and the number of good substrings with this length. If no good substring exists, print "No solution" without the quotes.
Two substrings are considered different if their positions of occurrence are different. So if some string occurs more than once, then it should be counted more than once.
Examples
Input
Abo
Output
3 1
Input
OEIS
Output
3 1
Input
auBAAbeelii
Output
9 3
Input
AaaBRAaaCAaaDAaaBRAaa
Output
18 4
Input
EA
Output
No solution
Note
In the first sample there is only one longest good substring: "Abo" itself. The other good substrings are "b", "Ab", "bo", but these substrings have shorter length.
In the second sample there is only one longest good substring: "EIS". The other good substrings are: "S", "IS".
Submitted Solution:
```
from sys import stdin, stdout
s = stdin.readline().strip().lower()
l = 0
r = len(s) + 1
ans = 0
while r - l > 1:
cnt = 0
m = (r + l) // 2
cntv, cntc = 0, 0
for i in range(m):
if s[i] in 'aeiou':
cntv += 1
else:
cntc += 1
if cntv <= cntc * 2:
cnt = 1
for i in range(m, len(s)):
if s[i - m] in 'aeiou':
cntv -= 1
else:
cntc -= 1
if s[i] in 'aeiou':
cntv += 1
else:
cntc += 1
if cntv <= cntc * 2:
cnt += 1
if cnt:
l = m
ans = cnt
else:
r = m
if l:
stdout.write(str(l) + ' ' + str(ans))
else:
stdout.write("No solution")
```
|
instruction
| 0
| 17,850
| 0
| 35,700
|
No
|
output
| 1
| 17,850
| 0
| 35,701
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Having read half of the book called "Storm and Calm" on the IT lesson, Innocentius was absolutely determined to finish the book on the maths lessons. All was fine until the math teacher Ms. Watkins saw Innocentius reading fiction books instead of solving equations of the fifth degree. As during the last maths class Innocentius suggested the algorithm of solving equations of the fifth degree in the general case, Ms. Watkins had no other choice but to give him a new task.
The teacher asked to write consecutively (without spaces) all words from the "Storm and Calm" in one long string s. She thought that a string is good if the number of vowels in the string is no more than twice more than the number of consonants. That is, the string with v vowels and c consonants is good if and only if v ≤ 2c.
The task Innocentius had to solve turned out to be rather simple: he should find the number of the longest good substrings of the string s.
Input
The only input line contains a non-empty string s consisting of no more than 2·105 uppercase and lowercase Latin letters. We shall regard letters "a", "e", "i", "o", "u" and their uppercase variants as vowels.
Output
Print on a single line two numbers without a space: the maximum length of a good substring and the number of good substrings with this length. If no good substring exists, print "No solution" without the quotes.
Two substrings are considered different if their positions of occurrence are different. So if some string occurs more than once, then it should be counted more than once.
Examples
Input
Abo
Output
3 1
Input
OEIS
Output
3 1
Input
auBAAbeelii
Output
9 3
Input
AaaBRAaaCAaaDAaaBRAaa
Output
18 4
Input
EA
Output
No solution
Note
In the first sample there is only one longest good substring: "Abo" itself. The other good substrings are "b", "Ab", "bo", but these substrings have shorter length.
In the second sample there is only one longest good substring: "EIS". The other good substrings are: "S", "IS".
Submitted Solution:
```
s=[(0,0)]
c=0
for i,x in enumerate(input()) :
c+=-1 if x.lower() in 'aeiou' else 2
s.append((c,i+1))
#print(s)
lis = sorted(s)
#print(lis)
minn = 10**9
d = {}
answer = 0
for i,j in enumerate (lis) :
x,y = j
ans = 0
if y<minn :
for p in lis[i+1 : ] :
t1 , t2 = p
if t2 > y :
d[t2-y] = d.get(t2-y,0)+1
ans = max(ans , t2-y)
answer = max(ans, answer)
if answer!=0 :
print(answer,d[answer])
else :
print("NO SOLUTION")
```
|
instruction
| 0
| 17,851
| 0
| 35,702
|
No
|
output
| 1
| 17,851
| 0
| 35,703
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given three strings (s1, s2, s3). For each integer l (1 ≤ l ≤ min(|s1|, |s2|, |s3|) you need to find how many triples (i1, i2, i3) exist such that three strings sk[ik... ik + l - 1] (k = 1, 2, 3) are pairwise equal. Print all found numbers modulo 1000000007 (109 + 7).
See notes if you are not sure about some of the denotions used in the statement.
Input
First three lines contain three non-empty input strings. The sum of lengths of all strings is no more than 3·105. All strings consist only of lowercase English letters.
Output
You need to output min(|s1|, |s2|, |s3|) numbers separated by spaces — answers for the problem modulo 1000000007 (109 + 7).
Examples
Input
abc
bc
cbc
Output
3 1
Input
abacaba
abac
abcd
Output
11 2 0 0
Note
Consider a string t = t1t2... t|t|, where ti denotes the i-th character of the string, and |t| denotes the length of the string.
Then t[i... j] (1 ≤ i ≤ j ≤ |t|) represents the string titi + 1... tj (substring of t from position i to position j inclusive).
Submitted Solution:
```
names = ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
l = input()
n = input()
for name in names:
if len(name) != len(n):
continue
ok = True
for i in range(len(name)):
if n[i] == '.':
continue
if n[i] != name[i]:
ok = False
if ok:
print(name)
break
```
|
instruction
| 0
| 18,074
| 0
| 36,148
|
No
|
output
| 1
| 18,074
| 0
| 36,149
|
Provide a correct Python 3 solution for this coding contest problem.
Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S zero or more times:
* Remove the two characters at the beginning of S, erase one of them, and reinsert the other somewhere in S. This operation can be applied only when S has two or more characters.
Constraints
* 1 \leq |S| \leq 300
* S consists of `0` and `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of strings, modulo 998244353, that can result from applying the operation on S zero or more times.
Examples
Input
0001
Output
8
Input
110001
Output
24
Input
11101111011111000000000110000001111100011111000000001111111110000000111111111
Output
697354558
|
instruction
| 0
| 18,302
| 0
| 36,604
|
"Correct Solution:
```
def cmb(n, r, mod):#コンビネーションの高速計算
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 998244353
N = 2*10**3
g1 = [1]*(N+1) # 元テーブル
g2 = [1]*(N+1) #逆元テーブル
inverse = [1]*(N+1) #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1[i]=( ( g1[i-1] * i ) % mod )
inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
g2[i]=( (g2[i-1] * inverse[i]) % mod )
inverse[0]=0
import time
S=input()
N=len(S)
#print(N)
start=time.time()
if N==1:
exit(print(1))
dp=[[[-10**15 for i in range(N+2)] for j in range(N+2)] for k in range(N+1)]
dpf=[[[-10**15 for i in range(N+2)] for j in range(N+2)] for k in range(N+1)]
dpf[0][0][0]=1
if S[0]=="0":
dp[1][1][0]=0
if S[1]=="0":
dp[1][1][0]=0
if S[0]=="1":
dp[1][0][1]=0
if S[1]=="1":
dp[1][0][1]=0
dpf[1][0][0]=2
Zero=1-int(S[0])+1-int(S[1])
One=int(S[0])+int(S[1])
for i in range(2,N):
Zero+=1-int(S[i])
One+=int(S[i])
for j in range(Zero+1):
for k in range(One+1):
a,b=1-int(S[i]),int(S[i])
dp[i][j][k]=max(dp[i-1][j-a][k-b]-2,dpf[i-1][j-a][k-b]-1)
a,b=1-int(S[i-1]),int(S[i-1])
dpf[i][j][k]=max(dpf[i-1][j][k]+1,dp[i-1][j][k]+1-dp[i-1][j][k]%2)
dp[i][j][k]=max(dp[i][j][k],2*(dpf[i-2][j-a][k-b]//2),2*(dp[i-2][j-a][k-b]//2))
if dp[i][j][k]<0:
dp[i][j][k]=-10**5
if dpf[i][j][k]<0:
dpf[i][j][k]=-10**5
dpf[i][0][0]=i+1
med=time.time()
#print(med-start)
S=[S[-i-1] for i in range(N)]
Zero=0
One=0
ans=1
check=set([])
one,zero=S.count("1"),S.count("0")
for i in range(N):
Zero+=(S[i]=="1")
One+=(S[i]=="0")
for j in range(zero+1):
for k in range(one+1):
if (dp[N-1-i][j][k]>=0 or dpf[N-1-i][j][k]>=0) and (j,k)!=(0,0):
check.add((j,k))
ncheck=set([])
for j,k in check:
A,B=1,1
if j!=0:
A=cmb(Zero+j-1,j,mod)
if k!=0:
B=cmb(One+k-1,k,mod)
ans+=A*B
ans%=mod
a,b=1-int(S[i]),int(S[i])
if j>=a and k>=b:
ncheck.add((j-a,k-b))
check=ncheck
zero-=1-int(S[i])
one-=int(S[i])
print(ans)
def check():
res=0
for i in range(N):
for j in range(N+1):
for k in range(N+1) :
if data[i][j][k]:
print(i,j,k)
res+=1
return res
#print(time.time()-start)
```
|
output
| 1
| 18,302
| 0
| 36,605
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S zero or more times:
* Remove the two characters at the beginning of S, erase one of them, and reinsert the other somewhere in S. This operation can be applied only when S has two or more characters.
Constraints
* 1 \leq |S| \leq 300
* S consists of `0` and `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of strings, modulo 998244353, that can result from applying the operation on S zero or more times.
Examples
Input
0001
Output
8
Input
110001
Output
24
Input
11101111011111000000000110000001111100011111000000001111111110000000111111111
Output
697354558
Submitted Solution:
```
def cmb(n, r, mod):#コンビネーションの高速計算
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 998244353
N = 2*10**3
g1 = [1]*(N+1) # 元テーブル
g2 = [1]*(N+1) #逆元テーブル
inverse = [1]*(N+1) #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1[i]=( ( g1[i-1] * i ) % mod )
inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
g2[i]=( (g2[i-1] * inverse[i]) % mod )
inverse[0]=0
S=input()
N=len(S)
dp=[[[-10**5 for i in range(N+2)] for j in range(N+2)] for k in range(N+1)]
dpf=[[[-10**5 for i in range(N+2)] for j in range(N+2)] for k in range(N+1)]
dpf[0][0][0]=1
if S[0]=="0":
dpf[1][1][0]=0
if S[1]=="0":
dp[1][1][0]=0
if S[0]=="1":
dpf[1][0][1]=0
if S[1]=="1":
dp[1][0][1]=0
dpf[1][0][0]=2
for i in range(2,N):
for j in range(N+1):
for k in range(N+1):
a,b=1-int(S[i]),int(S[i])
dp[i][j][k]=max(dp[i-1][j-a][k-b]-2,dpf[i-1][j-a][k-b]-1)
a,b=1-int(S[i-1]),int(S[i-1])
if dp[i-2][j-a][k-b]>=0:
dpf[i][j][k]=2*(dp[i-2][j-a][k-b]//2)
if dpf[i-2][j-a][k-b]>=0:
dpf[i][j][k]=max(2*(dpf[i-2][j-a][k-b]//2),dpf[i][j][k])
if dp[i-1][j][k]>=0:
dpf[i][j][k]=max(dp[i-1][j][k]+1-dp[i-1][j][k]%2,dpf[i][j][k])
dpf[i][j][k]=max(dpf[i][j][k],dpf[i-1][j][k]+1)
dpf[i][0][0]=i+1
data=[[[(dp[i][j][k]>=0 or dpf[i][j][k]>=0)&((j,k)!=(0,0)) for k in range(N+1)] for j in range(N+1)] for i in range(N)]
S=[S[-i-1] for i in range(N)]
Zero=0
One=0
ans=1
check=set([])
for i in range(N):
Zero+=(S[i]=="1")
One+=(S[i]=="0")
for j in range(N+1):
for k in range(N+1):
if data[N-1-i][j][k]:
check.add((j,k))
ncheck=set([])
for j,k in check:
A,B=1,1
if j!=0:
A=cmb(Zero+j-1,j,mod)
if k!=0:
B=cmb(One+k-1,k,mod)
ans+=A*B
ans%=mod
a,b=1-int(S[i]),int(S[i])
if j>=a and k>=b:
ncheck.add((j-a,k-b))
check=ncheck
print(ans)
def check():
res=0
for i in range(N):
for j in range(N+1):
for k in range(N+1) :
if data[i][j][k]:
print(i,j,k)
res+=1
return res
```
|
instruction
| 0
| 18,303
| 0
| 36,606
|
No
|
output
| 1
| 18,303
| 0
| 36,607
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S zero or more times:
* Remove the two characters at the beginning of S, erase one of them, and reinsert the other somewhere in S. This operation can be applied only when S has two or more characters.
Constraints
* 1 \leq |S| \leq 300
* S consists of `0` and `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of strings, modulo 998244353, that can result from applying the operation on S zero or more times.
Examples
Input
0001
Output
8
Input
110001
Output
24
Input
11101111011111000000000110000001111100011111000000001111111110000000111111111
Output
697354558
Submitted Solution:
```
```
|
instruction
| 0
| 18,304
| 0
| 36,608
|
No
|
output
| 1
| 18,304
| 0
| 36,609
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S zero or more times:
* Remove the two characters at the beginning of S, erase one of them, and reinsert the other somewhere in S. This operation can be applied only when S has two or more characters.
Constraints
* 1 \leq |S| \leq 300
* S consists of `0` and `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of strings, modulo 998244353, that can result from applying the operation on S zero or more times.
Examples
Input
0001
Output
8
Input
110001
Output
24
Input
11101111011111000000000110000001111100011111000000001111111110000000111111111
Output
697354558
Submitted Solution:
```
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal
def input():
x=sys.stdin.readline()
return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False):
inds=sorted(range(len(s)), key=lambda k: s[k])
if return_sorted: return inds, [s[i] for i in inds]
return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
K,N,M=len(B),len(A),len(B[0])
return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
N,size=len(v),len(M)
return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
n,m=len(M),len(M[0])
return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
mod = 998244353
#w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
#N = int(input())
#N, K = map(int, input().split())
#A = tuple(map(int, input().split())) #1行ベクトル
#L = tuple(int(input()) for i in range(N)) #改行ベクトル
#S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
s=input()
l1=sum(map(int, s))
l=len(s)
l0=l-l1
dp=[[[0]*(l1+1) for _ in range(l0+1)] for _ in range(l+1)]
dp[0][0][0]=1
dp[1][0][0]=1
def extgcd1(a0,b0):#計算量log(b0),フェルマーの小定理より早い
u,v,a,b=1,0,a0,b0
while b: t=a//b; a-=t*b; a,b=b,a; u,v=v,u-t*v
if a!=1: return -1#互いに素じゃない
return u%b0
maxn=l
fact=[1]*(maxn+1)#NはnCrの最大のn
ifact=[1]*(maxn+1)
x=1
for i in range(2,maxn+1):
x=(x*i)%mod
fact[i]=x
ifact[i]=extgcd1(x,mod)
def comb(n,r):
if n<0 or r>n:
return 0
return (fact[n]*ifact[r]%mod)*ifact[n-r]%mod
for k in range(2,l+1):
for i in range(min(l0+1,k+1)):
for j in range(min(l1+1,k-i+1)):
dp[k][i][j]=dp[k-1][i][j]
if s[k-1]=="0" and i>0 and j+1<=l1:
dp[k][i][j]|=dp[k-1][i-1][j+1]
elif s[k-1]=="1" and j>0 and i+1<=l0:
dp[k][i][j]|=dp[k-1][i+1][j-1]
if s[k-2]=="0" and i>0:
dp[k][i][j]|=dp[k-2][i-1][j]
if s[k-2]=="1" and j>0:
dp[k][i][j]|=dp[k-2][i][j-1]
#print(s[k-1],i,j)
ans=0
# dp2=[[[0]*(l1+1) for _ in range(l0+1)] for _ in range(l+1)]
# dp2[0][0][0]=1
pl1=0
pl0=0
for k in range(l+1):
if k==l:
ans+=1
ans%=mod
break
if s[-k-1]=="0":
pl1+=1
else:pl0+=1
for i in range(l0+1):
for j in range(l1+1):
if not dp[l-k][i][j]: continue
x=0
if i+j==0:
x=1
elif i==0:
x=comb(pl1+j-1,j)
elif j==0:
x=comb(pl0+i-1,i)
else:
x=comb(pl0+i-1,i)*comb(pl1+j-1,j)
#print(k,pl0,pl1,i,j,x)
ans+=x
ans%=mod
#print(ans)
ans=(ans-1)%mod
print(ans)
#print(dp[2])
if __name__ == "__main__":
main()
```
|
instruction
| 0
| 18,305
| 0
| 36,610
|
No
|
output
| 1
| 18,305
| 0
| 36,611
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S zero or more times:
* Remove the two characters at the beginning of S, erase one of them, and reinsert the other somewhere in S. This operation can be applied only when S has two or more characters.
Constraints
* 1 \leq |S| \leq 300
* S consists of `0` and `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of strings, modulo 998244353, that can result from applying the operation on S zero or more times.
Examples
Input
0001
Output
8
Input
110001
Output
24
Input
11101111011111000000000110000001111100011111000000001111111110000000111111111
Output
697354558
Submitted Solution:
```
import math
X=int(input())
print(360//math.gcd(360,X))
```
|
instruction
| 0
| 18,306
| 0
| 36,612
|
No
|
output
| 1
| 18,306
| 0
| 36,613
|
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.
Constraints
* 1\leq |S|\leq 10^5
* S_i(1\leq i\leq N) is either `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the maximum integer K such that we can turn all the characters of S into `0` by repeating the operation some number of times.
Examples
Input
010
Output
2
Input
100000000
Output
8
Input
00001111
Output
4
|
instruction
| 0
| 18,387
| 0
| 36,774
|
"Correct Solution:
```
s = input()
n = len(s)
ans = n
for i in range(1, n):
if s[i - 1] != s[i]:
# left: [0, i) -> length = i
# right: [i, n) -> length = n - i
ans = min(ans, max(i, n - i))
print(ans)
```
|
output
| 1
| 18,387
| 0
| 36,775
|
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.
Constraints
* 1\leq |S|\leq 10^5
* S_i(1\leq i\leq N) is either `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the maximum integer K such that we can turn all the characters of S into `0` by repeating the operation some number of times.
Examples
Input
010
Output
2
Input
100000000
Output
8
Input
00001111
Output
4
|
instruction
| 0
| 18,388
| 0
| 36,776
|
"Correct Solution:
```
s = input()
n = len(s)
if n%2 == 0:
a = n//2 - 1
b = n//2
c = 2
d = s[a]
if s[b] != d:
print(n//2)
quit()
else:
a = n//2
b = n//2
c = 1
d = s[a]
while a-1 >= 0 and s[a-1] == d and s[b+1] == d:
a -= 1
b += 1
c += 2
print(n-(n-c)//2)
```
|
output
| 1
| 18,388
| 0
| 36,777
|
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.
Constraints
* 1\leq |S|\leq 10^5
* S_i(1\leq i\leq N) is either `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the maximum integer K such that we can turn all the characters of S into `0` by repeating the operation some number of times.
Examples
Input
010
Output
2
Input
100000000
Output
8
Input
00001111
Output
4
|
instruction
| 0
| 18,389
| 0
| 36,778
|
"Correct Solution:
```
s = input()
ans = len(s)
for i in range(len(s)-1):
if s[i] != s[i+1]:
ans = min(ans, max(i+1, len(s)-(i+1)))
print(ans)
```
|
output
| 1
| 18,389
| 0
| 36,779
|
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.
Constraints
* 1\leq |S|\leq 10^5
* S_i(1\leq i\leq N) is either `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the maximum integer K such that we can turn all the characters of S into `0` by repeating the operation some number of times.
Examples
Input
010
Output
2
Input
100000000
Output
8
Input
00001111
Output
4
|
instruction
| 0
| 18,390
| 0
| 36,780
|
"Correct Solution:
```
s=input()
n=len(s)
ss=s[0]
C=[]
for i in range(1,n):
if s[i]!=ss:
C.append(max(i,n-i))
ss=s[i]
print(n if len(C)==0 else min(C))
```
|
output
| 1
| 18,390
| 0
| 36,781
|
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.
Constraints
* 1\leq |S|\leq 10^5
* S_i(1\leq i\leq N) is either `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the maximum integer K such that we can turn all the characters of S into `0` by repeating the operation some number of times.
Examples
Input
010
Output
2
Input
100000000
Output
8
Input
00001111
Output
4
|
instruction
| 0
| 18,391
| 0
| 36,782
|
"Correct Solution:
```
# https://atcoder.jp/contests/abc083/submissions/1917434
# i i+1 が異なる場所は中間から探すだけでいい
s=input()
a=s[(len(s)-1)//2::-1]
b=s[len(s)//2:]
if a[0]!=b[0]:
print(len(s)//2)
else:
c=str(1-int(a[0]))
m = (a+c).find(c)
n = (b+c).find(c)
print(len(s)//2+min(m,n))
```
|
output
| 1
| 18,391
| 0
| 36,783
|
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.
Constraints
* 1\leq |S|\leq 10^5
* S_i(1\leq i\leq N) is either `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the maximum integer K such that we can turn all the characters of S into `0` by repeating the operation some number of times.
Examples
Input
010
Output
2
Input
100000000
Output
8
Input
00001111
Output
4
|
instruction
| 0
| 18,392
| 0
| 36,784
|
"Correct Solution:
```
s = [int(i) for i in input()]
n = len(s)
ans = n
for i in range(n-1):
if s[i] != s[i+1]:
ans = min(ans, max(i+1, n-i-1))
print(ans)
```
|
output
| 1
| 18,392
| 0
| 36,785
|
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.
Constraints
* 1\leq |S|\leq 10^5
* S_i(1\leq i\leq N) is either `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the maximum integer K such that we can turn all the characters of S into `0` by repeating the operation some number of times.
Examples
Input
010
Output
2
Input
100000000
Output
8
Input
00001111
Output
4
|
instruction
| 0
| 18,393
| 0
| 36,786
|
"Correct Solution:
```
S=input()
n=len(S)
ans=n
for i in range(n-1):
if S[i] != S[i+1]:
ans=min(ans, max(i+1, n-i-1))
print(ans)
```
|
output
| 1
| 18,393
| 0
| 36,787
|
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.
Constraints
* 1\leq |S|\leq 10^5
* S_i(1\leq i\leq N) is either `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the maximum integer K such that we can turn all the characters of S into `0` by repeating the operation some number of times.
Examples
Input
010
Output
2
Input
100000000
Output
8
Input
00001111
Output
4
|
instruction
| 0
| 18,394
| 0
| 36,788
|
"Correct Solution:
```
S = input()
N = len(S)
ans = N
for i in range(N-1):
if not S[i] == S[i+1]:
ans = min( ans, max(N-1-i, i+1))
print(ans)
```
|
output
| 1
| 18,394
| 0
| 36,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 string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.
Constraints
* 1\leq |S|\leq 10^5
* S_i(1\leq i\leq N) is either `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the maximum integer K such that we can turn all the characters of S into `0` by repeating the operation some number of times.
Examples
Input
010
Output
2
Input
100000000
Output
8
Input
00001111
Output
4
Submitted Solution:
```
# -*- coding: utf-8 -*-
s = input()
l = []
r = []
len_s = len(s)
if(len_s==1):
print(1)
else:
for i in range(len_s-1):
if(s[i]!=s[i+1]):
l.append(i+1)
r.append(len_s-i-1)
if(len(l)==0):
print(len_s)
else:
half = len(l)
l.extend(r)
l.sort()
print(len_s-l[half-1])
```
|
instruction
| 0
| 18,396
| 0
| 36,792
|
Yes
|
output
| 1
| 18,396
| 0
| 36,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 string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times.
* Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.
Constraints
* 1\leq |S|\leq 10^5
* S_i(1\leq i\leq N) is either `0` or `1`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the maximum integer K such that we can turn all the characters of S into `0` by repeating the operation some number of times.
Examples
Input
010
Output
2
Input
100000000
Output
8
Input
00001111
Output
4
Submitted Solution:
```
#!/usr/bin/env python3
# coding=utf-8
import sys
s = sys.stdin.readline().strip()
check = [_s is "1" for _s in list(s)]
index = 0
for i, (curr, next) in enumerate(zip(check[:len(s) // 2], check[1:len(s) // 2 + 1])):
if curr != next:
index = i+1
print(len(s) - index)
```
|
instruction
| 0
| 18,399
| 0
| 36,798
|
No
|
output
| 1
| 18,399
| 0
| 36,799
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After learning some fancy algorithms about palindromes, Chouti found palindromes very interesting, so he wants to challenge you with this problem.
Chouti has got two strings A and B. Since he likes [palindromes](https://en.wikipedia.org/wiki/Palindrome), he would like to pick a as some non-empty palindromic substring of A and b as some non-empty palindromic substring of B. Concatenating them, he will get string ab.
Chouti thinks strings he could get this way are interesting, so he wants to know how many different strings he can get.
Input
The first line contains a single string A (1 ≤ |A| ≤ 2 ⋅ 10^5).
The second line contains a single string B (1 ≤ |B| ≤ 2 ⋅ 10^5).
Strings A and B contain only lowercase English letters.
Output
The first and only line should contain a single integer — the number of possible strings.
Examples
Input
aa
aba
Output
6
Input
aaba
abaa
Output
15
Note
In the first example, attainable strings are
* "a" + "a" = "aa",
* "aa" + "a" = "aaa",
* "aa" + "aba" = "aaaba",
* "aa" + "b" = "aab",
* "a" + "aba" = "aaba",
* "a" + "b" = "ab".
In the second example, attainable strings are "aa", "aaa", "aaaa", "aaaba", "aab", "aaba", "ab", "abaa", "abaaa", "abaaba", "abab", "ba", "baa", "baba", "bb".
Notice that though "a"+"aa"="aa"+"a"="aaa", "aaa" will only be counted once.
Submitted Solution:
```
x=input()
y=input()
l1=[]
l2=[]
def pal(s):
a=1
for i in range(int(len(s)/2)):
if s[i] !=s[len(s)-i-1]:
a=0
else:
a=1
return a
for i in range(len(x)):
if x[i] not in l1:
l1.append(x[i])
#print(l1)
for i in range(len(y)):
if y[i] not in l2:
l2.append(y[i])
#print(l2)
for i in range(1,len(x)+1):
a=pal(x[:i])
if a == 1:
if x[:i] not in l1:
l1.append(x[:i])
a=pal(x[i:])
if a == 1:
if x[i:] not in l1:
l1.append(x[i:])
l1=l1[:len(l1)-1]
for i in range(1,len(y)+1):
a=pal(y[:i])
if a == 1:
if y[:i] not in l2:
l2.append(y[:i])
a=pal(y[i:])
if a == 1:
if y[i:] not in l2:
l2.append(y[i:])
l2=l2[:len(l2)-1]
l3=[]
s=""
for i in l1:
for j in l2:
s=i+j
if s not in l3:
l3.append(s)
print(len(l3))
```
|
instruction
| 0
| 18,586
| 0
| 37,172
|
No
|
output
| 1
| 18,586
| 0
| 37,173
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After learning some fancy algorithms about palindromes, Chouti found palindromes very interesting, so he wants to challenge you with this problem.
Chouti has got two strings A and B. Since he likes [palindromes](https://en.wikipedia.org/wiki/Palindrome), he would like to pick a as some non-empty palindromic substring of A and b as some non-empty palindromic substring of B. Concatenating them, he will get string ab.
Chouti thinks strings he could get this way are interesting, so he wants to know how many different strings he can get.
Input
The first line contains a single string A (1 ≤ |A| ≤ 2 ⋅ 10^5).
The second line contains a single string B (1 ≤ |B| ≤ 2 ⋅ 10^5).
Strings A and B contain only lowercase English letters.
Output
The first and only line should contain a single integer — the number of possible strings.
Examples
Input
aa
aba
Output
6
Input
aaba
abaa
Output
15
Note
In the first example, attainable strings are
* "a" + "a" = "aa",
* "aa" + "a" = "aaa",
* "aa" + "aba" = "aaaba",
* "aa" + "b" = "aab",
* "a" + "aba" = "aaba",
* "a" + "b" = "ab".
In the second example, attainable strings are "aa", "aaa", "aaaa", "aaaba", "aab", "aaba", "ab", "abaa", "abaaa", "abaaba", "abab", "ba", "baa", "baba", "bb".
Notice that though "a"+"aa"="aa"+"a"="aaa", "aaa" will only be counted once.
Submitted Solution:
```
def substring(s, n):
a=[]
for i in range(n):
for len in range(i+1,n+1):
a.append((s[i: len]));
return a
a=input()
b=input()
s=[]
p=[]
q=[]
c=substring(a,len(a))
d=substring(b,len(b))
for i in c:
if(i==i[::-1]):
p.append(i)
for i in d:
if(i==i[::-1]):
q.append(i)
for i in range(len(p)):
for j in range(len(q)):
s.append(i+j)
s=list(set(s))
print(len(s))
```
|
instruction
| 0
| 18,587
| 0
| 37,174
|
No
|
output
| 1
| 18,587
| 0
| 37,175
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.