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. Limak can repeatedly remove one of the first two characters of a string, for example abcxyx \rightarrow acxyx \rightarrow cxyx \rightarrow cyx. You are given N different strings S_1, S_2, \ldots, S_N. Among N \cdot (N-1) / 2 pairs (S_i, S_j), in how many pairs could Limak obtain one string from the other? Constraints * 2 \leq N \leq 200\,000 * S_i consists of lowercase English letters `a`-`z`. * S_i \neq S_j * 1 \leq |S_i| * |S_1| + |S_2| + \ldots + |S_N| \leq 10^6 Input Input is given from Standard Input in the following format. N S_1 S_2 \vdots S_N Output Print the number of unordered pairs (S_i, S_j) where i \neq j and Limak can obtain one string from the other. Examples Input 3 abcxyx cyx abc Output 1 Input 6 b a abc c d ab Output 5 Submitted Solution: ``` mod1 = 1000000007 mod2 = 1000000009 base1 = 2009 base2 = 1007 eps = 10**-9 def main(): import sys input = sys.stdin.readline N = int(input()) S = [] for _ in range(N): s = input().rstrip('\n') S.append(s[::-1]) S.sort(key=lambda s: len(s), reverse=True) cnt = [] for s in S: c = [0] * 26 for ss in s: c[ord(ss) - 97] += 1 cnt.append(c) ans = 0 H1 = [0] * N H2 = [0] * N for L in range(1, 10**6+1): if not S: break M = len(S) key = [] i = M-1 dic_last = {} while i >= 0: if len(S[i]) == L: s = S.pop() cnt.pop() h1 = H1.pop() h2 = H2.pop() if L > 1: last = ord(s[L-2]) - 97 h1 = (h1 * base1 + last)%mod1 h2 = (h2 * base2 + last)%mod2 key.append((s, h1, h2)) else: if L > 1: ss = ord(S[i][L-2]) - 97 cnt[i][ss] -= 1 H1[i] = (H1[i] * base1 + ss)%mod1 H2[i] = (H2[i] * base2 + ss)%mod2 hh = H1[i] * (mod2+1) + H2[i] if hh not in dic_last: dic_last[hh] = [0] * 26 for j in range(26): if cnt[i][j] > 0: dic_last[hh][j] += 1 i -= 1 for s, h1, h2 in key: last = ord(s[-1]) - 97 h = h1 * (mod2+1) + h2 if L == 1: for i in range(len(cnt)): if cnt[i][last] > 0: ans += 1 else: if h in dic_last: ans += dic_last[h][last] #print(L, S, ans) print(ans) if __name__ == '__main__': main() ```
instruction
0
45,169
18
90,338
Yes
output
1
45,169
18
90,339
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak can repeatedly remove one of the first two characters of a string, for example abcxyx \rightarrow acxyx \rightarrow cxyx \rightarrow cyx. You are given N different strings S_1, S_2, \ldots, S_N. Among N \cdot (N-1) / 2 pairs (S_i, S_j), in how many pairs could Limak obtain one string from the other? Constraints * 2 \leq N \leq 200\,000 * S_i consists of lowercase English letters `a`-`z`. * S_i \neq S_j * 1 \leq |S_i| * |S_1| + |S_2| + \ldots + |S_N| \leq 10^6 Input Input is given from Standard Input in the following format. N S_1 S_2 \vdots S_N Output Print the number of unordered pairs (S_i, S_j) where i \neq j and Limak can obtain one string from the other. Examples Input 3 abcxyx cyx abc Output 1 Input 6 b a abc c d ab Output 5 Submitted Solution: ``` import sys from collections import Counter from string import ascii_lowercase def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 19 MOD = 10 ** 19 + 7 EPS = 10 ** -10 class RollingHash: """ 文字列stringの部分文字列のハッシュを構築する。O(N) """ def __init__(self, string): self.n = len(string) self.BASE = 1234 self.MASK30 = (1 << 30) - 1 self.MASK31 = (1 << 31) - 1 self.MASK61 = (1 << 61) - 1 self.MOD = self.MASK61 self.hash = [0] * (self.n + 1) self.pow = [1] * (self.n + 1) for i, char in enumerate(string): self.hash[i + 1] = self.calc_mod(self.mul(self.hash[i], self.BASE) + ord(char)) self.pow[i + 1] = self.calc_mod(self.mul(self.pow[i], self.BASE)) def calc_mod(self, x): """ x mod 2^61-1 を返す """ xu = x >> 61 xd = x & self.MASK61 x = xu + xd if x >= self.MOD: x -= self.MASK61 return x def mul(self, a, b): """ a*b mod 2^61-1 を返す """ au = a >> 31 ad = a & self.MASK31 bu = b >> 31 bd = b & self.MASK31 mid = ad * bu + au * bd midu = mid >> 30 midd = mid & self.MASK30 return self.calc_mod(au * bu * 2 + midu + (midd << 31) + ad * bd) def get_hash(self, l, r): """ string[l,r)のハッシュ値を返すO(1) """ res = self.calc_mod(self.hash[r] - self.mul(self.hash[l], self.pow[r - l])) return res def merge(self, h1, h2, length2): """ ハッシュ値h1と長さlength2のハッシュ値h2を結合するO(1) """ return self.calc_mod(self.mul(h1, self.pow[length2]) + h2) def get_lcp(self, l1, r1, l2, r2): """ string[l1:r2]とstring[l2:r2]の長共通接頭辞(Longest Common Prefix)の 長さを求めるO(log|string|) """ ng = min(r1 - l1, r2 - l2) + 1 ok = 0 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if self.get_hash(l1, l1 + mid) == self.get_hash(l2, l2 + mid): ok = mid else: ng = mid return ok N = INT() se = set() A = [] for i in range(N): s = input() s = s[::-1] rh = RollingHash(s) A.append((s, rh)) se.add(rh.get_hash(0, len(s))) ch = [0] * 26 for i, c in enumerate(ascii_lowercase): ch[i] = RollingHash(c).get_hash(0, 1) ans = 0 for s, rh in A: C = Counter(s) for i in range(len(s)): for j, c in enumerate(ascii_lowercase): if C[c]: if rh.merge(rh.get_hash(0, i), ch[j], 1) in se: ans += 1 C[s[i]] -= 1 if C[s[i]] == 0: del C[s[i]] ans -= N print(ans) ```
instruction
0
45,170
18
90,340
Yes
output
1
45,170
18
90,341
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak can repeatedly remove one of the first two characters of a string, for example abcxyx \rightarrow acxyx \rightarrow cxyx \rightarrow cyx. You are given N different strings S_1, S_2, \ldots, S_N. Among N \cdot (N-1) / 2 pairs (S_i, S_j), in how many pairs could Limak obtain one string from the other? Constraints * 2 \leq N \leq 200\,000 * S_i consists of lowercase English letters `a`-`z`. * S_i \neq S_j * 1 \leq |S_i| * |S_1| + |S_2| + \ldots + |S_N| \leq 10^6 Input Input is given from Standard Input in the following format. N S_1 S_2 \vdots S_N Output Print the number of unordered pairs (S_i, S_j) where i \neq j and Limak can obtain one string from the other. Examples Input 3 abcxyx cyx abc Output 1 Input 6 b a abc c d ab Output 5 Submitted Solution: ``` import sys sys.setrecursionlimit(10**8) from collections import defaultdict,Counter def saiki(cnts): hitomozi = [] d = defaultdict(lambda: []) heads = defaultdict(lambda: 0) for i in range(len(cnts)): if len(cnts[i][0])==1: hitomozi.append(cnts[i][0][0]) else: for k in cnts[i][1].keys(): heads[k] += 1 cnts[i][1][cnts[i][0][-1]] -= 1 t = cnts[i][0].pop(-1) d[t].append([cnts[i][0],cnts[i][1]]) for h in hitomozi: ans[0] += heads[h] for v in d.values(): saiki(v) N = int(input()) S = [list(input()) for _ in range(N)] ans = [0] cnts = [] for s in S: cnts.append([s,Counter(s)]) saiki(cnts) print(ans[0]) ```
instruction
0
45,171
18
90,342
No
output
1
45,171
18
90,343
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak can repeatedly remove one of the first two characters of a string, for example abcxyx \rightarrow acxyx \rightarrow cxyx \rightarrow cyx. You are given N different strings S_1, S_2, \ldots, S_N. Among N \cdot (N-1) / 2 pairs (S_i, S_j), in how many pairs could Limak obtain one string from the other? Constraints * 2 \leq N \leq 200\,000 * S_i consists of lowercase English letters `a`-`z`. * S_i \neq S_j * 1 \leq |S_i| * |S_1| + |S_2| + \ldots + |S_N| \leq 10^6 Input Input is given from Standard Input in the following format. N S_1 S_2 \vdots S_N Output Print the number of unordered pairs (S_i, S_j) where i \neq j and Limak can obtain one string from the other. Examples Input 3 abcxyx cyx abc Output 1 Input 6 b a abc c d ab Output 5 Submitted Solution: ``` from collections import defaultdict class RollingHash(): def __init__(self, s, base, mod): self.mod = mod self.pw = pw = [1]*(len(s)+1) l = len(s) self.h = h = [0]*(l+1) v = 0 for i in range(l): h[i+1] = v = (v * base + ord(s[i])) % mod v = 1 for i in range(l): pw[i+1] = v = v * base % mod def get(self, l, r): return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod N = int(input()) Slist = [] for i in range(N): S = input() Slist.append(S) Slist.sort(key=len) dic = defaultdict(lambda:defaultdict(int)) ans = 0 for S in Slist: alp = set() l = len(S) RH = RollingHash(S,37,10**9+7) for i in range(len(S)): alp.add(S[i]) alpdic = dic[RH.get(i+1,l)] for X in alpdic.keys(): if X in alp: ans += alpdic[X] dic[RH.get(1,l)][S[0]] += 1 print(ans) ```
instruction
0
45,172
18
90,344
No
output
1
45,172
18
90,345
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak can repeatedly remove one of the first two characters of a string, for example abcxyx \rightarrow acxyx \rightarrow cxyx \rightarrow cyx. You are given N different strings S_1, S_2, \ldots, S_N. Among N \cdot (N-1) / 2 pairs (S_i, S_j), in how many pairs could Limak obtain one string from the other? Constraints * 2 \leq N \leq 200\,000 * S_i consists of lowercase English letters `a`-`z`. * S_i \neq S_j * 1 \leq |S_i| * |S_1| + |S_2| + \ldots + |S_N| \leq 10^6 Input Input is given from Standard Input in the following format. N S_1 S_2 \vdots S_N Output Print the number of unordered pairs (S_i, S_j) where i \neq j and Limak can obtain one string from the other. Examples Input 3 abcxyx cyx abc Output 1 Input 6 b a abc c d ab Output 5 Submitted Solution: ``` n=int(input()) s=[] for i in range(n): s.append(input()) s[i]=s[i][::-1] s.sort() count=0 for i in range(n-1): j=i+1 while(True): if j>=n or s[i][:-1]!=s[j][:len(s[i])-1]: break for k in range(len(s[i])-1,len(s[j])): if s[i][-1]==s[j][k]: count+=1 break j+=1 print(count) ```
instruction
0
45,173
18
90,346
No
output
1
45,173
18
90,347
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak can repeatedly remove one of the first two characters of a string, for example abcxyx \rightarrow acxyx \rightarrow cxyx \rightarrow cyx. You are given N different strings S_1, S_2, \ldots, S_N. Among N \cdot (N-1) / 2 pairs (S_i, S_j), in how many pairs could Limak obtain one string from the other? Constraints * 2 \leq N \leq 200\,000 * S_i consists of lowercase English letters `a`-`z`. * S_i \neq S_j * 1 \leq |S_i| * |S_1| + |S_2| + \ldots + |S_N| \leq 10^6 Input Input is given from Standard Input in the following format. N S_1 S_2 \vdots S_N Output Print the number of unordered pairs (S_i, S_j) where i \neq j and Limak can obtain one string from the other. Examples Input 3 abcxyx cyx abc Output 1 Input 6 b a abc c d ab Output 5 Submitted Solution: ``` n = int(input()) s = [] for i in range(n): s.append(input()) r = 0 for i in range(n): for j in range(i + 1, n): a, b = s[i], s[j] if len(a) < len(b): a, b = b, a l = len(b) - 1 if (l == 0 and b in a) or (b[0] in a[:-l] and a[-l:] == b[1:]): r += 1 print(r) ```
instruction
0
45,174
18
90,348
No
output
1
45,174
18
90,349
Provide a correct Python 3 solution for this coding contest problem. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. Constraints * The length of S is 4. * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If S consists of exactly two kinds of characters which both appear twice in S, print `Yes`; otherwise, print `No`. Examples Input ASSA Output Yes Input STOP Output No Input FFEE Output Yes Input FREE Output No
instruction
0
45,207
18
90,414
"Correct Solution: ``` S=sorted(input()) print('Yes' if S[0]==S[1] and S[2]==S[3] and S[0]!=S[2] else 'No') ```
output
1
45,207
18
90,415
Provide a correct Python 3 solution for this coding contest problem. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. Constraints * The length of S is 4. * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If S consists of exactly two kinds of characters which both appear twice in S, print `Yes`; otherwise, print `No`. Examples Input ASSA Output Yes Input STOP Output No Input FFEE Output Yes Input FREE Output No
instruction
0
45,208
18
90,416
"Correct Solution: ``` s=list(set(input()));print("Yes") if len(s)==2 else print("No") ```
output
1
45,208
18
90,417
Provide a correct Python 3 solution for this coding contest problem. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. Constraints * The length of S is 4. * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If S consists of exactly two kinds of characters which both appear twice in S, print `Yes`; otherwise, print `No`. Examples Input ASSA Output Yes Input STOP Output No Input FFEE Output Yes Input FREE Output No
instruction
0
45,209
18
90,418
"Correct Solution: ``` a=input() print('YNeos'[sum(map(a.count,a))!=8::2]) ```
output
1
45,209
18
90,419
Provide a correct Python 3 solution for this coding contest problem. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. Constraints * The length of S is 4. * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If S consists of exactly two kinds of characters which both appear twice in S, print `Yes`; otherwise, print `No`. Examples Input ASSA Output Yes Input STOP Output No Input FFEE Output Yes Input FREE Output No
instruction
0
45,210
18
90,420
"Correct Solution: ``` #ABC132 s = input() print("Yes" if len(set(s))==2 and s.count(s[0])==2 else "No") ```
output
1
45,210
18
90,421
Provide a correct Python 3 solution for this coding contest problem. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. Constraints * The length of S is 4. * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If S consists of exactly two kinds of characters which both appear twice in S, print `Yes`; otherwise, print `No`. Examples Input ASSA Output Yes Input STOP Output No Input FFEE Output Yes Input FREE Output No
instruction
0
45,211
18
90,422
"Correct Solution: ``` s=input() if len(set(list(s)))==2:print('Yes') else:print('No') ```
output
1
45,211
18
90,423
Provide a correct Python 3 solution for this coding contest problem. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. Constraints * The length of S is 4. * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If S consists of exactly two kinds of characters which both appear twice in S, print `Yes`; otherwise, print `No`. Examples Input ASSA Output Yes Input STOP Output No Input FFEE Output Yes Input FREE Output No
instruction
0
45,212
18
90,424
"Correct Solution: ``` s = input() print("Yes" if all(map(lambda c: s.count(c) == 2, s)) else "No") ```
output
1
45,212
18
90,425
Provide a correct Python 3 solution for this coding contest problem. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. Constraints * The length of S is 4. * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If S consists of exactly two kinds of characters which both appear twice in S, print `Yes`; otherwise, print `No`. Examples Input ASSA Output Yes Input STOP Output No Input FFEE Output Yes Input FREE Output No
instruction
0
45,213
18
90,426
"Correct Solution: ``` S=input();s=set(S);print('NYoe s'[len(s)==2 and S.count(list(s)[0])==2::2]) ```
output
1
45,213
18
90,427
Provide a correct Python 3 solution for this coding contest problem. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. Constraints * The length of S is 4. * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If S consists of exactly two kinds of characters which both appear twice in S, print `Yes`; otherwise, print `No`. Examples Input ASSA Output Yes Input STOP Output No Input FFEE Output Yes Input FREE Output No
instruction
0
45,214
18
90,428
"Correct Solution: ``` s=list(input()) if len(set(s))==2 and s.count(s[0]): print('Yes') else: print('No') ```
output
1
45,214
18
90,429
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. Constraints * The length of S is 4. * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If S consists of exactly two kinds of characters which both appear twice in S, print `Yes`; otherwise, print `No`. Examples Input ASSA Output Yes Input STOP Output No Input FFEE Output Yes Input FREE Output No Submitted Solution: ``` s = input() if len(set(list(s))) == 2: print("Yes") else: print("No") ```
instruction
0
45,215
18
90,430
Yes
output
1
45,215
18
90,431
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. Constraints * The length of S is 4. * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If S consists of exactly two kinds of characters which both appear twice in S, print `Yes`; otherwise, print `No`. Examples Input ASSA Output Yes Input STOP Output No Input FFEE Output Yes Input FREE Output No Submitted Solution: ``` s = set(input()) if len(s) == 2: print('Yes') else: print('No') ```
instruction
0
45,216
18
90,432
Yes
output
1
45,216
18
90,433
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. Constraints * The length of S is 4. * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If S consists of exactly two kinds of characters which both appear twice in S, print `Yes`; otherwise, print `No`. Examples Input ASSA Output Yes Input STOP Output No Input FFEE Output Yes Input FREE Output No Submitted Solution: ``` s=sorted(input()) print('Yes'if(s[0]==s[1]!=s[2]==s[3])else'No') ```
instruction
0
45,217
18
90,434
Yes
output
1
45,217
18
90,435
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. Constraints * The length of S is 4. * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If S consists of exactly two kinds of characters which both appear twice in S, print `Yes`; otherwise, print `No`. Examples Input ASSA Output Yes Input STOP Output No Input FFEE Output Yes Input FREE Output No Submitted Solution: ``` s=sorted(input()) print("Yes"if s[1]!=s[2]and len(set(s))==2 else"No") ```
instruction
0
45,218
18
90,436
Yes
output
1
45,218
18
90,437
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. Constraints * The length of S is 4. * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If S consists of exactly two kinds of characters which both appear twice in S, print `Yes`; otherwise, print `No`. Examples Input ASSA Output Yes Input STOP Output No Input FFEE Output Yes Input FREE Output No Submitted Solution: ``` n=input() ps=input() n=int(n[0]) ps=ps.split() ps=[int(ps) for ps in ps] output=0 for i in range(n-2): if ps[i]<ps[i+1] and ps[i+1]<ps[i+2]: output=output+1 elif ps[i+2]<ps[i+1] and ps[i+1]<ps[i]: output=output+1 else:output=output+0 print(output) ```
instruction
0
45,219
18
90,438
No
output
1
45,219
18
90,439
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. Constraints * The length of S is 4. * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If S consists of exactly two kinds of characters which both appear twice in S, print `Yes`; otherwise, print `No`. Examples Input ASSA Output Yes Input STOP Output No Input FFEE Output Yes Input FREE Output No Submitted Solution: ``` n=input() p=input() n=int(n[0]) p=p.split() p=[int(p) for p in p] output=0 for i in range(n-2): if p[i]<p[i+1] and p[i+1]<p[i+2]: output=output+1 elif p[i+2]<p[i+1] and p[i+1]<p[i]: output=output+1 else: output=output+0 print(output) ```
instruction
0
45,220
18
90,440
No
output
1
45,220
18
90,441
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. Constraints * The length of S is 4. * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If S consists of exactly two kinds of characters which both appear twice in S, print `Yes`; otherwise, print `No`. Examples Input ASSA Output Yes Input STOP Output No Input FFEE Output Yes Input FREE Output No Submitted Solution: ``` print('Yes' if len(set(input().split()))==2 else 'No') ```
instruction
0
45,221
18
90,442
No
output
1
45,221
18
90,443
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. Constraints * The length of S is 4. * S consists of uppercase English letters. Input Input is given from Standard Input in the following format: S Output If S consists of exactly two kinds of characters which both appear twice in S, print `Yes`; otherwise, print `No`. Examples Input ASSA Output Yes Input STOP Output No Input FFEE Output Yes Input FREE Output No Submitted Solution: ``` s = list(input()) s.sort() if s[0]==s[1] and s[2]==s[4]: print("Yes") else: print("No") ```
instruction
0
45,222
18
90,444
No
output
1
45,222
18
90,445
Provide a correct Python 3 solution for this coding contest problem. Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI Output YES Input JUROR Output YES Input YES Output NO
instruction
0
46,263
18
92,526
"Correct Solution: ``` x=[] mylist=list(input()) for i in mylist: if i in "BCDGJOPQRSU": x.append(True) else: x.append(False) if all(x[0] == elem for elem in x): print("YES") else: print("NO") ```
output
1
46,263
18
92,527
Provide a correct Python 3 solution for this coding contest problem. Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI Output YES Input JUROR Output YES Input YES Output NO
instruction
0
46,264
18
92,528
"Correct Solution: ``` s = list(input()) L = ['A','E','F','H','I','K','L','M','N','T','V','W','X','Y','Z'] C = ['B','C','D','G','J','O','P','Q','R','S','U'] total = 0 for i in s: if i in L: total += 1 if i in C: total += 2 if total == len(s) or total == len(s)*2: print("YES") else: print("NO") ```
output
1
46,264
18
92,529
Provide a correct Python 3 solution for this coding contest problem. Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI Output YES Input JUROR Output YES Input YES Output NO
instruction
0
46,265
18
92,530
"Correct Solution: ``` n, cnt = input(), 0 for i in n: if i in set('AEFHIKLMNTVWXYZ'): cnt += 1 print('YES' if cnt == 0 or cnt == len(n) else 'NO') ```
output
1
46,265
18
92,531
Provide a correct Python 3 solution for this coding contest problem. Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI Output YES Input JUROR Output YES Input YES Output NO
instruction
0
46,266
18
92,532
"Correct Solution: ``` # coding: utf-8 word = input() count = len([letter for letter in word if letter in 'AEFHIKLMNTVWXYZ']) print('YES') if count == 0 or count == len(word) else print('NO') ```
output
1
46,266
18
92,533
Provide a correct Python 3 solution for this coding contest problem. Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI Output YES Input JUROR Output YES Input YES Output NO
instruction
0
46,267
18
92,534
"Correct Solution: ``` n=input() s='AEFHIKLMNTVWXYZ' t='BCDGJOPQRSU' f1=0 f2=0 for i in s: if i in n:f1=1 for i in t: if i in n:f2=1 if f1+f2==1:print('YES') else:print('NO') ```
output
1
46,267
18
92,535
Provide a correct Python 3 solution for this coding contest problem. Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI Output YES Input JUROR Output YES Input YES Output NO
instruction
0
46,268
18
92,536
"Correct Solution: ``` a=input();print(('NO','YES')[sum(x in'AEFHIKLMNTVWXYZ'for x in a)in(0,len(a))]) ```
output
1
46,268
18
92,537
Provide a correct Python 3 solution for this coding contest problem. Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI Output YES Input JUROR Output YES Input YES Output NO
instruction
0
46,269
18
92,538
"Correct Solution: ``` NEAT="AEFHIKLMNTVWXYZ" a=input() if all(x in NEAT for x in a) or all(x not in NEAT for x in a) : print("YES") else: print("NO") ```
output
1
46,269
18
92,539
Provide a correct Python 3 solution for this coding contest problem. Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI Output YES Input JUROR Output YES Input YES Output NO
instruction
0
46,270
18
92,540
"Correct Solution: ``` ll = ['A','E','F','H','I','K','L','M','N','T','V','W','X','Y','Z'] s = input() f1 = 0 f2 = 0 for i in range(len(s)): f1 = 0 for j in range(15): if (s[i] == ll[j]): f1 = 1 if (not(i)): f2 = 1 else: if (not(f2)): print("NO") exit() if(not(f1)): if(not(i)): f2 = 0 else: if(f2): print("NO") exit() print("YES") ```
output
1
46,270
18
92,541
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI Output YES Input JUROR Output YES Input YES Output NO Submitted Solution: ``` lin = set(list('WETYIAFHKLZXVNM')) s = input() print('YES' if len(set(list(s)).intersection(lin)) in [len(set(list(s))), 0] else 'NO') ```
instruction
0
46,271
18
92,542
Yes
output
1
46,271
18
92,543
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI Output YES Input JUROR Output YES Input YES Output NO Submitted Solution: ``` s = str(input()) straight = ["A", "E", "F", "H", "I", "K", "L", "M", "N", "T", "V", "W","X", "Y", "Z"] bendy = [i for i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" if i not in straight] ans=0 for i in s: if i in straight: ans+=1 if ans % len(s) == 0: print("YES") else: print("NO") ```
instruction
0
46,272
18
92,544
Yes
output
1
46,272
18
92,545
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI Output YES Input JUROR Output YES Input YES Output NO Submitted Solution: ``` a = input() b = len(a) c = [] for i in range(b): c.append(a[i]) d = 0 dict1 = dict(W=1,E=1,T=1,Y=1,I=1,A=1,F=1,H=1,K=1,L=1,Z=1,X=1,V=1,N=1,M=1,Q=0,R=0,U=0,O=0,P=0,S=0,D=0,G=0,J=0,C=0,B=0) for i in range(b): d += dict1.get(c[i]) if d == 0 or d == b: print('YES') else: print('NO') ```
instruction
0
46,273
18
92,546
Yes
output
1
46,273
18
92,547
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI Output YES Input JUROR Output YES Input YES Output NO Submitted Solution: ``` def main(): a = set('AEFHIKLMNTVWXYZ') b = set('BCDGJOPQRSU') w = list(input()) in_a = False in_b = False for l in w: in_a = in_a or l in a in_b = in_b or l in b if in_a and in_b: print('NO') else: print('YES') if __name__ == '__main__': main() ```
instruction
0
46,274
18
92,548
Yes
output
1
46,274
18
92,549
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI Output YES Input JUROR Output YES Input YES Output NO Submitted Solution: ``` def li(): return list(map(int, input().split(" "))) a = "AEFHIKLMNPTVWXYZ" b = "BCDGJOQRSU" aa = bb = False for i in input(): if i in a: aa = True else: bb = True if aa^bb: print("Yes") else: print("No") ```
instruction
0
46,275
18
92,550
No
output
1
46,275
18
92,551
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI Output YES Input JUROR Output YES Input YES Output NO Submitted Solution: ``` z="QWERTYUIOPASDFGHJKLZXCVBNM" t="01101101001001010111101011" s = input() for i in s: for j in range(26): if z[j] == i: if t[j] == '0': print('NO') exit(0) print('YES') ```
instruction
0
46,276
18
92,552
No
output
1
46,276
18
92,553
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI Output YES Input JUROR Output YES Input YES Output NO Submitted Solution: ``` NEAT="AEFHIKLMNTVWXYZ" a=input() for x in a: if x in NEAT : print("YES") else: print("NO") ```
instruction
0
46,277
18
92,554
No
output
1
46,277
18
92,555
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI Output YES Input JUROR Output YES Input YES Output NO Submitted Solution: ``` n, cnt = input(), 0 for i in n: if i in set('AEIOU'): cnt += 1 print('YES' if 2 * cnt >= len(n) else 'NO') ```
instruction
0
46,278
18
92,556
No
output
1
46,278
18
92,557
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|. First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal. After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 ≤ l ≤ i ≤ r ≤ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring. Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically. Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them. Input The first line contains the only integer n (1 ≤ n ≤ 100) — the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter. Output Output the only line — Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically. The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 ≤ i ≤ |a|), that ai < bi, and for any j (1 ≤ j < i) aj = bj. |a| stands for the length of string a. Examples Input 3 bers ucky elu PetrLoveLuckyNumbers t Output PetrLovtTttttNumtttt Input 4 hello party abefglghjdhfgj IVan petrsmatchwin a Output petrsmatchwin Input 2 aCa cba abAcaba c Output abCacba Submitted Solution: ``` s = [input().lower() for i in range(int(input()))] u, x = input(), input() y = 'ab'[x == 'a'] d = [(x, y), (x.upper(), y.upper())] v = u.lower() n = len(v) k = [0] * (n + 1) for q in s: i = v.find(q) while i != -1: k[i] += 1 k[i + len(q)] -= 1 i = v.find(q, i + 1) p = '' for i in range(n): k[i + 1] += k[i] p += d[u[i] != v[i]][x == v[i]] if k[i] else u[i] print(p) ```
instruction
0
46,816
18
93,632
Yes
output
1
46,816
18
93,633
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|. First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal. After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 ≤ l ≤ i ≤ r ≤ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring. Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically. Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them. Input The first line contains the only integer n (1 ≤ n ≤ 100) — the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter. Output Output the only line — Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically. The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 ≤ i ≤ |a|), that ai < bi, and for any j (1 ≤ j < i) aj = bj. |a| stands for the length of string a. Examples Input 3 bers ucky elu PetrLoveLuckyNumbers t Output PetrLovtTttttNumtttt Input 4 hello party abefglghjdhfgj IVan petrsmatchwin a Output petrsmatchwin Input 2 aCa cba abAcaba c Output abCacba Submitted Solution: ``` def main(): n = int(input()) forbidden = [input() for _ in range(n)] res = input() f = [0 for i in range(len(res))] letter = input() for i in range(n): for j in range(len(res)): if len(res[j:]) < len(forbidden[i]): break if res[j: j + len(forbidden[i])].upper() == forbidden[i].upper(): for k in range(j, j + len(forbidden[i])): f[k] = 1 ans = "" for i in range(len(res)): if (f[i] == 1): if (res[i].upper() == letter.upper()): if letter.upper() == 'A': if res[i].isupper(): ans = ans + 'B' else: ans = ans + 'b' else: if res[i].isupper(): ans = ans + 'A' else: ans = ans + 'a' else: if res[i].isupper(): ans = ans + letter.upper() else: ans = ans + letter else: ans = ans + res[i] print( ans) if __name__ == '__main__': main() ```
instruction
0
46,817
18
93,634
Yes
output
1
46,817
18
93,635
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|. First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal. After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 ≤ l ≤ i ≤ r ≤ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring. Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically. Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them. Input The first line contains the only integer n (1 ≤ n ≤ 100) — the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter. Output Output the only line — Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically. The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 ≤ i ≤ |a|), that ai < bi, and for any j (1 ≤ j < i) aj = bj. |a| stands for the length of string a. Examples Input 3 bers ucky elu PetrLoveLuckyNumbers t Output PetrLovtTttttNumtttt Input 4 hello party abefglghjdhfgj IVan petrsmatchwin a Output petrsmatchwin Input 2 aCa cba abAcaba c Output abCacba Submitted Solution: ``` # Legends Always Come Up with Solution # Author: Manvir Singh import os from io import BytesIO, IOBase import sys from collections import defaultdict,deque,Counter from bisect import * from math import sqrt,pi,ceil,log import math from itertools import permutations from copy import deepcopy from sys import setrecursionlimit def main(): n = int(input()) a = [] for i in range(n): a.append(input().rstrip()) w = list(input().rstrip()) c = input().rstrip() m = len(w) z = [] i = 0 while i < m: for j in range(n): if w[i].lower() == a[j][0].lower(): if i + len(a[j]) <= m: f = 1 for k in range(i,i+len(a[j])): if w[k].lower() != a[j][k-i].lower(): f=0 break if f: if len(z)!=0: if z[-1][1]>=i: z[-1][1]=max(i+len(a[j])-1,z[-1][1]) else: z.append([i,i+len(a[j])-1]) else: z.append([i,i+len(a[j])-1]) i += 1 for i in z: for k in range(i[0],i[1]+1): if w[k].isupper(): if w[k] != c.upper(): w[k] = c.upper() else: if w[k] != "A": w[k] = "A" else: w[k] = "B" else: if w[k] != c.lower(): w[k] = c.lower() else: if w[k] != "a": w[k] = "a" else: w[k] = "b" print("".join(w)) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == "__main__": main() ```
instruction
0
46,818
18
93,636
Yes
output
1
46,818
18
93,637
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|. First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal. After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 ≤ l ≤ i ≤ r ≤ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring. Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically. Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them. Input The first line contains the only integer n (1 ≤ n ≤ 100) — the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter. Output Output the only line — Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically. The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 ≤ i ≤ |a|), that ai < bi, and for any j (1 ≤ j < i) aj = bj. |a| stands for the length of string a. Examples Input 3 bers ucky elu PetrLoveLuckyNumbers t Output PetrLovtTttttNumtttt Input 4 hello party abefglghjdhfgj IVan petrsmatchwin a Output petrsmatchwin Input 2 aCa cba abAcaba c Output abCacba Submitted Solution: ``` #from bisect import bisect_left as bl #c++ lowerbound bl(array,element) #from bisect import bisect_right as br #c++ upperbound br(array,element) #from __future__ import print_function, division #while using python2 # from itertools import accumulate # from collections import defaultdict, Counter def modinv(n,p): return pow(n,p-2,p) def main(): #sys.stdin = open('input.txt', 'r') #sys.stdout = open('output.txt', 'w') n = int(input()) forbidden = [] for i in range(n): forbidden.append(input()) parent = input() c = input() to_be_replaced = set() for key in forbidden: s = parent.lower() key = key.lower() i = 0 while s[i:].find(key) != -1: i = i + s[i:].find(key) for j in range(i, i+len(key)): to_be_replaced.add(j) i += 1 # print(i) # input() # print("after key", key) # print(to_be_replaced) ans = [] for i in range(len(parent)): cur = parent[i] if i in to_be_replaced: # print("cur =", cur) if cur == c.lower() or cur == c.upper(): if c in 'aA': if cur.islower(): ans.append('b') else: ans.append('B') else: if cur.islower(): ans.append('a') else: ans.append('A') elif cur == cur.upper(): ans.append(c.upper()) elif cur == cur.lower(): ans.append(c.lower()) else: ans.append(cur) print("".join(ans)) #------------------ Python 2 and 3 footer by Pajenegod and c1729----------------------------------------- py2 = round(0.5) if py2: from future_builtins import ascii, filter, hex, map, oct, zip range = xrange import os, sys from io import IOBase, BytesIO BUFSIZE = 8192 class FastIO(BytesIO): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.writable = "x" in file.mode or "w" in file.mode self.write = super(FastIO, self).write if self.writable else None def _fill(self): s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0]) return s def read(self): while self._fill(): pass return super(FastIO,self).read() def readline(self): while self.newlines == 0: s = self._fill(); self.newlines = s.count(b"\n") + (not s) self.newlines -= 1 return super(FastIO, self).readline() def flush(self): if self.writable: os.write(self._fd, self.getvalue()) self.truncate(0), self.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable if py2: self.write = self.buffer.write self.read = self.buffer.read self.readline = self.buffer.readline else: self.write = lambda s:self.buffer.write(s.encode('ascii')) self.read = lambda:self.buffer.read().decode('ascii') self.readline = lambda:self.buffer.readline().decode('ascii') sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip('\r\n') if __name__ == '__main__': main() ```
instruction
0
46,819
18
93,638
Yes
output
1
46,819
18
93,639
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|. First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal. After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 ≤ l ≤ i ≤ r ≤ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring. Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically. Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them. Input The first line contains the only integer n (1 ≤ n ≤ 100) — the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter. Output Output the only line — Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically. The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 ≤ i ≤ |a|), that ai < bi, and for any j (1 ≤ j < i) aj = bj. |a| stands for the length of string a. Examples Input 3 bers ucky elu PetrLoveLuckyNumbers t Output PetrLovtTttttNumtttt Input 4 hello party abefglghjdhfgj IVan petrsmatchwin a Output petrsmatchwin Input 2 aCa cba abAcaba c Output abCacba Submitted Solution: ``` # Legends Always Come Up with Solution # Author: Manvir Singh import os from io import BytesIO, IOBase import sys from collections import defaultdict,deque,Counter from bisect import * from math import sqrt,pi,ceil,log import math from itertools import permutations from copy import deepcopy from sys import setrecursionlimit def main(): n = int(input()) a = [] for i in range(n): a.append(input().rstrip()) w = list(input().rstrip()) c = input().rstrip() m = len(w) z = [] i = 0 while i < m: for j in range(n): if w[i].lower() == a[j][0].lower(): if i + len(a[j]) <= m: f = 1 for k in range(i, i + len(a[j])): if w[k].lower() != a[j][k - i].lower(): f = 0 if f: if z != []: if z[-1][1] >= i: z[-1][1] = i + len(a[j]) - 1 else: z.append([i, i + len(a[j]) - 1]) else: z.append([i, i + len(a[j]) - 1]) i += 1 for i in z: for k in range(i[0], i[1] + 1): if w[k].isupper(): if w[k] != c.upper(): w[k] = c.upper() else: if w[k] != "A": w[k] = "A" else: w[k] = "B" else: if w[k] != c.lower(): w[k] = c else: if w[k] != "a": w[k] = "a" else: w[k] = "b" print("".join(w)) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == "__main__": main() ```
instruction
0
46,820
18
93,640
No
output
1
46,820
18
93,641
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|. First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal. After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 ≤ l ≤ i ≤ r ≤ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring. Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically. Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them. Input The first line contains the only integer n (1 ≤ n ≤ 100) — the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter. Output Output the only line — Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically. The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 ≤ i ≤ |a|), that ai < bi, and for any j (1 ≤ j < i) aj = bj. |a| stands for the length of string a. Examples Input 3 bers ucky elu PetrLoveLuckyNumbers t Output PetrLovtTttttNumtttt Input 4 hello party abefglghjdhfgj IVan petrsmatchwin a Output petrsmatchwin Input 2 aCa cba abAcaba c Output abCacba Submitted Solution: ``` n = int(input()) f = [] for z in range(n): f.append(input()) w = input() letter = input() t = [] for forb in f: if forb.casefold() in w.casefold(): #print(forb,f) x = w.casefold().index(forb.casefold()) t.append((x,x+len(forb))) #print(t) for tup in t: for l in range(tup[0],tup[1]): if w[l] != letter.casefold(): if w[l].isupper(): w = w[:l]+letter.capitalize()+w[l+1:] else: w = w[:l] + letter + w[l + 1:] elif w[l] == letter.casefold() and letter == 'a'.casefold(): if w[l].isupper(): w = w[:l] + 'B' + w[l + 1:] else: w = w[:l] + 'b' + w[l + 1:] elif w[l] == letter.casefold() and letter != 'a'.casefold(): if w[l].isupper(): w = w[:l] + 'A' + w[l + 1:] else: w = w[:l] + 'a' + w[l + 1:] print(w) ```
instruction
0
46,821
18
93,642
No
output
1
46,821
18
93,643
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|. First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal. After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 ≤ l ≤ i ≤ r ≤ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring. Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically. Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them. Input The first line contains the only integer n (1 ≤ n ≤ 100) — the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter. Output Output the only line — Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically. The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 ≤ i ≤ |a|), that ai < bi, and for any j (1 ≤ j < i) aj = bj. |a| stands for the length of string a. Examples Input 3 bers ucky elu PetrLoveLuckyNumbers t Output PetrLovtTttttNumtttt Input 4 hello party abefglghjdhfgj IVan petrsmatchwin a Output petrsmatchwin Input 2 aCa cba abAcaba c Output abCacba Submitted Solution: ``` import sys def inpt(): return sys.stdin.readline().strip() n=int(inpt()) zlo=[] for i in range(n): s=inpt() s=s.lower() zlo.append(s) s=inpt() leter=inpt() leter=leter.lower() slov=[] upper=[] for i in range(len(s)): slov.append(s[i]) if 65 <=ord(s[i]) <91: upper.append(i) s=s.lower() for i in zlo: tmp=s k=0 fi=tmp.find(i) while fi!=-1: for j in range(len(i)): if s[fi+j+k]!=leter: slov[fi+j+k]=leter elif leter=='a': slov[fi+j+k]='b' else: slov[fi+j-k]='a' tmp=tmp[fi+1:] k+=fi+1 fi=tmp.find(i) for i in upper: slov[i]=slov[i].upper() else: for i in slov: print(i,end="") ```
instruction
0
46,822
18
93,644
No
output
1
46,822
18
93,645
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|. First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal. After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 ≤ l ≤ i ≤ r ≤ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring. Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically. Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them. Input The first line contains the only integer n (1 ≤ n ≤ 100) — the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter. Output Output the only line — Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically. The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 ≤ i ≤ |a|), that ai < bi, and for any j (1 ≤ j < i) aj = bj. |a| stands for the length of string a. Examples Input 3 bers ucky elu PetrLoveLuckyNumbers t Output PetrLovtTttttNumtttt Input 4 hello party abefglghjdhfgj IVan petrsmatchwin a Output petrsmatchwin Input 2 aCa cba abAcaba c Output abCacba Submitted Solution: ``` from math import* a=[list(input().lower()) for i in range(int(input()))] s=input() s0=list(s) s=list(s.lower()) c=input() C=chr(ord(c)-ord('a')+ord('A')) r=['.']*len(s) for t in a: for i in range(len(s)-len(t)+1): #print(s[i:i+len(t)],t) if(s[i:i+len(t)]==t): r[i:i+len(t)]=t s=s0 for i in range(len(s)): if r[i]!='.': if ord(s[i])<=ord('Z'): if s[i]==C: s[i]='A' else: s[i]=C else: if s[i]==c: s[i]='a' else: s[i]=c print(*s,sep='') ```
instruction
0
46,823
18
93,646
No
output
1
46,823
18
93,647
Provide a correct Python 3 solution for this coding contest problem. Write a program which reverses a given string str. Input str (the size of str ≤ 20) is given in a line. Output Print the reversed str in a line. Example Input w32nimda Output admin23w
instruction
0
46,942
18
93,884
"Correct Solution: ``` instr=input() print(instr[::-1]) ```
output
1
46,942
18
93,885
Provide a correct Python 3 solution for this coding contest problem. Write a program which reverses a given string str. Input str (the size of str ≤ 20) is given in a line. Output Print the reversed str in a line. Example Input w32nimda Output admin23w
instruction
0
46,943
18
93,886
"Correct Solution: ``` a=[] str=str(input()) for i in range(len(str)): b=str[-(i+1)] a.append(b) a=''.join(a) print(a) ```
output
1
46,943
18
93,887
Provide a correct Python 3 solution for this coding contest problem. Write a program which reverses a given string str. Input str (the size of str ≤ 20) is given in a line. Output Print the reversed str in a line. Example Input w32nimda Output admin23w
instruction
0
46,944
18
93,888
"Correct Solution: ``` a = input() b = a[::-1] print(b) ```
output
1
46,944
18
93,889
Provide a correct Python 3 solution for this coding contest problem. Write a program which reverses a given string str. Input str (the size of str ≤ 20) is given in a line. Output Print the reversed str in a line. Example Input w32nimda Output admin23w
instruction
0
46,945
18
93,890
"Correct Solution: ``` # coding: utf-8 # Your code here! s = list(input()) s.reverse() for i in range(len(s)): print(s[i], end = "") print("") ```
output
1
46,945
18
93,891