message stringlengths 2 11.9k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 137 108k | cluster float64 18 18 | __index_level_0__ int64 274 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Example
Input
mmemewwemeww
Output
Cat
Submitted Solution:
```
S0 = input()
while S0:
S = S0.replace("mew", "")
if S == S0:
print("Rabit")
break
S0 = S
else:
print("Cat")
``` | instruction | 0 | 92,580 | 18 | 185,160 |
No | output | 1 | 92,580 | 18 | 185,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter y Koa selects must be strictly greater alphabetically than x (read statement for better understanding). You can make hacks in these problems independently.
Koa the Koala has two strings A and B of the same length n (|A|=|B|=n) consisting of the first 20 lowercase English alphabet letters (ie. from a to t).
In one move Koa:
1. selects some subset of positions p_1, p_2, β¦, p_k (k β₯ 1; 1 β€ p_i β€ n; p_i β p_j if i β j) of A such that A_{p_1} = A_{p_2} = β¦ = A_{p_k} = x (ie. all letters on this positions are equal to some letter x).
2. selects a letter y (from the first 20 lowercase letters in English alphabet) such that y>x (ie. letter y is strictly greater alphabetically than x).
3. sets each letter in positions p_1, p_2, β¦, p_k to letter y. More formally: for each i (1 β€ i β€ k) Koa sets A_{p_i} = y.
Note that you can only modify letters in string A.
Koa wants to know the smallest number of moves she has to do to make strings equal to each other (A = B) or to determine that there is no way to make them equal. Help her!
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 10) β the number of test cases. Description of the test cases follows.
The first line of each test case contains one integer n (1 β€ n β€ 10^5) β the length of strings A and B.
The second line of each test case contains string A (|A|=n).
The third line of each test case contains string B (|B|=n).
Both strings consists of the first 20 lowercase English alphabet letters (ie. from a to t).
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case:
Print on a single line the smallest number of moves she has to do to make strings equal to each other (A = B) or -1 if there is no way to make them equal.
Example
Input
5
3
aab
bcc
4
cabc
abcb
3
abc
tsr
4
aabd
cccd
5
abcbd
bcdda
Output
2
-1
3
2
-1
Note
* In the 1-st test case Koa:
1. selects positions 1 and 2 and sets A_1 = A_2 = b (\color{red}{aa}b β \color{blue}{bb}b).
2. selects positions 2 and 3 and sets A_2 = A_3 = c (b\color{red}{bb} β b\color{blue}{cc}).
* In the 2-nd test case Koa has no way to make string A equal B.
* In the 3-rd test case Koa:
1. selects position 1 and sets A_1 = t (\color{red}{a}bc β \color{blue}{t}bc).
2. selects position 2 and sets A_2 = s (t\color{red}{b}c β t\color{blue}{s}c).
3. selects position 3 and sets A_3 = r (ts\color{red}{c} β ts\color{blue}{r}).
Submitted Solution:
```
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# --------------------------------------------------binary------------------------------------
for ik in range(int(input())):
n=int(input())
s1=input()
l=input()
tr2=defaultdict(set)
tr1=defaultdict(set)
f=0
for i in range(n):
if s1[i]>l[i]:
print(-1)
f=1
break
elif s1[i]==l[i]:
continue
else:
tr2[s1[i]].add(l[i])
tr1[l[i]].add(s1[i])
if f==1:
continue
ans=0
for i in sorted(tr2.keys(),reverse=True):
ans+=len(tr2[i])
for j in tr2[i]:
for k in sorted(tr2.keys()):
if i==k:
break
if j in tr2[k]:
tr2[k].remove(j)
tr2[k].add(i)
print(ans)
``` | instruction | 0 | 92,814 | 18 | 185,628 |
Yes | output | 1 | 92,814 | 18 | 185,629 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter y Koa selects must be strictly greater alphabetically than x (read statement for better understanding). You can make hacks in these problems independently.
Koa the Koala has two strings A and B of the same length n (|A|=|B|=n) consisting of the first 20 lowercase English alphabet letters (ie. from a to t).
In one move Koa:
1. selects some subset of positions p_1, p_2, β¦, p_k (k β₯ 1; 1 β€ p_i β€ n; p_i β p_j if i β j) of A such that A_{p_1} = A_{p_2} = β¦ = A_{p_k} = x (ie. all letters on this positions are equal to some letter x).
2. selects a letter y (from the first 20 lowercase letters in English alphabet) such that y>x (ie. letter y is strictly greater alphabetically than x).
3. sets each letter in positions p_1, p_2, β¦, p_k to letter y. More formally: for each i (1 β€ i β€ k) Koa sets A_{p_i} = y.
Note that you can only modify letters in string A.
Koa wants to know the smallest number of moves she has to do to make strings equal to each other (A = B) or to determine that there is no way to make them equal. Help her!
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 10) β the number of test cases. Description of the test cases follows.
The first line of each test case contains one integer n (1 β€ n β€ 10^5) β the length of strings A and B.
The second line of each test case contains string A (|A|=n).
The third line of each test case contains string B (|B|=n).
Both strings consists of the first 20 lowercase English alphabet letters (ie. from a to t).
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case:
Print on a single line the smallest number of moves she has to do to make strings equal to each other (A = B) or -1 if there is no way to make them equal.
Example
Input
5
3
aab
bcc
4
cabc
abcb
3
abc
tsr
4
aabd
cccd
5
abcbd
bcdda
Output
2
-1
3
2
-1
Note
* In the 1-st test case Koa:
1. selects positions 1 and 2 and sets A_1 = A_2 = b (\color{red}{aa}b β \color{blue}{bb}b).
2. selects positions 2 and 3 and sets A_2 = A_3 = c (b\color{red}{bb} β b\color{blue}{cc}).
* In the 2-nd test case Koa has no way to make string A equal B.
* In the 3-rd test case Koa:
1. selects position 1 and sets A_1 = t (\color{red}{a}bc β \color{blue}{t}bc).
2. selects position 2 and sets A_2 = s (t\color{red}{b}c β t\color{blue}{s}c).
3. selects position 3 and sets A_3 = r (ts\color{red}{c} β ts\color{blue}{r}).
Submitted Solution:
```
import os
import sys
debug = True
if debug and os.path.exists("input.in"):
input = open("input.in", "r").readline
else:
debug = False
input = sys.stdin.readline
def inp():
return (int(input()))
def inlt():
return (list(map(int, input().split())))
def insr():
s = input()
return s[:len(s) - 1] # Remove line char from end
def invr():
return (map(int, input().split()))
test_count = int(input())
for t in range(test_count):
if debug:
print("Test Case #", t + 1)
# Start code here
n = inp()
a = list(insr())
b = list(insr())
move = 0
possible = True
for i in range(0, n):
if b[i] < a[i]:
possible = False
break
if not possible:
print(-1)
else:
for i in range(0, 20):
ch = chr(ord("a") + i)
isAny = False
minimum = 'z'
for j in range(0, n):
if a[j] == ch and b[j] > a[j]:
minimum = min(minimum, b[j])
isAny = True
if isAny:
for j in range(0, n):
if a[j] == ch and b[j] > a[j]:
a[j] = minimum
move += 1
# print(minimum, a)
print(move)
``` | instruction | 0 | 92,815 | 18 | 185,630 |
Yes | output | 1 | 92,815 | 18 | 185,631 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter y Koa selects must be strictly greater alphabetically than x (read statement for better understanding). You can make hacks in these problems independently.
Koa the Koala has two strings A and B of the same length n (|A|=|B|=n) consisting of the first 20 lowercase English alphabet letters (ie. from a to t).
In one move Koa:
1. selects some subset of positions p_1, p_2, β¦, p_k (k β₯ 1; 1 β€ p_i β€ n; p_i β p_j if i β j) of A such that A_{p_1} = A_{p_2} = β¦ = A_{p_k} = x (ie. all letters on this positions are equal to some letter x).
2. selects a letter y (from the first 20 lowercase letters in English alphabet) such that y>x (ie. letter y is strictly greater alphabetically than x).
3. sets each letter in positions p_1, p_2, β¦, p_k to letter y. More formally: for each i (1 β€ i β€ k) Koa sets A_{p_i} = y.
Note that you can only modify letters in string A.
Koa wants to know the smallest number of moves she has to do to make strings equal to each other (A = B) or to determine that there is no way to make them equal. Help her!
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 10) β the number of test cases. Description of the test cases follows.
The first line of each test case contains one integer n (1 β€ n β€ 10^5) β the length of strings A and B.
The second line of each test case contains string A (|A|=n).
The third line of each test case contains string B (|B|=n).
Both strings consists of the first 20 lowercase English alphabet letters (ie. from a to t).
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case:
Print on a single line the smallest number of moves she has to do to make strings equal to each other (A = B) or -1 if there is no way to make them equal.
Example
Input
5
3
aab
bcc
4
cabc
abcb
3
abc
tsr
4
aabd
cccd
5
abcbd
bcdda
Output
2
-1
3
2
-1
Note
* In the 1-st test case Koa:
1. selects positions 1 and 2 and sets A_1 = A_2 = b (\color{red}{aa}b β \color{blue}{bb}b).
2. selects positions 2 and 3 and sets A_2 = A_3 = c (b\color{red}{bb} β b\color{blue}{cc}).
* In the 2-nd test case Koa has no way to make string A equal B.
* In the 3-rd test case Koa:
1. selects position 1 and sets A_1 = t (\color{red}{a}bc β \color{blue}{t}bc).
2. selects position 2 and sets A_2 = s (t\color{red}{b}c β t\color{blue}{s}c).
3. selects position 3 and sets A_3 = r (ts\color{red}{c} β ts\color{blue}{r}).
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
from collections import Counter
# c=sorted((i,int(val))for i,val in enumerate(input().split()))
import heapq
# c=sorted((i,int(val))for i,val in enumerate(input().split()))
# n = int(input())
# ls = list(map(int, input().split()))
# n, k = map(int, input().split())
# n =int(input())
# e=list(map(int, input().split()))
# n =int(input())
from collections import Counter
for _ in range(int(input())):
n = int(input())
s=list(input())
t=input()
f=0
d={}
ls=[[]]*26
for i in range(n):
if ord(s[i])>ord(t[i]):
f=1
break
cnt=0
if f==1:
print(-1)
else:
for val in range(97, ord("t") + 1):
char = chr(val)
ls = []
y = "z"
for i in range(n):
if s[i] == char and t[i] > s[i]:
ls.append(i)
y = min(t[i], y)
if ls != []:
cnt += 1
for j in ls:
s[j] = y
print(cnt)
``` | instruction | 0 | 92,816 | 18 | 185,632 |
Yes | output | 1 | 92,816 | 18 | 185,633 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter y Koa selects must be strictly greater alphabetically than x (read statement for better understanding). You can make hacks in these problems independently.
Koa the Koala has two strings A and B of the same length n (|A|=|B|=n) consisting of the first 20 lowercase English alphabet letters (ie. from a to t).
In one move Koa:
1. selects some subset of positions p_1, p_2, β¦, p_k (k β₯ 1; 1 β€ p_i β€ n; p_i β p_j if i β j) of A such that A_{p_1} = A_{p_2} = β¦ = A_{p_k} = x (ie. all letters on this positions are equal to some letter x).
2. selects a letter y (from the first 20 lowercase letters in English alphabet) such that y>x (ie. letter y is strictly greater alphabetically than x).
3. sets each letter in positions p_1, p_2, β¦, p_k to letter y. More formally: for each i (1 β€ i β€ k) Koa sets A_{p_i} = y.
Note that you can only modify letters in string A.
Koa wants to know the smallest number of moves she has to do to make strings equal to each other (A = B) or to determine that there is no way to make them equal. Help her!
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 10) β the number of test cases. Description of the test cases follows.
The first line of each test case contains one integer n (1 β€ n β€ 10^5) β the length of strings A and B.
The second line of each test case contains string A (|A|=n).
The third line of each test case contains string B (|B|=n).
Both strings consists of the first 20 lowercase English alphabet letters (ie. from a to t).
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case:
Print on a single line the smallest number of moves she has to do to make strings equal to each other (A = B) or -1 if there is no way to make them equal.
Example
Input
5
3
aab
bcc
4
cabc
abcb
3
abc
tsr
4
aabd
cccd
5
abcbd
bcdda
Output
2
-1
3
2
-1
Note
* In the 1-st test case Koa:
1. selects positions 1 and 2 and sets A_1 = A_2 = b (\color{red}{aa}b β \color{blue}{bb}b).
2. selects positions 2 and 3 and sets A_2 = A_3 = c (b\color{red}{bb} β b\color{blue}{cc}).
* In the 2-nd test case Koa has no way to make string A equal B.
* In the 3-rd test case Koa:
1. selects position 1 and sets A_1 = t (\color{red}{a}bc β \color{blue}{t}bc).
2. selects position 2 and sets A_2 = s (t\color{red}{b}c β t\color{blue}{s}c).
3. selects position 3 and sets A_3 = r (ts\color{red}{c} β ts\color{blue}{r}).
Submitted Solution:
```
import sys
input = sys.stdin.readline
t = int(input())
letters = 'abcdefghijklmnopqrst'
letters_index = {}
for let in letters:
letters_index[let] = letters.index(let)
#print(letters_index)
for _ in range(t):
l = int(input())
a = input().rstrip()
b = input().rstrip()
used = {}
an = ''
bn = ''
for j in range(len(a)):
if (a[j], b[j]) in used:
pass
else:
an += a[j]
bn += b[j]
used[(a[j], b[j])] = 1
a = an
b = bn
nogo = 0
for j in range(len(a)):
x = letters_index[b[j]] - letters_index[a[j]]
if x<0:
nogo = 1
break
if nogo==1:
print(-1)
else:
c = 0
while a!=b:
tbr = ('z', 999)
for j in range(len(a)):
x = letters_index[b[j]] - letters_index[a[j]]
if x!=0:
if a[j] < tbr[0]:
tbr = (a[j], x)
if x < tbr[1] and a[j]<=tbr[0]:
tbr = (a[j], x)
old_l = tbr[0]
new_l = letters_index[old_l] + tbr[1]
new_l = letters[new_l]
av = ''
bv = ''
for kk in range(len(a)):
if a[kk] != b[kk]:
if a[kk]==old_l:
av+= new_l
else:
av+= a[kk]
bv += b[kk]
a = av
b = bv
c+=1
print(c)
``` | instruction | 0 | 92,817 | 18 | 185,634 |
Yes | output | 1 | 92,817 | 18 | 185,635 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter y Koa selects must be strictly greater alphabetically than x (read statement for better understanding). You can make hacks in these problems independently.
Koa the Koala has two strings A and B of the same length n (|A|=|B|=n) consisting of the first 20 lowercase English alphabet letters (ie. from a to t).
In one move Koa:
1. selects some subset of positions p_1, p_2, β¦, p_k (k β₯ 1; 1 β€ p_i β€ n; p_i β p_j if i β j) of A such that A_{p_1} = A_{p_2} = β¦ = A_{p_k} = x (ie. all letters on this positions are equal to some letter x).
2. selects a letter y (from the first 20 lowercase letters in English alphabet) such that y>x (ie. letter y is strictly greater alphabetically than x).
3. sets each letter in positions p_1, p_2, β¦, p_k to letter y. More formally: for each i (1 β€ i β€ k) Koa sets A_{p_i} = y.
Note that you can only modify letters in string A.
Koa wants to know the smallest number of moves she has to do to make strings equal to each other (A = B) or to determine that there is no way to make them equal. Help her!
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 10) β the number of test cases. Description of the test cases follows.
The first line of each test case contains one integer n (1 β€ n β€ 10^5) β the length of strings A and B.
The second line of each test case contains string A (|A|=n).
The third line of each test case contains string B (|B|=n).
Both strings consists of the first 20 lowercase English alphabet letters (ie. from a to t).
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case:
Print on a single line the smallest number of moves she has to do to make strings equal to each other (A = B) or -1 if there is no way to make them equal.
Example
Input
5
3
aab
bcc
4
cabc
abcb
3
abc
tsr
4
aabd
cccd
5
abcbd
bcdda
Output
2
-1
3
2
-1
Note
* In the 1-st test case Koa:
1. selects positions 1 and 2 and sets A_1 = A_2 = b (\color{red}{aa}b β \color{blue}{bb}b).
2. selects positions 2 and 3 and sets A_2 = A_3 = c (b\color{red}{bb} β b\color{blue}{cc}).
* In the 2-nd test case Koa has no way to make string A equal B.
* In the 3-rd test case Koa:
1. selects position 1 and sets A_1 = t (\color{red}{a}bc β \color{blue}{t}bc).
2. selects position 2 and sets A_2 = s (t\color{red}{b}c β t\color{blue}{s}c).
3. selects position 3 and sets A_3 = r (ts\color{red}{c} β ts\color{blue}{r}).
Submitted Solution:
```
for nt in range(int(input())):
n = int(input())
s = input()
t = input()
new = []
alpha = []
for i in range(97,117):
alpha.append(chr(i))
flag = 0
for i in range(n):
if t[i]<s[i]:
flag = 1
break
if s[i]!=t[i]:
new.append([s[i],t[i]])
if flag:
print (-1)
continue
new.sort(key = lambda x: (x[0],x[1]))
ans = 0
move = {}
done = {}
used = [0]*len(new)
loc = {}
for i in range(len(new)):
loc[new[i][0],new[i][1]] = i
for i in range(len(new)):
if (new[i][0],new[i][1]) in done:
continue
flag = 0
for j in alpha:
if new[i][0]==j:
break
if (j,new[i][0]) in done and not used[loc[j,new[i][0]]] and (j,new[i][1]) in done and not used[loc[j,new[i][1]]]:
flag = 1
used[loc[j,new[i][0]]] = 1
used[loc[j,new[i][1]]] = 1
break
if not flag:
ans += 1
done[new[i][0],new[i][1]] = 1
print (ans)
``` | instruction | 0 | 92,818 | 18 | 185,636 |
No | output | 1 | 92,818 | 18 | 185,637 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter y Koa selects must be strictly greater alphabetically than x (read statement for better understanding). You can make hacks in these problems independently.
Koa the Koala has two strings A and B of the same length n (|A|=|B|=n) consisting of the first 20 lowercase English alphabet letters (ie. from a to t).
In one move Koa:
1. selects some subset of positions p_1, p_2, β¦, p_k (k β₯ 1; 1 β€ p_i β€ n; p_i β p_j if i β j) of A such that A_{p_1} = A_{p_2} = β¦ = A_{p_k} = x (ie. all letters on this positions are equal to some letter x).
2. selects a letter y (from the first 20 lowercase letters in English alphabet) such that y>x (ie. letter y is strictly greater alphabetically than x).
3. sets each letter in positions p_1, p_2, β¦, p_k to letter y. More formally: for each i (1 β€ i β€ k) Koa sets A_{p_i} = y.
Note that you can only modify letters in string A.
Koa wants to know the smallest number of moves she has to do to make strings equal to each other (A = B) or to determine that there is no way to make them equal. Help her!
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 10) β the number of test cases. Description of the test cases follows.
The first line of each test case contains one integer n (1 β€ n β€ 10^5) β the length of strings A and B.
The second line of each test case contains string A (|A|=n).
The third line of each test case contains string B (|B|=n).
Both strings consists of the first 20 lowercase English alphabet letters (ie. from a to t).
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case:
Print on a single line the smallest number of moves she has to do to make strings equal to each other (A = B) or -1 if there is no way to make them equal.
Example
Input
5
3
aab
bcc
4
cabc
abcb
3
abc
tsr
4
aabd
cccd
5
abcbd
bcdda
Output
2
-1
3
2
-1
Note
* In the 1-st test case Koa:
1. selects positions 1 and 2 and sets A_1 = A_2 = b (\color{red}{aa}b β \color{blue}{bb}b).
2. selects positions 2 and 3 and sets A_2 = A_3 = c (b\color{red}{bb} β b\color{blue}{cc}).
* In the 2-nd test case Koa has no way to make string A equal B.
* In the 3-rd test case Koa:
1. selects position 1 and sets A_1 = t (\color{red}{a}bc β \color{blue}{t}bc).
2. selects position 2 and sets A_2 = s (t\color{red}{b}c β t\color{blue}{s}c).
3. selects position 3 and sets A_3 = r (ts\color{red}{c} β ts\color{blue}{r}).
Submitted Solution:
```
for nt in range(int(input())):
n = int(input())
s = input()
t = input()
new = []
flag = 0
for i in range(n):
if t[i]<s[i]:
flag = 1
break
if s[i]!=t[i]:
new.append([s[i],t[i]])
if flag:
print (-1)
continue
new.sort(key = lambda x: (x[0],x[1]))
used = [0]*n
done = {}
first = {}
ans = 0
for i in range(len(new)):
if new[i][0] not in first:
first[new[i][0]] = 1
used[i] = 1
if new[i][1] not in done:
ans += 1
done[new[i][1]] = [i]
else:
flag = 0
for k in done[new[i][1]]:
if not used[k]:
used[k] = 1
flag = 1
break
if not flag:
ans += 1
done[new[i][1]].append(i)
# print (done,ans,used)
print (ans)
``` | instruction | 0 | 92,819 | 18 | 185,638 |
No | output | 1 | 92,819 | 18 | 185,639 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter y Koa selects must be strictly greater alphabetically than x (read statement for better understanding). You can make hacks in these problems independently.
Koa the Koala has two strings A and B of the same length n (|A|=|B|=n) consisting of the first 20 lowercase English alphabet letters (ie. from a to t).
In one move Koa:
1. selects some subset of positions p_1, p_2, β¦, p_k (k β₯ 1; 1 β€ p_i β€ n; p_i β p_j if i β j) of A such that A_{p_1} = A_{p_2} = β¦ = A_{p_k} = x (ie. all letters on this positions are equal to some letter x).
2. selects a letter y (from the first 20 lowercase letters in English alphabet) such that y>x (ie. letter y is strictly greater alphabetically than x).
3. sets each letter in positions p_1, p_2, β¦, p_k to letter y. More formally: for each i (1 β€ i β€ k) Koa sets A_{p_i} = y.
Note that you can only modify letters in string A.
Koa wants to know the smallest number of moves she has to do to make strings equal to each other (A = B) or to determine that there is no way to make them equal. Help her!
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 10) β the number of test cases. Description of the test cases follows.
The first line of each test case contains one integer n (1 β€ n β€ 10^5) β the length of strings A and B.
The second line of each test case contains string A (|A|=n).
The third line of each test case contains string B (|B|=n).
Both strings consists of the first 20 lowercase English alphabet letters (ie. from a to t).
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case:
Print on a single line the smallest number of moves she has to do to make strings equal to each other (A = B) or -1 if there is no way to make them equal.
Example
Input
5
3
aab
bcc
4
cabc
abcb
3
abc
tsr
4
aabd
cccd
5
abcbd
bcdda
Output
2
-1
3
2
-1
Note
* In the 1-st test case Koa:
1. selects positions 1 and 2 and sets A_1 = A_2 = b (\color{red}{aa}b β \color{blue}{bb}b).
2. selects positions 2 and 3 and sets A_2 = A_3 = c (b\color{red}{bb} β b\color{blue}{cc}).
* In the 2-nd test case Koa has no way to make string A equal B.
* In the 3-rd test case Koa:
1. selects position 1 and sets A_1 = t (\color{red}{a}bc β \color{blue}{t}bc).
2. selects position 2 and sets A_2 = s (t\color{red}{b}c β t\color{blue}{s}c).
3. selects position 3 and sets A_3 = r (ts\color{red}{c} β ts\color{blue}{r}).
Submitted Solution:
```
def solve(n,a,b):
for i in range(n):
if(a[i]>b[i]):
return -1
ans=0
for j in range(20):
cr=chr(97+j)
arr=[]
x='z'
for i in range(n):
if(a[i]==cr and b[i]>cr):
x=min(a[i],x)
arr.append(i)
if(len(arr)!=0):
ans+=1
for k in arr:
a[k]=x
return ans
for _ in range(int(input())):
n=int(input())
a=list(input())
b=list(input())
print(solve(n,a,b))
``` | instruction | 0 | 92,820 | 18 | 185,640 |
No | output | 1 | 92,820 | 18 | 185,641 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter y Koa selects must be strictly greater alphabetically than x (read statement for better understanding). You can make hacks in these problems independently.
Koa the Koala has two strings A and B of the same length n (|A|=|B|=n) consisting of the first 20 lowercase English alphabet letters (ie. from a to t).
In one move Koa:
1. selects some subset of positions p_1, p_2, β¦, p_k (k β₯ 1; 1 β€ p_i β€ n; p_i β p_j if i β j) of A such that A_{p_1} = A_{p_2} = β¦ = A_{p_k} = x (ie. all letters on this positions are equal to some letter x).
2. selects a letter y (from the first 20 lowercase letters in English alphabet) such that y>x (ie. letter y is strictly greater alphabetically than x).
3. sets each letter in positions p_1, p_2, β¦, p_k to letter y. More formally: for each i (1 β€ i β€ k) Koa sets A_{p_i} = y.
Note that you can only modify letters in string A.
Koa wants to know the smallest number of moves she has to do to make strings equal to each other (A = B) or to determine that there is no way to make them equal. Help her!
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 10) β the number of test cases. Description of the test cases follows.
The first line of each test case contains one integer n (1 β€ n β€ 10^5) β the length of strings A and B.
The second line of each test case contains string A (|A|=n).
The third line of each test case contains string B (|B|=n).
Both strings consists of the first 20 lowercase English alphabet letters (ie. from a to t).
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case:
Print on a single line the smallest number of moves she has to do to make strings equal to each other (A = B) or -1 if there is no way to make them equal.
Example
Input
5
3
aab
bcc
4
cabc
abcb
3
abc
tsr
4
aabd
cccd
5
abcbd
bcdda
Output
2
-1
3
2
-1
Note
* In the 1-st test case Koa:
1. selects positions 1 and 2 and sets A_1 = A_2 = b (\color{red}{aa}b β \color{blue}{bb}b).
2. selects positions 2 and 3 and sets A_2 = A_3 = c (b\color{red}{bb} β b\color{blue}{cc}).
* In the 2-nd test case Koa has no way to make string A equal B.
* In the 3-rd test case Koa:
1. selects position 1 and sets A_1 = t (\color{red}{a}bc β \color{blue}{t}bc).
2. selects position 2 and sets A_2 = s (t\color{red}{b}c β t\color{blue}{s}c).
3. selects position 3 and sets A_3 = r (ts\color{red}{c} β ts\color{blue}{r}).
Submitted Solution:
```
"""
Satwik_Tiwari ;) .
21st july , 2020 - tuesday
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter # Counter(list) return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned
#==============================================================================================
#fast I/O region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
#===============================================================================================
#some shortcuts
mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var)) #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n") #as stdout.write always print sring.
def testcase(t):
for p in range(t):
solve()
def printlist(a) :
for p in range(0,len(a)):
out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
ans = 1
while(b>0):
if(b%2==1):
ans*=a
a*=a
b//=2
return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) :
if (n <= 1) : return False
if (n <= 3) : return True
if (n % 2 == 0 or n % 3 == 0) : return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
#===============================================================================================
# code here ;))
def solve():
n = int(inp())
a = list(inp())
b = list(inp())
for i in range(n):
if(a[i] > b[i]):
print(-1)
return
cnt = [{} for i in range(20)]
for i in range(n):
if(a[i] in cnt[ord(b[i])-97]):
cnt[ord(b[i])-97][a[i]] +=1
else:
cnt[ord(b[i])-97][a[i]] = 1
# for i in range(20):
# print(cnt[i])
ans = 0
for i in range(1,20):
if(len(cnt[i]) == 0):
continue
else:
ans+=1
print(ans)
# testcase(1)
testcase(int(inp()))
``` | instruction | 0 | 92,821 | 18 | 185,642 |
No | output | 1 | 92,821 | 18 | 185,643 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input
The only line of the input contains a string s (1 β€ |s| β€ 10). Each character in s is a lowercase English letter.
Output
If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Examples
Input
revive
Output
reviver
Input
ee
Output
eye
Input
kitayuta
Output
NA
Note
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | instruction | 0 | 93,067 | 18 | 186,134 |
Tags: brute force, implementation, strings
Correct Solution:
```
def func(s):
for i in range(len(s)+1):
for j in range(97,123):
q = s[:i]+chr(j)+s[i:]
rev = q[::-1]
if q == rev:
return q
return "NA"
s=input()
print(func(s))
``` | output | 1 | 93,067 | 18 | 186,135 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input
The only line of the input contains a string s (1 β€ |s| β€ 10). Each character in s is a lowercase English letter.
Output
If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Examples
Input
revive
Output
reviver
Input
ee
Output
eye
Input
kitayuta
Output
NA
Note
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | instruction | 0 | 93,068 | 18 | 186,136 |
Tags: brute force, implementation, strings
Correct Solution:
```
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def MAP2():return map(float,input().split())
def LIST(): return list(map(int, input().split()))
def STRING(): return input()
import string
from heapq import heappop , heappush
from bisect import *
from collections import deque , Counter
from math import *
from itertools import permutations , accumulate
dx = [-1 , 1 , 0 , 0 ]
dy = [0 , 0 , 1 , - 1]
#visited = [[False for i in range(m)] for j in range(n)]
#for tt in range(INT()):
def check(s):
if s == s[::-1]:
return True
return False
s = STR()
ans = ''
flag = False
st_letters = set(s)
for i in range(11):
for j in st_letters:
z = s.copy()
z.insert(i , j)
if check(z):
flag = True
ans = ''.join(z)
break
if flag:
print(ans)
else:
print('NA')
``` | output | 1 | 93,068 | 18 | 186,137 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input
The only line of the input contains a string s (1 β€ |s| β€ 10). Each character in s is a lowercase English letter.
Output
If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Examples
Input
revive
Output
reviver
Input
ee
Output
eye
Input
kitayuta
Output
NA
Note
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | instruction | 0 | 93,069 | 18 | 186,138 |
Tags: brute force, implementation, strings
Correct Solution:
```
s=input()
for i in range (26):
for j in range (len(s)+1):
s1=s[:j]+chr(ord('a')+i)+s[j:]
if s1[::-1]==s1:
print (s1)
exit()
print('NA')
``` | output | 1 | 93,069 | 18 | 186,139 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input
The only line of the input contains a string s (1 β€ |s| β€ 10). Each character in s is a lowercase English letter.
Output
If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Examples
Input
revive
Output
reviver
Input
ee
Output
eye
Input
kitayuta
Output
NA
Note
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | instruction | 0 | 93,070 | 18 | 186,140 |
Tags: brute force, implementation, strings
Correct Solution:
```
x = input()
d = False
for c in range(97,123):
if ( d):
break
for i in range(len(x) + 1):
n = x[:i] + chr(c) + x[i:]
if n == n[::-1]:
print (n)
d= True
break
if (not d):
print ("NA")
``` | output | 1 | 93,070 | 18 | 186,141 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input
The only line of the input contains a string s (1 β€ |s| β€ 10). Each character in s is a lowercase English letter.
Output
If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Examples
Input
revive
Output
reviver
Input
ee
Output
eye
Input
kitayuta
Output
NA
Note
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | instruction | 0 | 93,071 | 18 | 186,142 |
Tags: brute force, implementation, strings
Correct Solution:
```
# 505A
__author__ = 'artyom'
# SOLUTION
def main():
s = list(read(0))
n = len(s)
m = n // 2
for i in range(n + 1):
p = s[:i] + [s[n - i - (i <= m)]] + s[i:n]
if p == p[::-1]:
return p
return 'NA'
# HELPERS
def read(mode=2):
# 0: String
# 1: List of strings
# 2: List of integers
inputs = input().strip()
if mode == 0: return inputs
if mode == 1: return inputs.split()
if mode == 2: return int(inputs)
if mode == 3: return list(map(int, inputs.split()))
def write(s="\n"):
if s is None: s = ''
if isinstance(s, list): s = ''.join(map(str, s))
s = str(s)
print(s, end="")
write(main())
``` | output | 1 | 93,071 | 18 | 186,143 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input
The only line of the input contains a string s (1 β€ |s| β€ 10). Each character in s is a lowercase English letter.
Output
If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Examples
Input
revive
Output
reviver
Input
ee
Output
eye
Input
kitayuta
Output
NA
Note
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | instruction | 0 | 93,072 | 18 | 186,144 |
Tags: brute force, implementation, strings
Correct Solution:
```
s = input()
for i in range(26):
a = chr(ord('a') + i)
for j in range(len(s)):
temp = s[:j] + a + s[j:]
if temp == temp[::-1]:
print(temp)
exit(0)
temp = s + a
if temp == temp[::-1]:
print(temp)
exit(0)
print("NA")
``` | output | 1 | 93,072 | 18 | 186,145 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input
The only line of the input contains a string s (1 β€ |s| β€ 10). Each character in s is a lowercase English letter.
Output
If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Examples
Input
revive
Output
reviver
Input
ee
Output
eye
Input
kitayuta
Output
NA
Note
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | instruction | 0 | 93,073 | 18 | 186,146 |
Tags: brute force, implementation, strings
Correct Solution:
```
#Author : Zahin uddin
#Github : https://github.com/Zahin52
from sys import *
import math
#import queue
input=stdin.readline
I=int
R=range
listInput=lambda:list(map(int,input().strip().split()))
lineInput= lambda:map(int,input().strip().split())
sJoin=lambda a,sep : '{}'.format(sep).join(a)
arrJoin=lambda a,sep : '{}'.format(sep).join(map(str,a))
#print=stdout.write
def isPrime(n):
if(n <= 1):
return False
if(n <= 3):
return True
if(n % 2 == 0 or n % 3 == 0):
return False
for i in range(5,int(math.sqrt(n) + 1), 6):
if(n % i == 0 or n % (i + 2) == 0):
return False
return True
def main():
s=input().strip()
i,j=0,len(s)-1
pos=0
char=""
jchar=""
ipos=0
while i<j:
if s[i]!=s[j]:
pos=j
ipos=i
char=s[i]
jchar=s[j]
break
i+=1
j-=1
if pos==0:
L=len(s)
mid=(L+2-1)//2
first,last=s[:mid],s[mid:]
s=first+s[mid-1]+last
print(s)
else:
first,last=s[:pos+1],s[pos+1:]
start,stop=s[:ipos],s[ipos:]
r=start+jchar+stop
s=first+char+last
if s[::]==s[::-1]:
print(s)
elif r[::]==r[::-1]:
print(r)
else:
print("NA")
if __name__ == "__main__":
main()
``` | output | 1 | 93,073 | 18 | 186,147 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input
The only line of the input contains a string s (1 β€ |s| β€ 10). Each character in s is a lowercase English letter.
Output
If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Examples
Input
revive
Output
reviver
Input
ee
Output
eye
Input
kitayuta
Output
NA
Note
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | instruction | 0 | 93,074 | 18 | 186,148 |
Tags: brute force, implementation, strings
Correct Solution:
```
# Π±ΡΡΡΡΠΎ ΠΆΠ°Π΄Π½ΠΎ Π½ΠΎ ΠΊΡΠΈΠ²ΠΎ
s=input()
for i in range(len(s)+1):
for j in range(26):
z=s[:i]+chr(ord('a')+j)+s[i:]
if z==z[::-1]:
print(z)
exit(0)
print("NA")
``` | output | 1 | 93,074 | 18 | 186,149 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input
The only line of the input contains a string s (1 β€ |s| β€ 10). Each character in s is a lowercase English letter.
Output
If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Examples
Input
revive
Output
reviver
Input
ee
Output
eye
Input
kitayuta
Output
NA
Note
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.
Submitted Solution:
```
s = input()
for i in range(26):
for j in range(len(s) + 1) :
ans = s[: j] + chr(97 + i) + s[j:]
if ans == ans[::-1] :
print(ans)
exit()
print('NA')
``` | instruction | 0 | 93,075 | 18 | 186,150 |
Yes | output | 1 | 93,075 | 18 | 186,151 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input
The only line of the input contains a string s (1 β€ |s| β€ 10). Each character in s is a lowercase English letter.
Output
If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Examples
Input
revive
Output
reviver
Input
ee
Output
eye
Input
kitayuta
Output
NA
Note
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.
Submitted Solution:
```
s = input()
l = len(s)
a = 'abcdefghijklmnopqrstuvwxyz'
for i in range(len(a)):
for j in range(l+1):
x = s[:j]+a[i]+s[j:]
if x == x[::-1]:
print(x)
exit()
else:
print("NA")
``` | instruction | 0 | 93,076 | 18 | 186,152 |
Yes | output | 1 | 93,076 | 18 | 186,153 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input
The only line of the input contains a string s (1 β€ |s| β€ 10). Each character in s is a lowercase English letter.
Output
If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Examples
Input
revive
Output
reviver
Input
ee
Output
eye
Input
kitayuta
Output
NA
Note
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.
Submitted Solution:
```
s = input()
for j in range(len(s)+1):
for i in range(26):
t = s[:j]+chr(i+ord('a'))+s[j:]
if(t == t[::-1]):
print(t)
exit(0)
print("NA")
``` | instruction | 0 | 93,077 | 18 | 186,154 |
Yes | output | 1 | 93,077 | 18 | 186,155 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input
The only line of the input contains a string s (1 β€ |s| β€ 10). Each character in s is a lowercase English letter.
Output
If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Examples
Input
revive
Output
reviver
Input
ee
Output
eye
Input
kitayuta
Output
NA
Note
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.
Submitted Solution:
```
def main():
l = list(input())
l.append(None)
for i in range(len(l) - 1, -1, -1):
for c in 'abcdefghijklmnopqrstuvwxyz':
l[i] = c
if l == l[::-1]:
print(''.join(l))
return
l[i] = l[i - 1]
print('NA')
if __name__ == '__main__':
main()
``` | instruction | 0 | 93,078 | 18 | 186,156 |
Yes | output | 1 | 93,078 | 18 | 186,157 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input
The only line of the input contains a string s (1 β€ |s| β€ 10). Each character in s is a lowercase English letter.
Output
If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Examples
Input
revive
Output
reviver
Input
ee
Output
eye
Input
kitayuta
Output
NA
Note
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.
Submitted Solution:
```
"""""""""""""""""""""""""""""""""""""""""""""
| author: mr.math - Hakimov Rahimjon |
| e-mail: mr.math0777@gmail.com |
"""""""""""""""""""""""""""""""""""""""""""""
#inp = open("lepus.in", "r"); input = inp.readline; out = open("lepus.out", "w"); print = out.write
TN = 1
# ===========================================
def solution():
s = list(input())
n = len(s)
ans = "NA"
t = ["" for i in range(n+2)]
for i in range((n+1)//2):
t[i] += s[i]
t[-i-1] += s[i]
if n % 2 == 0: t[n//2] = s[n//2]
t = "".join(t)
cur = 0
for i in range(n):
if t[i] != s[i-cur]: cur += 1
if cur > 1: print("NA")
else: print(t)
# ===========================================
while TN != 0:
solution()
TN -= 1
# ===========================================
#inp.close()
#out.close()
``` | instruction | 0 | 93,079 | 18 | 186,158 |
No | output | 1 | 93,079 | 18 | 186,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input
The only line of the input contains a string s (1 β€ |s| β€ 10). Each character in s is a lowercase English letter.
Output
If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Examples
Input
revive
Output
reviver
Input
ee
Output
eye
Input
kitayuta
Output
NA
Note
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.
Submitted Solution:
```
s=input()
si=s[::-1]
if s==si and len(s)%2==0:
output=s[:len(s)//2]+"a"+s[len(s)//2:]
print(output)
elif s==si and len(s)%2==1:
output=s[:len(s)//2+1]+s[len(s)//2:]
print(output)
else:
output=""
save=-1
for i in range(len(s)):
if s[i]!=si[i]:
output+=s[i]
save=i
break
else:
output+=s[i]
if save>-1 and save<len(s):
output+=si[save:]
if output!=output[::-1]:
print("NA")
'''print(output)'''
else:
print(output)
``` | instruction | 0 | 93,080 | 18 | 186,160 |
No | output | 1 | 93,080 | 18 | 186,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input
The only line of the input contains a string s (1 β€ |s| β€ 10). Each character in s is a lowercase English letter.
Output
If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Examples
Input
revive
Output
reviver
Input
ee
Output
eye
Input
kitayuta
Output
NA
Note
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.
Submitted Solution:
```
def is_palindrome(s):
if s==s[::-1]:
return True
return False
s = input().strip()
l = len(s)
if is_palindrome(s):
if l%2:
print(s[:l//2]+s[l//2]+s[l//2:])
else:
print(s[:l//2]+'a'+s[l//2:])
else:
for i in range(l):
if is_palindrome(s[:i]+s[i+1:]):
c = s[:l-i]+s[i]+s[l-i:]
if is_palindrome(c):
print(c)
break
else:
print("NA")
``` | instruction | 0 | 93,081 | 18 | 186,162 |
No | output | 1 | 93,081 | 18 | 186,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.
You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.
If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
Input
The only line of the input contains a string s (1 β€ |s| β€ 10). Each character in s is a lowercase English letter.
Output
If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
Examples
Input
revive
Output
reviver
Input
ee
Output
eye
Input
kitayuta
Output
NA
Note
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.
Submitted Solution:
```
def is_palindrome(s):
return str(s) == str(s)[::-1]
def main():
s = input()
length = len(s)
if is_palindrome(s):
if length % 2 == 0:
mid = length // 2
print(s[:mid] + 'a' + s[mid:])
return
else:
mid = (length - 1) // 2
print(s[:mid] + s[mid] + s[mid:])
return
else:
for index in range(length):
candidate = s[:index] + s[index + 1:]
if is_palindrome(candidate):
if index == 0:
print(s + s[index])
elif index == length - 1:
print(s[index] + s)
else:
print(s[:-index] + s[index] + s[-index:])
return
print('NA')
if __name__ == '__main__':
main()
``` | instruction | 0 | 93,082 | 18 | 186,164 |
No | output | 1 | 93,082 | 18 | 186,165 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.
<image>
However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat.
<image>
You have met a cat. Can you figure out whether it's normal or grumpy?
Interaction
This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9.
In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase.
Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out.
Note
Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
Submitted Solution:
```
#print('grumpy')
from sys import exit
import sys
a = ['no', 'no', 'no', 'no', 'no', "don't t",'grea',"don't t",'not ','cool']
b = ['no','no','no', 'no w', 'no w','go d','wors','terr', "don't e", 'are ']
for i in range(10):
sys.stdout.write(str(i))
sys.stdout.write('\n')
sys.stdout.flush()
inp = input()
if (inp.__len__()>4):
if (inp[:4] == "don'"):
inp = inp[:7]
else:
inp = inp[:4]
if inp in a:
a.remove(inp)
else :
print('grumpy')
exit()
if inp in b:
b.remove(inp)
else:
print('normal')
exit()
sys.stdout.write('normal')
#sys.stdout.write('\n')
sys.stdout.flush()
exit()
for i in range(10):
print(i)
a = input()
if (a.__len__() > 2):
if a[-2:] == 'en':
print('grumpy')
exit()
print('normal')
``` | instruction | 0 | 93,224 | 18 | 186,448 |
Yes | output | 1 | 93,224 | 18 | 186,449 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i** | instruction | 0 | 93,307 | 18 | 186,614 |
"Correct Solution:
```
n = int(input())
s = input()
k = int(input())
t = s[k-1]
s = [c if c == t else "*" for c in s]
print("".join(s))
``` | output | 1 | 93,307 | 18 | 186,615 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i** | instruction | 0 | 93,308 | 18 | 186,616 |
"Correct Solution:
```
n=int(input())
s=input()
k=int(input())
print(''.join([x if x==s[k-1] else '*' for x in s]))
``` | output | 1 | 93,308 | 18 | 186,617 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i** | instruction | 0 | 93,309 | 18 | 186,618 |
"Correct Solution:
```
N=int(input())
S=input()
t=S[int(input())-1]
ans = [i if i==t else "*" for i in S]
print("".join(ans))
``` | output | 1 | 93,309 | 18 | 186,619 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i** | instruction | 0 | 93,310 | 18 | 186,620 |
"Correct Solution:
```
n=int(input())
s=input()
k=int(input())
ans=""
for i in range(n):
ans+=((s[i],"*")[s[i]!=s[k-1]])
print(ans)
``` | output | 1 | 93,310 | 18 | 186,621 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i** | instruction | 0 | 93,311 | 18 | 186,622 |
"Correct Solution:
```
N = int(input())
S = input()
K = int(input())
Sk = S[K - 1]
print(''.join([s if s == Sk else '*' for s in S]))
``` | output | 1 | 93,311 | 18 | 186,623 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i** | instruction | 0 | 93,312 | 18 | 186,624 |
"Correct Solution:
```
n = int(input())
s = input()
k = int(input())
for r in s:
print(r if r == s[k-1] else "*",end="")
``` | output | 1 | 93,312 | 18 | 186,625 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i** | instruction | 0 | 93,313 | 18 | 186,626 |
"Correct Solution:
```
n=int(input())
l=list(input())
m=int(input())
for i in range(len(l)):
if l[i]!=l[m-1]:
l[i]="*"
print("".join(l))
``` | output | 1 | 93,313 | 18 | 186,627 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i** | instruction | 0 | 93,314 | 18 | 186,628 |
"Correct Solution:
```
input()
s = input()
n = int(input())
print(*[i if i==s[n-1] else "*" for i in s], sep='')
``` | output | 1 | 93,314 | 18 | 186,629 |
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 of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
Submitted Solution:
```
N = int(input())
S = input()
K = int(input())
sk = S[K-1]
print("".join([s if s == sk else "*" for s in S]))
``` | instruction | 0 | 93,315 | 18 | 186,630 |
Yes | output | 1 | 93,315 | 18 | 186,631 |
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 of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
Submitted Solution:
```
import re
n = int(input())
s = input()
k = int(input())
target = s[k-1]
print(re.sub('[^' + s[k-1] + ']', '*', s))
``` | instruction | 0 | 93,316 | 18 | 186,632 |
Yes | output | 1 | 93,316 | 18 | 186,633 |
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 of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
Submitted Solution:
```
import re
n = int(input())
s = input()
k = int(input())
ans = re.sub(rf'[^{s[k-1]}]', '*', s)
print(ans)
``` | instruction | 0 | 93,317 | 18 | 186,634 |
Yes | output | 1 | 93,317 | 18 | 186,635 |
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 of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
Submitted Solution:
```
N=int(input())
S= input()
K=int(input())
print(''.join(map(lambda s: '*' if s != S[K-1] else s, S)))
``` | instruction | 0 | 93,318 | 18 | 186,636 |
Yes | output | 1 | 93,318 | 18 | 186,637 |
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 of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
Submitted Solution:
```
n = int(input())
str = input()
str =list(str)
str.append("a")
cs = int(input())
char = str[cs-1]
for i in range(n):
if str[i] != char:
str[i:i+1] = "*"
ans = str[0:n]
print(*ans)
``` | instruction | 0 | 93,319 | 18 | 186,638 |
No | output | 1 | 93,319 | 18 | 186,639 |
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 of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
Submitted Solution:
```
N = int(input())
S = input()
K = int(input())
target = S[K - 1]
for i in range(N):
if S[i] != target:
S[i] = '*'
print(S)
``` | instruction | 0 | 93,320 | 18 | 186,640 |
No | output | 1 | 93,320 | 18 | 186,641 |
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 of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
Submitted Solution:
```
k = int( input())
s = list(str(input()))
n = int( input())
for i in range(len(s)):
if s[i] != s[n-1]:
s[i] = "*"
print(s)
``` | instruction | 0 | 93,321 | 18 | 186,642 |
No | output | 1 | 93,321 | 18 | 186,643 |
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 of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
Submitted Solution:
```
S = int(input())
word = list(input())
K = int(input())
judge=word[K-1]
for i in range(S):
if word[i] == judge:
pass
else:
word[i] = '*'
print(" ".join(word))
``` | instruction | 0 | 93,322 | 18 | 186,644 |
No | output | 1 | 93,322 | 18 | 186,645 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem
Taro hides important books in the school locker, so he manages them more strictly than other people, and in addition to the keys provided by the school, he has installed the following button authentication type keys. ..
<image>
However, Taro, who easily forgets his password, has a habit of making it possible to write his password in one stroke. Even more sweet Taro wrote the candidates on paper when he thought about his password. Jiro, who happened to pick up the paper, tried to open the locker without throwing it away because he had a bad personality.
However, there are as many as 1000 password proposals written on the paper, and it seems that the sun will go down if you try all the inputs. Therefore, Jiro, who knows Taro's habits, decided to pick up only the ones that can be written with one stroke from the 1000 passwords in order to reduce the number of examinations, and asked the programmer to do the work.
There is always one or more candidates for each dataset. The rules for one-stroke writing are shown below.
1. The same characters are not consecutive. For example, AAA is not allowed.
2. One-stroke writing is possible in four directions, up, down, left and right. Do not move diagonally.
3. It does not go out of the frame of the button array and continue. Movement such as ABCA is not allowed.
4. You can pass over the characters that you have passed once.
5. Input of only one character of the button is regarded as one-stroke writing.
Input
The input consists of a group of 1000 character strings as shown below, and each line is an uppercase alphabetic string of 1 to 10 characters from A to I. It is assumed that there is no duplication of character string data.
string1
string2
...
string1000
Output
Extract only the candidate passwords (candidatePassword) from the input and list them as follows. In the following cases, N candidates are listed.
candidatePassword1
candidatePassword2
...
candidatePasswordN
The output is the same as the order of the input strings and the order must not be changed.
Example
Input
ABCFI
ABCABCABC
AEI
EFC
οΌδΈη₯οΌ
DEHED
EEEEE
οΌδ»₯δΈγ§γ‘γγγ©1000εοΌ
Output
ABCFI
EFC
οΌδΈη₯οΌ
DEHED
Submitted Solution:
```
dic = {}
dic["A"] = "BD"
dic["B"] = "ACE"
dic["C"] = "BF"
dic["D"] = "AEG"
dic["E"] = "BDFH"
dic["F"] = "CEI"
dic["G"] = "DH"
dic["H"] = "EGI"
dic["I"] = "FH"
results = []
for i in range(2):
pwd = input()
frag = 1
for j in range(len(pwd) - 1):
if pwd[j] in dic[pwd[j + 1]]:
a = 1
else:
frag = 0
break
if frag:
results.append(pwd)
for i in range(len(results)):
print(results[i])
``` | instruction | 0 | 93,460 | 18 | 186,920 |
No | output | 1 | 93,460 | 18 | 186,921 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem
Taro hides important books in the school locker, so he manages them more strictly than other people, and in addition to the keys provided by the school, he has installed the following button authentication type keys. ..
<image>
However, Taro, who easily forgets his password, has a habit of making it possible to write his password in one stroke. Even more sweet Taro wrote the candidates on paper when he thought about his password. Jiro, who happened to pick up the paper, tried to open the locker without throwing it away because he had a bad personality.
However, there are as many as 1000 password proposals written on the paper, and it seems that the sun will go down if you try all the inputs. Therefore, Jiro, who knows Taro's habits, decided to pick up only the ones that can be written with one stroke from the 1000 passwords in order to reduce the number of examinations, and asked the programmer to do the work.
There is always one or more candidates for each dataset. The rules for one-stroke writing are shown below.
1. The same characters are not consecutive. For example, AAA is not allowed.
2. One-stroke writing is possible in four directions, up, down, left and right. Do not move diagonally.
3. It does not go out of the frame of the button array and continue. Movement such as ABCA is not allowed.
4. You can pass over the characters that you have passed once.
5. Input of only one character of the button is regarded as one-stroke writing.
Input
The input consists of a group of 1000 character strings as shown below, and each line is an uppercase alphabetic string of 1 to 10 characters from A to I. It is assumed that there is no duplication of character string data.
string1
string2
...
string1000
Output
Extract only the candidate passwords (candidatePassword) from the input and list them as follows. In the following cases, N candidates are listed.
candidatePassword1
candidatePassword2
...
candidatePasswordN
The output is the same as the order of the input strings and the order must not be changed.
Example
Input
ABCFI
ABCABCABC
AEI
EFC
οΌδΈη₯οΌ
DEHED
EEEEE
οΌδ»₯δΈγ§γ‘γγγ©1000εοΌ
Output
ABCFI
EFC
οΌδΈη₯οΌ
DEHED
Submitted Solution:
```
movable = {"A":("B","D","\n"),"B":("A","C","E","\n"),"C":("B","F","\n"),"D":("A","E","G","\n"),"E":("D","B","F","H","\n"),"F":("C","E","I","\n"),"G":("D","H","I","\n"),"H":("G","E","I","\n"),"I":("H","F","\n")}
A = [""]*1000
for i in range(1000):
A[i] = input()
B = []
def judge(string):
counter = 0
for i in range(len(string)-1):
if string[i+1] in movable[string[i]]:
counter += 1
else :
break
return len(string) == counter
for po in A:
if judge(po):
B.append(po)
else:
continue
for pu in B:
print(pu)
``` | instruction | 0 | 93,461 | 18 | 186,922 |
No | output | 1 | 93,461 | 18 | 186,923 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem
Taro hides important books in the school locker, so he manages them more strictly than other people, and in addition to the keys provided by the school, he has installed the following button authentication type keys. ..
<image>
However, Taro, who easily forgets his password, has a habit of making it possible to write his password in one stroke. Even more sweet Taro wrote the candidates on paper when he thought about his password. Jiro, who happened to pick up the paper, tried to open the locker without throwing it away because he had a bad personality.
However, there are as many as 1000 password proposals written on the paper, and it seems that the sun will go down if you try all the inputs. Therefore, Jiro, who knows Taro's habits, decided to pick up only the ones that can be written with one stroke from the 1000 passwords in order to reduce the number of examinations, and asked the programmer to do the work.
There is always one or more candidates for each dataset. The rules for one-stroke writing are shown below.
1. The same characters are not consecutive. For example, AAA is not allowed.
2. One-stroke writing is possible in four directions, up, down, left and right. Do not move diagonally.
3. It does not go out of the frame of the button array and continue. Movement such as ABCA is not allowed.
4. You can pass over the characters that you have passed once.
5. Input of only one character of the button is regarded as one-stroke writing.
Input
The input consists of a group of 1000 character strings as shown below, and each line is an uppercase alphabetic string of 1 to 10 characters from A to I. It is assumed that there is no duplication of character string data.
string1
string2
...
string1000
Output
Extract only the candidate passwords (candidatePassword) from the input and list them as follows. In the following cases, N candidates are listed.
candidatePassword1
candidatePassword2
...
candidatePasswordN
The output is the same as the order of the input strings and the order must not be changed.
Example
Input
ABCFI
ABCABCABC
AEI
EFC
οΌδΈη₯οΌ
DEHED
EEEEE
οΌδ»₯δΈγ§γ‘γγγ©1000εοΌ
Output
ABCFI
EFC
οΌδΈη₯οΌ
DEHED
Submitted Solution:
```
N = 1000
A = ["B","D"]
B = ["A","C","E"]
C = ["B","F"]
D = ["A","E","G"]
E = ["B","D","F","H"]
F = ["C","E","I"]
G = ["D","H"]
H = ["E","G","I"]
I = ["F","I"]
def check(string):
if len(string) == 1:
return True
for i in range(len(string)-1):
if string[i] == "A" and not(string[i+1] in A):
return False
if string[i] == "B" and not(string[i+1] in B):
return False
if string[i] == "C" and not(string[i+1] in C):
return False
if string[i] == "D" and not(string[i+1] in D):
return False
if string[i] == "E" and not(string[i+1] in E):
return False
if string[i] == "F" and not(string[i+1] in F):
return False
if string[i] == "G" and not(string[i+1] in G):
return False
if string[i] == "H" and not(string[i+1] in H):
return False
if string[i] == "I" and not(string[i+1] in I):
return False
return True
for i in range(N):
s = str(input())
if check(s):
print(s)
``` | instruction | 0 | 93,462 | 18 | 186,924 |
No | output | 1 | 93,462 | 18 | 186,925 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Submitted Solution:
```
def main():
input()
words = input().strip().split()
max_volume = 0
for word in words:
volume = sum(1 for ch in word if 'A' <= ch <= 'Z')
max_volume = max(volume, max_volume)
print(max_volume)
if __name__ == '__main__':
main()
``` | instruction | 0 | 94,086 | 18 | 188,172 |
Yes | output | 1 | 94,086 | 18 | 188,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Submitted Solution:
```
a = input()
b = input().split()
ans = 0
for x in b:
c = sum([1 for q in x if q.isupper()])
if c > ans:
ans = c
print(ans)
``` | instruction | 0 | 94,087 | 18 | 188,174 |
Yes | output | 1 | 94,087 | 18 | 188,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Submitted Solution:
```
n = int(input())
s = input().split()
k = 0
for i in s:
v = 0
for j in i:
if 65 <= ord(j) and ord(j) <= 90:
v += 1
if v > k:
k = v
print(k)
``` | instruction | 0 | 94,088 | 18 | 188,176 |
Yes | output | 1 | 94,088 | 18 | 188,177 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Submitted Solution:
```
#Numero inservible
NumC= list(map(int, input().split()))
#Palabra que sirve
Word = input().split()
upper = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
MMayus = 0
for a in range(len(Word)):
thing = 0
for b in range(len(Word[a])):
if(Word[a][b] in upper):
thing+=1
if(thing>MMayus):
MMayus = thing
print(MMayus)
``` | instruction | 0 | 94,089 | 18 | 188,178 |
Yes | output | 1 | 94,089 | 18 | 188,179 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
Input
The first line contains one integer number n (1 β€ n β€ 200) β length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Output
Print one integer number β volume of text.
Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
Submitted Solution:
```
a = int(input())
word = list(map(str,input().split(" ")))
print(word)
lst = []
for c in range(len(word)) :
count = 0
for i in range(len(word[c])):
if word[c][i].isupper():
count += 1
lst.append(count)
print(max(lst))
``` | instruction | 0 | 94,090 | 18 | 188,180 |
No | output | 1 | 94,090 | 18 | 188,181 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.