message
stringlengths
2
23.8k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
97
109k
cluster
float64
0
0
__index_level_0__
int64
194
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings a and b. It is known that |b| ≀ |a|, that is, the length of b is at most the length of a. The Cossack considers every substring of length |b| in string a. Let's call this substring c. He matches the corresponding characters in b and c, after which he counts the number of positions where the two strings are different. We call this function f(b, c). For example, let b = 00110, and c = 11000. In these strings, the first, second, third and fourth positions are different. Vus the Cossack counts the number of such substrings c such that f(b, c) is even. For example, let a = 01100010 and b = 00110. a has four substrings of the length |b|: 01100, 11000, 10001, 00010. * f(00110, 01100) = 2; * f(00110, 11000) = 4; * f(00110, 10001) = 4; * f(00110, 00010) = 1. Since in three substrings, f(b, c) is even, the answer is 3. Vus can not find the answer for big strings. That is why he is asking you to help him. Input The first line contains a binary string a (1 ≀ |a| ≀ 10^6) β€” the first string. The second line contains a binary string b (1 ≀ |b| ≀ |a|) β€” the second string. Output Print one number β€” the answer. Examples Input 01100010 00110 Output 3 Input 1010111110 0110 Output 4 Note The first example is explained in the legend. In the second example, there are five substrings that satisfy us: 1010, 0101, 1111, 1111. Submitted Solution: ``` a = input() b = input() Ans = 0 for i in range(len(b),len(a)+1): Parity = 0 B = 0 for j in range((i-len(b)), i): if(a[j] != b[B]): Parity+=1 B+=1 if(not (Parity&1)): Ans+=1 print(Ans) ```
instruction
0
79,999
0
159,998
No
output
1
79,999
0
159,999
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings a and b. It is known that |b| ≀ |a|, that is, the length of b is at most the length of a. The Cossack considers every substring of length |b| in string a. Let's call this substring c. He matches the corresponding characters in b and c, after which he counts the number of positions where the two strings are different. We call this function f(b, c). For example, let b = 00110, and c = 11000. In these strings, the first, second, third and fourth positions are different. Vus the Cossack counts the number of such substrings c such that f(b, c) is even. For example, let a = 01100010 and b = 00110. a has four substrings of the length |b|: 01100, 11000, 10001, 00010. * f(00110, 01100) = 2; * f(00110, 11000) = 4; * f(00110, 10001) = 4; * f(00110, 00010) = 1. Since in three substrings, f(b, c) is even, the answer is 3. Vus can not find the answer for big strings. That is why he is asking you to help him. Input The first line contains a binary string a (1 ≀ |a| ≀ 10^6) β€” the first string. The second line contains a binary string b (1 ≀ |b| ≀ |a|) β€” the second string. Output Print one number β€” the answer. Examples Input 01100010 00110 Output 3 Input 1010111110 0110 Output 4 Note The first example is explained in the legend. In the second example, there are five substrings that satisfy us: 1010, 0101, 1111, 1111. Submitted Solution: ``` a=input() b=input() chetcount=0 for i in range(len(b),len(a)+1): c=a[i-len(b):i] count=0 for j in range(len(c)): if b[j]==c[j]: count+=1 if count%2==1: chetcount+=1 print(chetcount) ```
instruction
0
80,000
0
160,000
No
output
1
80,000
0
160,001
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings a and b. It is known that |b| ≀ |a|, that is, the length of b is at most the length of a. The Cossack considers every substring of length |b| in string a. Let's call this substring c. He matches the corresponding characters in b and c, after which he counts the number of positions where the two strings are different. We call this function f(b, c). For example, let b = 00110, and c = 11000. In these strings, the first, second, third and fourth positions are different. Vus the Cossack counts the number of such substrings c such that f(b, c) is even. For example, let a = 01100010 and b = 00110. a has four substrings of the length |b|: 01100, 11000, 10001, 00010. * f(00110, 01100) = 2; * f(00110, 11000) = 4; * f(00110, 10001) = 4; * f(00110, 00010) = 1. Since in three substrings, f(b, c) is even, the answer is 3. Vus can not find the answer for big strings. That is why he is asking you to help him. Input The first line contains a binary string a (1 ≀ |a| ≀ 10^6) β€” the first string. The second line contains a binary string b (1 ≀ |b| ≀ |a|) β€” the second string. Output Print one number β€” the answer. Examples Input 01100010 00110 Output 3 Input 1010111110 0110 Output 4 Note The first example is explained in the legend. In the second example, there are five substrings that satisfy us: 1010, 0101, 1111, 1111. Submitted Solution: ``` a = input() b = input() na = len(a) nb = len(b) cntc = cntb = 0 for i in range(nb): if b[i] == '1': cntb += 1 if a[i] == '1': cntc += 1 ans = 0 if cntb % 2 == cntc % 2: ans += 1 for i in range(1, na): if i + nb >= na: break else: if a[i - 1] == '1': cntc -= 1 if a[i + nb - 1] == '1': cntc += 1 if cntb % 2 == cntc % 2: ans += 1 print(ans) ```
instruction
0
80,001
0
160,002
No
output
1
80,001
0
160,003
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings a and b. It is known that |b| ≀ |a|, that is, the length of b is at most the length of a. The Cossack considers every substring of length |b| in string a. Let's call this substring c. He matches the corresponding characters in b and c, after which he counts the number of positions where the two strings are different. We call this function f(b, c). For example, let b = 00110, and c = 11000. In these strings, the first, second, third and fourth positions are different. Vus the Cossack counts the number of such substrings c such that f(b, c) is even. For example, let a = 01100010 and b = 00110. a has four substrings of the length |b|: 01100, 11000, 10001, 00010. * f(00110, 01100) = 2; * f(00110, 11000) = 4; * f(00110, 10001) = 4; * f(00110, 00010) = 1. Since in three substrings, f(b, c) is even, the answer is 3. Vus can not find the answer for big strings. That is why he is asking you to help him. Input The first line contains a binary string a (1 ≀ |a| ≀ 10^6) β€” the first string. The second line contains a binary string b (1 ≀ |b| ≀ |a|) β€” the second string. Output Print one number β€” the answer. Examples Input 01100010 00110 Output 3 Input 1010111110 0110 Output 4 Note The first example is explained in the legend. In the second example, there are five substrings that satisfy us: 1010, 0101, 1111, 1111. Submitted Solution: ``` # -*- coding:utf-8 -*- """ created by shuangquan.huang at 1/9/20 """ import collections import time import os import sys import bisect import heapq from typing import List def solve(A, B): ones = sum([int(x) for x in list(B)]) A = [int(x) for x in list(A)] oa = sum([int(x) for x in A[:len(B)]]) ans = 1 if ones % 2 == oa % 2 else 0 for i in range(len(B), len(A)): oa = A[i] oa -= A[i-len(B)] ans += 1 if ones % 2 == oa % 2 else 0 return ans A = input() B = input() print(solve(A, B)) ```
instruction
0
80,002
0
160,004
No
output
1
80,002
0
160,005
Provide tags and a correct Python 3 solution for this coding contest problem. The problem was inspired by Pied Piper story. After a challenge from Hooli's compression competitor Nucleus, Richard pulled an all-nighter to invent a new approach to compression: middle-out. You are given two strings s and t of the same length n. Their characters are numbered from 1 to n from left to right (i.e. from the beginning to the end). In a single move you can do the following sequence of actions: * choose any valid index i (1 ≀ i ≀ n), * move the i-th character of s from its position to the beginning of the string or move the i-th character of s from its position to the end of the string. Note, that the moves don't change the length of the string s. You can apply a move only to the string s. For example, if s="test" in one move you can obtain: * if i=1 and you move to the beginning, then the result is "test" (the string doesn't change), * if i=2 and you move to the beginning, then the result is "etst", * if i=3 and you move to the beginning, then the result is "stet", * if i=4 and you move to the beginning, then the result is "ttes", * if i=1 and you move to the end, then the result is "estt", * if i=2 and you move to the end, then the result is "tste", * if i=3 and you move to the end, then the result is "tets", * if i=4 and you move to the end, then the result is "test" (the string doesn't change). You want to make the string s equal to the string t. What is the minimum number of moves you need? If it is impossible to transform s to t, print -1. Input The first line contains integer q (1 ≀ q ≀ 100) β€” the number of independent test cases in the input. Each test case is given in three lines. The first line of a test case contains n (1 ≀ n ≀ 100) β€” the length of the strings s and t. The second line contains s, the third line contains t. Both strings s and t have length n and contain only lowercase Latin letters. There are no constraints on the sum of n in the test (i.e. the input with q=100 and all n=100 is allowed). Output For every test print minimum possible number of moves, which are needed to transform s into t, or -1, if it is impossible to do. Examples Input 3 9 iredppipe piedpiper 4 estt test 4 tste test Output 2 1 2 Input 4 1 a z 5 adhas dasha 5 aashd dasha 5 aahsd dasha Output -1 2 2 3 Note In the first example, the moves in one of the optimal answers are: * for the first test case s="iredppipe", t="piedpiper": "iredppipe" β†’ "iedppiper" β†’ "piedpiper"; * for the second test case s="estt", t="test": "estt" β†’ "test"; * for the third test case s="tste", t="test": "tste" β†’ "etst" β†’ "test".
instruction
0
80,918
0
161,836
Tags: constructive algorithms, greedy, strings Correct Solution: ``` from collections import * def go(): n,s,t=int(input()),input(),input() if Counter(s)!=Counter(t): return -1 ans=0 for i in range(n): k=0 for j in range(i,n): while k<n and s[k] != t[j]: k += 1 if k == n: break k += 1 ans = max(ans, j-i+1) return n-ans for _ in range(int(input())): print(go()) ```
output
1
80,918
0
161,837
Provide tags and a correct Python 3 solution for this coding contest problem. The problem was inspired by Pied Piper story. After a challenge from Hooli's compression competitor Nucleus, Richard pulled an all-nighter to invent a new approach to compression: middle-out. You are given two strings s and t of the same length n. Their characters are numbered from 1 to n from left to right (i.e. from the beginning to the end). In a single move you can do the following sequence of actions: * choose any valid index i (1 ≀ i ≀ n), * move the i-th character of s from its position to the beginning of the string or move the i-th character of s from its position to the end of the string. Note, that the moves don't change the length of the string s. You can apply a move only to the string s. For example, if s="test" in one move you can obtain: * if i=1 and you move to the beginning, then the result is "test" (the string doesn't change), * if i=2 and you move to the beginning, then the result is "etst", * if i=3 and you move to the beginning, then the result is "stet", * if i=4 and you move to the beginning, then the result is "ttes", * if i=1 and you move to the end, then the result is "estt", * if i=2 and you move to the end, then the result is "tste", * if i=3 and you move to the end, then the result is "tets", * if i=4 and you move to the end, then the result is "test" (the string doesn't change). You want to make the string s equal to the string t. What is the minimum number of moves you need? If it is impossible to transform s to t, print -1. Input The first line contains integer q (1 ≀ q ≀ 100) β€” the number of independent test cases in the input. Each test case is given in three lines. The first line of a test case contains n (1 ≀ n ≀ 100) β€” the length of the strings s and t. The second line contains s, the third line contains t. Both strings s and t have length n and contain only lowercase Latin letters. There are no constraints on the sum of n in the test (i.e. the input with q=100 and all n=100 is allowed). Output For every test print minimum possible number of moves, which are needed to transform s into t, or -1, if it is impossible to do. Examples Input 3 9 iredppipe piedpiper 4 estt test 4 tste test Output 2 1 2 Input 4 1 a z 5 adhas dasha 5 aashd dasha 5 aahsd dasha Output -1 2 2 3 Note In the first example, the moves in one of the optimal answers are: * for the first test case s="iredppipe", t="piedpiper": "iredppipe" β†’ "iedppiper" β†’ "piedpiper"; * for the second test case s="estt", t="test": "estt" β†’ "test"; * for the third test case s="tste", t="test": "tste" β†’ "etst" β†’ "test".
instruction
0
80,919
0
161,838
Tags: constructive algorithms, greedy, strings Correct Solution: ``` q = int(input()) for x in range(q): n = int(input()) s = str(input()) t = str(input()) ss = sorted(s) tt = sorted(t) if ss != tt: ans = -1 else: ans = 1000000000 for i in range(n): k = i for j in range(n): if k < n and s[j] == t[k]: k+=1 ans = min(ans, n - k + i) print(ans) ```
output
1
80,919
0
161,839
Provide tags and a correct Python 3 solution for this coding contest problem. The problem was inspired by Pied Piper story. After a challenge from Hooli's compression competitor Nucleus, Richard pulled an all-nighter to invent a new approach to compression: middle-out. You are given two strings s and t of the same length n. Their characters are numbered from 1 to n from left to right (i.e. from the beginning to the end). In a single move you can do the following sequence of actions: * choose any valid index i (1 ≀ i ≀ n), * move the i-th character of s from its position to the beginning of the string or move the i-th character of s from its position to the end of the string. Note, that the moves don't change the length of the string s. You can apply a move only to the string s. For example, if s="test" in one move you can obtain: * if i=1 and you move to the beginning, then the result is "test" (the string doesn't change), * if i=2 and you move to the beginning, then the result is "etst", * if i=3 and you move to the beginning, then the result is "stet", * if i=4 and you move to the beginning, then the result is "ttes", * if i=1 and you move to the end, then the result is "estt", * if i=2 and you move to the end, then the result is "tste", * if i=3 and you move to the end, then the result is "tets", * if i=4 and you move to the end, then the result is "test" (the string doesn't change). You want to make the string s equal to the string t. What is the minimum number of moves you need? If it is impossible to transform s to t, print -1. Input The first line contains integer q (1 ≀ q ≀ 100) β€” the number of independent test cases in the input. Each test case is given in three lines. The first line of a test case contains n (1 ≀ n ≀ 100) β€” the length of the strings s and t. The second line contains s, the third line contains t. Both strings s and t have length n and contain only lowercase Latin letters. There are no constraints on the sum of n in the test (i.e. the input with q=100 and all n=100 is allowed). Output For every test print minimum possible number of moves, which are needed to transform s into t, or -1, if it is impossible to do. Examples Input 3 9 iredppipe piedpiper 4 estt test 4 tste test Output 2 1 2 Input 4 1 a z 5 adhas dasha 5 aashd dasha 5 aahsd dasha Output -1 2 2 3 Note In the first example, the moves in one of the optimal answers are: * for the first test case s="iredppipe", t="piedpiper": "iredppipe" β†’ "iedppiper" β†’ "piedpiper"; * for the second test case s="estt", t="test": "estt" β†’ "test"; * for the third test case s="tste", t="test": "tste" β†’ "etst" β†’ "test".
instruction
0
80,920
0
161,840
Tags: constructive algorithms, greedy, strings Correct Solution: ``` from collections import Counter def cal(n,s,t): if(Counter(s)!=Counter(t)): return -1 ans=0 for i in range(n): k=0 for j in range(i,n): while k<n and s[k] != t[j]: k+=1 if k==n: break k+=1 ans=max(ans,j-i+1) return n-ans for _ in range(int(input())): n=int(input()) s,t=input(),input() print(cal(n,s,t)) ```
output
1
80,920
0
161,841
Provide tags and a correct Python 3 solution for this coding contest problem. The problem was inspired by Pied Piper story. After a challenge from Hooli's compression competitor Nucleus, Richard pulled an all-nighter to invent a new approach to compression: middle-out. You are given two strings s and t of the same length n. Their characters are numbered from 1 to n from left to right (i.e. from the beginning to the end). In a single move you can do the following sequence of actions: * choose any valid index i (1 ≀ i ≀ n), * move the i-th character of s from its position to the beginning of the string or move the i-th character of s from its position to the end of the string. Note, that the moves don't change the length of the string s. You can apply a move only to the string s. For example, if s="test" in one move you can obtain: * if i=1 and you move to the beginning, then the result is "test" (the string doesn't change), * if i=2 and you move to the beginning, then the result is "etst", * if i=3 and you move to the beginning, then the result is "stet", * if i=4 and you move to the beginning, then the result is "ttes", * if i=1 and you move to the end, then the result is "estt", * if i=2 and you move to the end, then the result is "tste", * if i=3 and you move to the end, then the result is "tets", * if i=4 and you move to the end, then the result is "test" (the string doesn't change). You want to make the string s equal to the string t. What is the minimum number of moves you need? If it is impossible to transform s to t, print -1. Input The first line contains integer q (1 ≀ q ≀ 100) β€” the number of independent test cases in the input. Each test case is given in three lines. The first line of a test case contains n (1 ≀ n ≀ 100) β€” the length of the strings s and t. The second line contains s, the third line contains t. Both strings s and t have length n and contain only lowercase Latin letters. There are no constraints on the sum of n in the test (i.e. the input with q=100 and all n=100 is allowed). Output For every test print minimum possible number of moves, which are needed to transform s into t, or -1, if it is impossible to do. Examples Input 3 9 iredppipe piedpiper 4 estt test 4 tste test Output 2 1 2 Input 4 1 a z 5 adhas dasha 5 aashd dasha 5 aahsd dasha Output -1 2 2 3 Note In the first example, the moves in one of the optimal answers are: * for the first test case s="iredppipe", t="piedpiper": "iredppipe" β†’ "iedppiper" β†’ "piedpiper"; * for the second test case s="estt", t="test": "estt" β†’ "test"; * for the third test case s="tste", t="test": "tste" β†’ "etst" β†’ "test".
instruction
0
80,921
0
161,842
Tags: constructive algorithms, greedy, strings Correct Solution: ``` # your code goes here t =int(input()) for h in range(t): ans = 1000000000 n = int(input()) a = str(input()) b = str(input()) if sorted(a) != sorted(b): ans = -1 else: ans = 10000000000000 for i in range(n): k = i count = 0 for j in range(n): if k < n and a[j] == b[k]: k+=1 count+=1 ans = min(ans, n - count) print(ans) ```
output
1
80,921
0
161,843
Provide tags and a correct Python 3 solution for this coding contest problem. The problem was inspired by Pied Piper story. After a challenge from Hooli's compression competitor Nucleus, Richard pulled an all-nighter to invent a new approach to compression: middle-out. You are given two strings s and t of the same length n. Their characters are numbered from 1 to n from left to right (i.e. from the beginning to the end). In a single move you can do the following sequence of actions: * choose any valid index i (1 ≀ i ≀ n), * move the i-th character of s from its position to the beginning of the string or move the i-th character of s from its position to the end of the string. Note, that the moves don't change the length of the string s. You can apply a move only to the string s. For example, if s="test" in one move you can obtain: * if i=1 and you move to the beginning, then the result is "test" (the string doesn't change), * if i=2 and you move to the beginning, then the result is "etst", * if i=3 and you move to the beginning, then the result is "stet", * if i=4 and you move to the beginning, then the result is "ttes", * if i=1 and you move to the end, then the result is "estt", * if i=2 and you move to the end, then the result is "tste", * if i=3 and you move to the end, then the result is "tets", * if i=4 and you move to the end, then the result is "test" (the string doesn't change). You want to make the string s equal to the string t. What is the minimum number of moves you need? If it is impossible to transform s to t, print -1. Input The first line contains integer q (1 ≀ q ≀ 100) β€” the number of independent test cases in the input. Each test case is given in three lines. The first line of a test case contains n (1 ≀ n ≀ 100) β€” the length of the strings s and t. The second line contains s, the third line contains t. Both strings s and t have length n and contain only lowercase Latin letters. There are no constraints on the sum of n in the test (i.e. the input with q=100 and all n=100 is allowed). Output For every test print minimum possible number of moves, which are needed to transform s into t, or -1, if it is impossible to do. Examples Input 3 9 iredppipe piedpiper 4 estt test 4 tste test Output 2 1 2 Input 4 1 a z 5 adhas dasha 5 aashd dasha 5 aahsd dasha Output -1 2 2 3 Note In the first example, the moves in one of the optimal answers are: * for the first test case s="iredppipe", t="piedpiper": "iredppipe" β†’ "iedppiper" β†’ "piedpiper"; * for the second test case s="estt", t="test": "estt" β†’ "test"; * for the third test case s="tste", t="test": "tste" β†’ "etst" β†’ "test".
instruction
0
80,922
0
161,844
Tags: constructive algorithms, greedy, strings Correct Solution: ``` from sys import stdin, stdout def getminmove(s,t): len1 = len(s) len2 = len(t) if len1 != len2: return -1 sa = [0]*26 ta = [0]*26 for c in s: #print(str(ord(c)-ord('a'))) sa[ord(c)-ord('a')] += 1 for c in t: ta[ord(c) - ord('a')] += 1 #print(sa) #print(ta) for i in range(26): if sa[i] != ta[i]: return -1 res = 1000000000000000000000 for i in range(len(s)): k = i sum = 0 for j in range(len(t)): if k < len(s) and t[k] == s[j]: sum += 1 k += 1 res = min(len(s)-sum, res) return res if __name__ == '__main__': q = int(stdin.readline()) for i in range(q): n = int(stdin.readline()) s = stdin.readline().strip() t = stdin.readline().strip() move = getminmove(s, t) stdout.write(str(move) + '\n') ```
output
1
80,922
0
161,845
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The problem was inspired by Pied Piper story. After a challenge from Hooli's compression competitor Nucleus, Richard pulled an all-nighter to invent a new approach to compression: middle-out. You are given two strings s and t of the same length n. Their characters are numbered from 1 to n from left to right (i.e. from the beginning to the end). In a single move you can do the following sequence of actions: * choose any valid index i (1 ≀ i ≀ n), * move the i-th character of s from its position to the beginning of the string or move the i-th character of s from its position to the end of the string. Note, that the moves don't change the length of the string s. You can apply a move only to the string s. For example, if s="test" in one move you can obtain: * if i=1 and you move to the beginning, then the result is "test" (the string doesn't change), * if i=2 and you move to the beginning, then the result is "etst", * if i=3 and you move to the beginning, then the result is "stet", * if i=4 and you move to the beginning, then the result is "ttes", * if i=1 and you move to the end, then the result is "estt", * if i=2 and you move to the end, then the result is "tste", * if i=3 and you move to the end, then the result is "tets", * if i=4 and you move to the end, then the result is "test" (the string doesn't change). You want to make the string s equal to the string t. What is the minimum number of moves you need? If it is impossible to transform s to t, print -1. Input The first line contains integer q (1 ≀ q ≀ 100) β€” the number of independent test cases in the input. Each test case is given in three lines. The first line of a test case contains n (1 ≀ n ≀ 100) β€” the length of the strings s and t. The second line contains s, the third line contains t. Both strings s and t have length n and contain only lowercase Latin letters. There are no constraints on the sum of n in the test (i.e. the input with q=100 and all n=100 is allowed). Output For every test print minimum possible number of moves, which are needed to transform s into t, or -1, if it is impossible to do. Examples Input 3 9 iredppipe piedpiper 4 estt test 4 tste test Output 2 1 2 Input 4 1 a z 5 adhas dasha 5 aashd dasha 5 aahsd dasha Output -1 2 2 3 Note In the first example, the moves in one of the optimal answers are: * for the first test case s="iredppipe", t="piedpiper": "iredppipe" β†’ "iedppiper" β†’ "piedpiper"; * for the second test case s="estt", t="test": "estt" β†’ "test"; * for the third test case s="tste", t="test": "tste" β†’ "etst" β†’ "test". Submitted Solution: ``` q = int(input()) for a in range(q): n = int(input()) s = str(input()) t = str(input()) d = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26} dp = [[0] * n for i in range(n)] used = [[0] * n for i in range(n)] sym_cnt = [0] * n cnt_s = [0] * 26 cnt_t = [0] * 26 stop = False cnt = 0 min_cnt = n for i in range(n): cnt_s[d[s[i]] - 1] += 1 cnt_t[d[t[i]] - 1] += 1 for i in range(26): if cnt_s[i] != cnt_t[i]: print(-1) stop = True break if stop: continue for i in range(n): for j in range(n): pass for i in range(n): sym_cnt[i] += cnt_t[d[t[i]]] for sym in range(n): for sub_sym in range(n): if t[sym] == s[sub_sym]: used[sym][sub_sym] = 1 if sym > 0 and sub_sym > 0: if sub_sym > 0: if used[sym][sub_sym - 1] == 1: dp[sym][sub_sym] = min(max(dp[sym][sub_sym - 1] + 1, dp[sym - 1][sub_sym] + 1), sub_sym + 1) elif sym > 0 and sub_sym == 0: dp[sym][sub_sym] = min(dp[sym - 1][sub_sym] + 1, sub_sym + 1) elif sym == 0 and sub_sym > 0: dp[sym][sub_sym] = min(dp[sym][sub_sym - 1] + 1, sub_sym + 1) else: dp[sym][sub_sym] = 1 else: if sym > 0 and sub_sym > 0: dp[sym][sub_sym] = max(dp[sym][sub_sym - 1], dp[sym - 1][sub_sym]) elif sym > 0 and sub_sym == 0: dp[sym][sub_sym] = dp[sym - 1][sub_sym] elif sym == 0 and sub_sym > 0: dp[sym][sub_sym] = dp[sym][sub_sym - 1] else: dp[sym][sub_sym] = 0 if dp[sym][sub_sym] > cnt: cnt = dp[sym][sub_sym] if sym > 0: used[sym][sub_sym] = max(0, used[sym - 1][sub_sym]) for i in range(n): min_cnt = min(min_cnt, n - max(dp[i])) print(min_cnt) ```
instruction
0
80,923
0
161,846
No
output
1
80,923
0
161,847
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The problem was inspired by Pied Piper story. After a challenge from Hooli's compression competitor Nucleus, Richard pulled an all-nighter to invent a new approach to compression: middle-out. You are given two strings s and t of the same length n. Their characters are numbered from 1 to n from left to right (i.e. from the beginning to the end). In a single move you can do the following sequence of actions: * choose any valid index i (1 ≀ i ≀ n), * move the i-th character of s from its position to the beginning of the string or move the i-th character of s from its position to the end of the string. Note, that the moves don't change the length of the string s. You can apply a move only to the string s. For example, if s="test" in one move you can obtain: * if i=1 and you move to the beginning, then the result is "test" (the string doesn't change), * if i=2 and you move to the beginning, then the result is "etst", * if i=3 and you move to the beginning, then the result is "stet", * if i=4 and you move to the beginning, then the result is "ttes", * if i=1 and you move to the end, then the result is "estt", * if i=2 and you move to the end, then the result is "tste", * if i=3 and you move to the end, then the result is "tets", * if i=4 and you move to the end, then the result is "test" (the string doesn't change). You want to make the string s equal to the string t. What is the minimum number of moves you need? If it is impossible to transform s to t, print -1. Input The first line contains integer q (1 ≀ q ≀ 100) β€” the number of independent test cases in the input. Each test case is given in three lines. The first line of a test case contains n (1 ≀ n ≀ 100) β€” the length of the strings s and t. The second line contains s, the third line contains t. Both strings s and t have length n and contain only lowercase Latin letters. There are no constraints on the sum of n in the test (i.e. the input with q=100 and all n=100 is allowed). Output For every test print minimum possible number of moves, which are needed to transform s into t, or -1, if it is impossible to do. Examples Input 3 9 iredppipe piedpiper 4 estt test 4 tste test Output 2 1 2 Input 4 1 a z 5 adhas dasha 5 aashd dasha 5 aahsd dasha Output -1 2 2 3 Note In the first example, the moves in one of the optimal answers are: * for the first test case s="iredppipe", t="piedpiper": "iredppipe" β†’ "iedppiper" β†’ "piedpiper"; * for the second test case s="estt", t="test": "estt" β†’ "test"; * for the third test case s="tste", t="test": "tste" β†’ "etst" β†’ "test". Submitted Solution: ``` T=int(input()) while T>0: T-=1 n=int(input()) s=input() t=input() list1=[] list2=[] for i in range(n): list1.append(s[i]) list2.append(t[i]) move=0 for i in range(n-1,-1,-1): if list1[i]!=list2[i]: index=list1.index(list2[i]) element=list1.pop(index) list1.insert(0,element) move+=1 print(move) ```
instruction
0
80,924
0
161,848
No
output
1
80,924
0
161,849
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The problem was inspired by Pied Piper story. After a challenge from Hooli's compression competitor Nucleus, Richard pulled an all-nighter to invent a new approach to compression: middle-out. You are given two strings s and t of the same length n. Their characters are numbered from 1 to n from left to right (i.e. from the beginning to the end). In a single move you can do the following sequence of actions: * choose any valid index i (1 ≀ i ≀ n), * move the i-th character of s from its position to the beginning of the string or move the i-th character of s from its position to the end of the string. Note, that the moves don't change the length of the string s. You can apply a move only to the string s. For example, if s="test" in one move you can obtain: * if i=1 and you move to the beginning, then the result is "test" (the string doesn't change), * if i=2 and you move to the beginning, then the result is "etst", * if i=3 and you move to the beginning, then the result is "stet", * if i=4 and you move to the beginning, then the result is "ttes", * if i=1 and you move to the end, then the result is "estt", * if i=2 and you move to the end, then the result is "tste", * if i=3 and you move to the end, then the result is "tets", * if i=4 and you move to the end, then the result is "test" (the string doesn't change). You want to make the string s equal to the string t. What is the minimum number of moves you need? If it is impossible to transform s to t, print -1. Input The first line contains integer q (1 ≀ q ≀ 100) β€” the number of independent test cases in the input. Each test case is given in three lines. The first line of a test case contains n (1 ≀ n ≀ 100) β€” the length of the strings s and t. The second line contains s, the third line contains t. Both strings s and t have length n and contain only lowercase Latin letters. There are no constraints on the sum of n in the test (i.e. the input with q=100 and all n=100 is allowed). Output For every test print minimum possible number of moves, which are needed to transform s into t, or -1, if it is impossible to do. Examples Input 3 9 iredppipe piedpiper 4 estt test 4 tste test Output 2 1 2 Input 4 1 a z 5 adhas dasha 5 aashd dasha 5 aahsd dasha Output -1 2 2 3 Note In the first example, the moves in one of the optimal answers are: * for the first test case s="iredppipe", t="piedpiper": "iredppipe" β†’ "iedppiper" β†’ "piedpiper"; * for the second test case s="estt", t="test": "estt" β†’ "test"; * for the third test case s="tste", t="test": "tste" β†’ "etst" β†’ "test". Submitted Solution: ``` # your code goes here t =int(input()) for h in range(t): ans = 1000000000 n = int (input()) a = list(input()) b = list(input()) #print(a, ' ', b) for j in range(n): k = j count = 0 for i in range(n): #print(a[i],' ', b[k]) if a[i] == b[k]: k+=1 count += 1 if k == n: break if count != 0: ans = min(ans, n-count) #print(n, ' ', count) if ans == 1000000000: print(-1) else: print(ans) ```
instruction
0
80,925
0
161,850
No
output
1
80,925
0
161,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The problem was inspired by Pied Piper story. After a challenge from Hooli's compression competitor Nucleus, Richard pulled an all-nighter to invent a new approach to compression: middle-out. You are given two strings s and t of the same length n. Their characters are numbered from 1 to n from left to right (i.e. from the beginning to the end). In a single move you can do the following sequence of actions: * choose any valid index i (1 ≀ i ≀ n), * move the i-th character of s from its position to the beginning of the string or move the i-th character of s from its position to the end of the string. Note, that the moves don't change the length of the string s. You can apply a move only to the string s. For example, if s="test" in one move you can obtain: * if i=1 and you move to the beginning, then the result is "test" (the string doesn't change), * if i=2 and you move to the beginning, then the result is "etst", * if i=3 and you move to the beginning, then the result is "stet", * if i=4 and you move to the beginning, then the result is "ttes", * if i=1 and you move to the end, then the result is "estt", * if i=2 and you move to the end, then the result is "tste", * if i=3 and you move to the end, then the result is "tets", * if i=4 and you move to the end, then the result is "test" (the string doesn't change). You want to make the string s equal to the string t. What is the minimum number of moves you need? If it is impossible to transform s to t, print -1. Input The first line contains integer q (1 ≀ q ≀ 100) β€” the number of independent test cases in the input. Each test case is given in three lines. The first line of a test case contains n (1 ≀ n ≀ 100) β€” the length of the strings s and t. The second line contains s, the third line contains t. Both strings s and t have length n and contain only lowercase Latin letters. There are no constraints on the sum of n in the test (i.e. the input with q=100 and all n=100 is allowed). Output For every test print minimum possible number of moves, which are needed to transform s into t, or -1, if it is impossible to do. Examples Input 3 9 iredppipe piedpiper 4 estt test 4 tste test Output 2 1 2 Input 4 1 a z 5 adhas dasha 5 aashd dasha 5 aahsd dasha Output -1 2 2 3 Note In the first example, the moves in one of the optimal answers are: * for the first test case s="iredppipe", t="piedpiper": "iredppipe" β†’ "iedppiper" β†’ "piedpiper"; * for the second test case s="estt", t="test": "estt" β†’ "test"; * for the third test case s="tste", t="test": "tste" β†’ "etst" β†’ "test". Submitted Solution: ``` from collections import * def go(): n,s,t=int(input()),input(),input() if Counter(s)!=Counter(t): return -1 ans=0 for i in range(n): k=0 for j in range(i,n): while k<n and s[k] != t[j]: k += 1 if k == n: break k += 1 ans = max(ans, j-i+1) return n-ans for _ in range(int(input())): print(go()) ```
instruction
0
80,926
0
161,852
No
output
1
80,926
0
161,853
Provide a correct Python 3 solution for this coding contest problem. You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it. Constraints * 1 ≀ N ≀ 50 * 1 ≀ K ≀ N * S is a string of length N consisting of `A`, `B` and `C`. Input Input is given from Standard Input in the following format: N K S Output Print the string S after lowercasing the K-th character in it. Examples Input 3 1 ABC Output aBC Input 4 3 CABA Output CAbA
instruction
0
81,490
0
162,980
"Correct Solution: ``` n,k=map(int,input().split()) s=input();s=list(s) s[k-1]=s[k-1].lower() print("".join(s)) ```
output
1
81,490
0
162,981
Provide a correct Python 3 solution for this coding contest problem. You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it. Constraints * 1 ≀ N ≀ 50 * 1 ≀ K ≀ N * S is a string of length N consisting of `A`, `B` and `C`. Input Input is given from Standard Input in the following format: N K S Output Print the string S after lowercasing the K-th character in it. Examples Input 3 1 ABC Output aBC Input 4 3 CABA Output CAbA
instruction
0
81,491
0
162,982
"Correct Solution: ``` a,b=map(int,input().split()) l=list(input()) l[b-1]=l[b-1].lower() print(''.join(l)) ```
output
1
81,491
0
162,983
Provide a correct Python 3 solution for this coding contest problem. You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it. Constraints * 1 ≀ N ≀ 50 * 1 ≀ K ≀ N * S is a string of length N consisting of `A`, `B` and `C`. Input Input is given from Standard Input in the following format: N K S Output Print the string S after lowercasing the K-th character in it. Examples Input 3 1 ABC Output aBC Input 4 3 CABA Output CAbA
instruction
0
81,492
0
162,984
"Correct Solution: ``` _,k=input().split();s=input();k=int(k)-1 print(s[:k]+s[k].lower()+s[k+1:]) ```
output
1
81,492
0
162,985
Provide a correct Python 3 solution for this coding contest problem. You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it. Constraints * 1 ≀ N ≀ 50 * 1 ≀ K ≀ N * S is a string of length N consisting of `A`, `B` and `C`. Input Input is given from Standard Input in the following format: N K S Output Print the string S after lowercasing the K-th character in it. Examples Input 3 1 ABC Output aBC Input 4 3 CABA Output CAbA
instruction
0
81,493
0
162,986
"Correct Solution: ``` N,K=map(int,input().split()) s=list(input()) s[K-1]=chr(ord(s[K-1])+32) print("".join(s)) ```
output
1
81,493
0
162,987
Provide a correct Python 3 solution for this coding contest problem. You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it. Constraints * 1 ≀ N ≀ 50 * 1 ≀ K ≀ N * S is a string of length N consisting of `A`, `B` and `C`. Input Input is given from Standard Input in the following format: N K S Output Print the string S after lowercasing the K-th character in it. Examples Input 3 1 ABC Output aBC Input 4 3 CABA Output CAbA
instruction
0
81,494
0
162,988
"Correct Solution: ``` n, k = map(int, input().split()) s = input() t = s.lower() print(s[:k-1]+t[k-1]+s[k:]) ```
output
1
81,494
0
162,989
Provide a correct Python 3 solution for this coding contest problem. You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it. Constraints * 1 ≀ N ≀ 50 * 1 ≀ K ≀ N * S is a string of length N consisting of `A`, `B` and `C`. Input Input is given from Standard Input in the following format: N K S Output Print the string S after lowercasing the K-th character in it. Examples Input 3 1 ABC Output aBC Input 4 3 CABA Output CAbA
instruction
0
81,495
0
162,990
"Correct Solution: ``` N,K = map(int,input().split()) S = input() S = S[:K-1] + S[K-1].lower() + S[K:] print(S) ```
output
1
81,495
0
162,991
Provide a correct Python 3 solution for this coding contest problem. You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it. Constraints * 1 ≀ N ≀ 50 * 1 ≀ K ≀ N * S is a string of length N consisting of `A`, `B` and `C`. Input Input is given from Standard Input in the following format: N K S Output Print the string S after lowercasing the K-th character in it. Examples Input 3 1 ABC Output aBC Input 4 3 CABA Output CAbA
instruction
0
81,496
0
162,992
"Correct Solution: ``` N,K=map(int,input().split()) S=list(input()) S[K-1]=S[K-1].lower() S="".join(S) print(S) ```
output
1
81,496
0
162,993
Provide a correct Python 3 solution for this coding contest problem. You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it. Constraints * 1 ≀ N ≀ 50 * 1 ≀ K ≀ N * S is a string of length N consisting of `A`, `B` and `C`. Input Input is given from Standard Input in the following format: N K S Output Print the string S after lowercasing the K-th character in it. Examples Input 3 1 ABC Output aBC Input 4 3 CABA Output CAbA
instruction
0
81,497
0
162,994
"Correct Solution: ``` N, K=map(int,input().split()) S=str(input()) print(S[:K-1]+str.lower(S[K-1])+S[K:]) ```
output
1
81,497
0
162,995
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 `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it. Constraints * 1 ≀ N ≀ 50 * 1 ≀ K ≀ N * S is a string of length N consisting of `A`, `B` and `C`. Input Input is given from Standard Input in the following format: N K S Output Print the string S after lowercasing the K-th character in it. Examples Input 3 1 ABC Output aBC Input 4 3 CABA Output CAbA Submitted Solution: ``` n, k = map(int, input().split()) string = input() print(string.replace(string[k-1], string[k-1].lower())) ```
instruction
0
81,502
0
163,004
No
output
1
81,502
0
163,005
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q. For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo". Note it is allowed to split the string s to the strings only of length p or to the strings only of length q (see the second sample test). Input The first line contains three positive integers n, p, q (1 ≀ p, q ≀ n ≀ 100). The second line contains the string s consists of lowercase and uppercase latin letters and digits. Output If it's impossible to split the string s to the strings of length p and q print the only number "-1". Otherwise in the first line print integer k β€” the number of strings in partition of s. Each of the next k lines should contain the strings in partition. Each string should be of the length p or q. The string should be in order of their appearing in string s β€” from left to right. If there are several solutions print any of them. Examples Input 5 2 3 Hello Output 2 He llo Input 10 9 5 Codeforces Output 2 Codef orces Input 6 4 5 Privet Output -1 Input 8 1 1 abacabac Output 8 a b a c a b a c
instruction
0
82,163
0
164,326
Tags: brute force, implementation, strings Correct Solution: ``` n, p, q = [int(e) for e in input().split(' ')] s = input() solA = -1 solB = -1 for i in range(0, (n // p) + 1): if (n - p*i) % q == 0: solA = i solB = (n - p*i) // q break if solA == -1: print(-1) else: print(solA + solB) for i in range(0, solA): print(s[i*p:(i + 1)*p]) for i in range(0, solB): print(s[(solA*p + i*q):(solA*p + (i + 1)*q)]) ```
output
1
82,163
0
164,327
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q. For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo". Note it is allowed to split the string s to the strings only of length p or to the strings only of length q (see the second sample test). Input The first line contains three positive integers n, p, q (1 ≀ p, q ≀ n ≀ 100). The second line contains the string s consists of lowercase and uppercase latin letters and digits. Output If it's impossible to split the string s to the strings of length p and q print the only number "-1". Otherwise in the first line print integer k β€” the number of strings in partition of s. Each of the next k lines should contain the strings in partition. Each string should be of the length p or q. The string should be in order of their appearing in string s β€” from left to right. If there are several solutions print any of them. Examples Input 5 2 3 Hello Output 2 He llo Input 10 9 5 Codeforces Output 2 Codef orces Input 6 4 5 Privet Output -1 Input 8 1 1 abacabac Output 8 a b a c a b a c
instruction
0
82,164
0
164,328
Tags: brute force, implementation, strings Correct Solution: ``` n,p,q = map(int,input().split()) s = input() def problem6(n,p,q,s): cont = 0 cont2 = 0 j = 0 while n>=0: if n%p==0: break cont+=1 n -= q if n<0: print("-1") return cont2 = int(n/p) num = cont+cont2 print(num) for i in range(cont2): print(s[j:j+p]) j+=p for i in range(cont): print(s[j:j+q]) j+=q problem6(n,p,q,s) ```
output
1
82,164
0
164,329
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q. For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo". Note it is allowed to split the string s to the strings only of length p or to the strings only of length q (see the second sample test). Input The first line contains three positive integers n, p, q (1 ≀ p, q ≀ n ≀ 100). The second line contains the string s consists of lowercase and uppercase latin letters and digits. Output If it's impossible to split the string s to the strings of length p and q print the only number "-1". Otherwise in the first line print integer k β€” the number of strings in partition of s. Each of the next k lines should contain the strings in partition. Each string should be of the length p or q. The string should be in order of their appearing in string s β€” from left to right. If there are several solutions print any of them. Examples Input 5 2 3 Hello Output 2 He llo Input 10 9 5 Codeforces Output 2 Codef orces Input 6 4 5 Privet Output -1 Input 8 1 1 abacabac Output 8 a b a c a b a c
instruction
0
82,165
0
164,330
Tags: brute force, implementation, strings Correct Solution: ``` n, p, q = list(map(int, input().split())) s = input() dp = [0] * (n + max(p, q) + 1) dp[0] = 1 for i in range(n + 1): if dp[i] == 0: continue dp[i + p] = 1 dp[i + q] = 1 if not dp[n]: print('-1') exit() ans = [] while n: if n >= p and dp[n - p] == 1: ans.append(p) n -= p if n >= q and dp[n - q] == 1: ans.append(q) n -= q print(len(ans)) ind = 0 for size in ans: print(s[ind:ind+size]) ind += size ```
output
1
82,165
0
164,331
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q. For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo". Note it is allowed to split the string s to the strings only of length p or to the strings only of length q (see the second sample test). Input The first line contains three positive integers n, p, q (1 ≀ p, q ≀ n ≀ 100). The second line contains the string s consists of lowercase and uppercase latin letters and digits. Output If it's impossible to split the string s to the strings of length p and q print the only number "-1". Otherwise in the first line print integer k β€” the number of strings in partition of s. Each of the next k lines should contain the strings in partition. Each string should be of the length p or q. The string should be in order of their appearing in string s β€” from left to right. If there are several solutions print any of them. Examples Input 5 2 3 Hello Output 2 He llo Input 10 9 5 Codeforces Output 2 Codef orces Input 6 4 5 Privet Output -1 Input 8 1 1 abacabac Output 8 a b a c a b a c
instruction
0
82,166
0
164,332
Tags: brute force, implementation, strings Correct Solution: ``` n, p, q = map(int, input().split()) s = input() for i in range(n + 1): for j in range(n + 1): if (i * p + j * q == n): print(i + j) for ii in range (i): print(s[ii * p : (ii + 1) * p]) for jj in range (j): print(s[i * p + jj * q : i * p + (jj + 1) * q]) exit() print("-1") ```
output
1
82,166
0
164,333
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q. For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo". Note it is allowed to split the string s to the strings only of length p or to the strings only of length q (see the second sample test). Input The first line contains three positive integers n, p, q (1 ≀ p, q ≀ n ≀ 100). The second line contains the string s consists of lowercase and uppercase latin letters and digits. Output If it's impossible to split the string s to the strings of length p and q print the only number "-1". Otherwise in the first line print integer k β€” the number of strings in partition of s. Each of the next k lines should contain the strings in partition. Each string should be of the length p or q. The string should be in order of their appearing in string s β€” from left to right. If there are several solutions print any of them. Examples Input 5 2 3 Hello Output 2 He llo Input 10 9 5 Codeforces Output 2 Codef orces Input 6 4 5 Privet Output -1 Input 8 1 1 abacabac Output 8 a b a c a b a c
instruction
0
82,167
0
164,334
Tags: brute force, implementation, strings Correct Solution: ``` import sys n,p,q = map(int,sys.stdin.readline().split()) word = list(input()) sol = -1 for i in range(0,int(n/p)+1): #print(i) #print(f'sol={sol}') for j in range(0,int(n/q)+1): #print(j) if((i*p+j*q)==n): #print('entre') sol = i+j print(sol) for k in range(0,n): sys.stdout.write(word[k]) if(i and k<i*p and not((k+1)%p) or j and k>=i*p and not((k-i*p+1)%q)): print("") sys.exit(0) if(sol!=-1): break if(sol==-1): print('-1') ```
output
1
82,167
0
164,335
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q. For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo". Note it is allowed to split the string s to the strings only of length p or to the strings only of length q (see the second sample test). Input The first line contains three positive integers n, p, q (1 ≀ p, q ≀ n ≀ 100). The second line contains the string s consists of lowercase and uppercase latin letters and digits. Output If it's impossible to split the string s to the strings of length p and q print the only number "-1". Otherwise in the first line print integer k β€” the number of strings in partition of s. Each of the next k lines should contain the strings in partition. Each string should be of the length p or q. The string should be in order of their appearing in string s β€” from left to right. If there are several solutions print any of them. Examples Input 5 2 3 Hello Output 2 He llo Input 10 9 5 Codeforces Output 2 Codef orces Input 6 4 5 Privet Output -1 Input 8 1 1 abacabac Output 8 a b a c a b a c
instruction
0
82,168
0
164,336
Tags: brute force, implementation, strings Correct Solution: ``` n, p, q = map(int, input().split()) X = [] while n > 0: if n % p: n -= q X.append(q) else: X += [p] * (n // p) break if n < 0: print(-1) else: print(len(X)) s, i = input(), 0 for x in X: print(s[i:i+x]) i += x ```
output
1
82,168
0
164,337
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q. For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo". Note it is allowed to split the string s to the strings only of length p or to the strings only of length q (see the second sample test). Input The first line contains three positive integers n, p, q (1 ≀ p, q ≀ n ≀ 100). The second line contains the string s consists of lowercase and uppercase latin letters and digits. Output If it's impossible to split the string s to the strings of length p and q print the only number "-1". Otherwise in the first line print integer k β€” the number of strings in partition of s. Each of the next k lines should contain the strings in partition. Each string should be of the length p or q. The string should be in order of their appearing in string s β€” from left to right. If there are several solutions print any of them. Examples Input 5 2 3 Hello Output 2 He llo Input 10 9 5 Codeforces Output 2 Codef orces Input 6 4 5 Privet Output -1 Input 8 1 1 abacabac Output 8 a b a c a b a c
instruction
0
82,169
0
164,338
Tags: brute force, implementation, strings Correct Solution: ``` from math import sqrt def main(): n,p,q = [int(v) for v in input().split()] d = input() data=[-1 for _ in range(n+102)] parent = [-1 for _ in range(n+102)] data[0]=1 for i in range(0, n+1): if data[i]!=-1: data[i+p]=1 parent[i+p]=i data[i+q]=1 parent[i+q]=i if data[n]!=1: print(-1) else: res = [] cur = n c = parent[n] while c!=0: res.append(d[c:cur]) t = c cur=c c = parent[t] res.append(d[c:cur]) print(len(res)) for d in reversed(res): print(d) if __name__ == "__main__": main() ```
output
1
82,169
0
164,339
Provide tags and a correct Python 3 solution for this coding contest problem. Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible. String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input First line of input contains string s, consisting only of lowercase Latin letters (1 ≀ |s| ≀ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≀ k ≀ 26). Output Print single line with a minimum number of necessary changes, or the word Β«impossibleΒ» (without quotes) if it is impossible. Examples Input yandex 6 Output 0 Input yahoo 5 Output 1 Input google 7 Output impossible Note In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
instruction
0
82,251
0
164,502
Tags: greedy, implementation, strings Correct Solution: ``` s, k = input(), int(input()) print((max(k - len(set(s)), 0), "impossible")[len(s) < k]) ```
output
1
82,251
0
164,503
Provide tags and a correct Python 3 solution for this coding contest problem. Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible. String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input First line of input contains string s, consisting only of lowercase Latin letters (1 ≀ |s| ≀ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≀ k ≀ 26). Output Print single line with a minimum number of necessary changes, or the word Β«impossibleΒ» (without quotes) if it is impossible. Examples Input yandex 6 Output 0 Input yahoo 5 Output 1 Input google 7 Output impossible Note In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
instruction
0
82,252
0
164,504
Tags: greedy, implementation, strings Correct Solution: ``` string = input() k = int(input()) mas = list(string) mas1 = [] for i in mas: if i not in mas1: mas1.append(i) if k > len(string): print('impossible') elif len(mas1) <= k: print(k - len(mas1)) else: print('0') ```
output
1
82,252
0
164,505
Provide tags and a correct Python 3 solution for this coding contest problem. Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible. String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input First line of input contains string s, consisting only of lowercase Latin letters (1 ≀ |s| ≀ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≀ k ≀ 26). Output Print single line with a minimum number of necessary changes, or the word Β«impossibleΒ» (without quotes) if it is impossible. Examples Input yandex 6 Output 0 Input yahoo 5 Output 1 Input google 7 Output impossible Note In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
instruction
0
82,253
0
164,506
Tags: greedy, implementation, strings Correct Solution: ``` s, k = input(), int(input()) unique = len(set(s)) if k > len(s): print("impossible") else: print(max(0, k - unique)) ```
output
1
82,253
0
164,507
Provide tags and a correct Python 3 solution for this coding contest problem. Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible. String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input First line of input contains string s, consisting only of lowercase Latin letters (1 ≀ |s| ≀ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≀ k ≀ 26). Output Print single line with a minimum number of necessary changes, or the word Β«impossibleΒ» (without quotes) if it is impossible. Examples Input yandex 6 Output 0 Input yahoo 5 Output 1 Input google 7 Output impossible Note In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
instruction
0
82,254
0
164,508
Tags: greedy, implementation, strings Correct 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())) from collections import Counter #print("\n".join(ls)) #print(os.path.commonprefix(ls[0:2])) #for i in range(int(input())): s=input() n=int(input()) v=[0]*26 for i in range(len(s)): v[ord(s[i])-97]=1 if len(s)<n: print("impossible") else: if sum(v)>n: print(0) else: print(n - sum(v)) ```
output
1
82,254
0
164,509
Provide tags and a correct Python 3 solution for this coding contest problem. Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible. String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input First line of input contains string s, consisting only of lowercase Latin letters (1 ≀ |s| ≀ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≀ k ≀ 26). Output Print single line with a minimum number of necessary changes, or the word Β«impossibleΒ» (without quotes) if it is impossible. Examples Input yandex 6 Output 0 Input yahoo 5 Output 1 Input google 7 Output impossible Note In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
instruction
0
82,255
0
164,510
Tags: greedy, implementation, strings Correct Solution: ``` s = input() n = int(input()) if n > len(s): print("impossible") else: ls = list(s) ss = set(ls) x = (n - len(ss)) if x < 0: print(0) else: print(x) ```
output
1
82,255
0
164,511
Provide tags and a correct Python 3 solution for this coding contest problem. Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible. String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input First line of input contains string s, consisting only of lowercase Latin letters (1 ≀ |s| ≀ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≀ k ≀ 26). Output Print single line with a minimum number of necessary changes, or the word Β«impossibleΒ» (without quotes) if it is impossible. Examples Input yandex 6 Output 0 Input yahoo 5 Output 1 Input google 7 Output impossible Note In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
instruction
0
82,256
0
164,512
Tags: greedy, implementation, strings Correct Solution: ``` s = input() k = int(input()) if(k>len(s)): print("impossible") else: sizeSet = len(set(s)) if(sizeSet>=k): print(0) else: dif = k-len(set(s)) print(dif) ```
output
1
82,256
0
164,513
Provide tags and a correct Python 3 solution for this coding contest problem. Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible. String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input First line of input contains string s, consisting only of lowercase Latin letters (1 ≀ |s| ≀ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≀ k ≀ 26). Output Print single line with a minimum number of necessary changes, or the word Β«impossibleΒ» (without quotes) if it is impossible. Examples Input yandex 6 Output 0 Input yahoo 5 Output 1 Input google 7 Output impossible Note In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
instruction
0
82,257
0
164,514
Tags: greedy, implementation, strings Correct Solution: ``` #!/usr/bin/env python3 # -*- coding: utf-8 -*- import string a1 = list(string.ascii_lowercase) a2 = [] sum = 0 s = input() for _ in s: if _ in a1 and _ not in a2: sum += 1 a2.append(_) k = int(input()) if len(s) < k: print("impossible") elif k - sum > 0: print(k - sum) else: print(0) ```
output
1
82,257
0
164,515
Provide tags and a correct Python 3 solution for this coding contest problem. Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible. String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input First line of input contains string s, consisting only of lowercase Latin letters (1 ≀ |s| ≀ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≀ k ≀ 26). Output Print single line with a minimum number of necessary changes, or the word Β«impossibleΒ» (without quotes) if it is impossible. Examples Input yandex 6 Output 0 Input yahoo 5 Output 1 Input google 7 Output impossible Note In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6.
instruction
0
82,258
0
164,516
Tags: greedy, implementation, strings Correct Solution: ``` s=input() k=int(input()) x=len(set(s)) if len(s)<k: print("impossible") else: print(max(k-x,0)) ```
output
1
82,258
0
164,517
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible. String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input First line of input contains string s, consisting only of lowercase Latin letters (1 ≀ |s| ≀ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≀ k ≀ 26). Output Print single line with a minimum number of necessary changes, or the word Β«impossibleΒ» (without quotes) if it is impossible. Examples Input yandex 6 Output 0 Input yahoo 5 Output 1 Input google 7 Output impossible Note In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6. Submitted Solution: ``` x = input() y = len(set(x)) k = int(input()) if (len(x)<k): print("impossible") else: print(max(k - y, 0)) ```
instruction
0
82,260
0
164,520
Yes
output
1
82,260
0
164,521
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible. String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input First line of input contains string s, consisting only of lowercase Latin letters (1 ≀ |s| ≀ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≀ k ≀ 26). Output Print single line with a minimum number of necessary changes, or the word Β«impossibleΒ» (without quotes) if it is impossible. Examples Input yandex 6 Output 0 Input yahoo 5 Output 1 Input google 7 Output impossible Note In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6. Submitted Solution: ``` s=input() k=int(input()) print('impossible' if k>len(s) else max(0,k-len(set([i for i in s])))) ```
instruction
0
82,261
0
164,522
Yes
output
1
82,261
0
164,523
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible. String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input First line of input contains string s, consisting only of lowercase Latin letters (1 ≀ |s| ≀ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≀ k ≀ 26). Output Print single line with a minimum number of necessary changes, or the word Β«impossibleΒ» (without quotes) if it is impossible. Examples Input yandex 6 Output 0 Input yahoo 5 Output 1 Input google 7 Output impossible Note In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6. Submitted Solution: ``` from collections import Counter string = input() cond_num = int(input()) if len(string) < cond_num or cond_num > 26: print('impossible') else: ans = max(cond_num - len(Counter(string)), 0) print(ans) ```
instruction
0
82,262
0
164,524
Yes
output
1
82,262
0
164,525
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible. String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input First line of input contains string s, consisting only of lowercase Latin letters (1 ≀ |s| ≀ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≀ k ≀ 26). Output Print single line with a minimum number of necessary changes, or the word Β«impossibleΒ» (without quotes) if it is impossible. Examples Input yandex 6 Output 0 Input yahoo 5 Output 1 Input google 7 Output impossible Note In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6. Submitted Solution: ``` s=input() n=int(input()) c=0 l=[] for i in s: if i not in l: l.append(i) for i in l: c+=s.count(i)-1 if len(s)<n: print('Imposible') else: print(c) ```
instruction
0
82,263
0
164,526
No
output
1
82,263
0
164,527
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible. String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. Input First line of input contains string s, consisting only of lowercase Latin letters (1 ≀ |s| ≀ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≀ k ≀ 26). Output Print single line with a minimum number of necessary changes, or the word Β«impossibleΒ» (without quotes) if it is impossible. Examples Input yandex 6 Output 0 Input yahoo 5 Output 1 Input google 7 Output impossible Note In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6. Submitted Solution: ``` s=input() p=input() n=len(s) if n<int(p): print("impossible") else: l=[s[0]] for i in range(1,n): if l.count(s[i])==0: l.append(s[i]) b=int(p)-len(l) print(b) ```
instruction
0
82,264
0
164,528
No
output
1
82,264
0
164,529
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Problem Given the strings S and Q queries. The i-th query (0 ≀ i ≀ Q-1) is given the closed interval [li, ri] and the string Mi. Output how many character strings Mi exist in the substring from the li character to the ri character of S. Constraints * 1 ≀ | S | ≀ 100000 * 1 ≀ Q ≀ 100000 * 1 ≀ | Mi | ≀ 100000 (0 ≀ i ≀ Q-1) * 0 ≀ li ≀ ri <| S | (0 ≀ i ≀ Q-1) * All characters are lowercase * The total number of characters in string M does not exceed 2000000 Input The input is given in the following format. S Q l0 r0 M0 l1 r1 M1 .. .. .. lQβˆ’1 rQβˆ’1 MQβˆ’1 The string S and the number of queries Q are given on the first line, separated by blanks. The following Q lines are given the integers li, ri, Mi, separated by blanks. Output The output consists of Q lines. Print the answer to each query on one line in turn. Examples Input rupcrupc 5 0 3 rupc 0 7 rupc 2 7 ru 2 7 pc 1 5 u Output 1 2 1 2 2 Input abatagaadbura 8 0 6 a 6 12 a 0 6 aa 0 3 a 3 5 a 5 9 a 1 8 b 1 12 b Output 4 3 0 2 1 2 1 2 Input aaaaaaaaaa 5 0 9 aaa 0 9 aa 5 9 aaaa 2 8 aa 1 2 a Output 8 9 2 6 2 Submitted Solution: ``` s, n = input().split() n = int(n) for _ in range(n): li = input().split() # print('li:',li) word = li[-1] i,j = map(int,li[:2]) partS = s[i:j+1] # print('word:',word) # print('parts:',partS) nword = 0 for idx in range(len(partS)-len(word)+1): # print(partS[idx:idx+len(word)]) if partS[idx:idx+len(word)] == word: nword += 1 print(nword) ```
instruction
0
82,522
0
165,044
No
output
1
82,522
0
165,045
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant loves strings very much. He has an array a from n strings, consisting of lowercase English letters. Let's number the elements of the array from 1 to n, then let's denote the element number i as ai. For each string ai (1 ≀ i ≀ n) the Little Elephant wants to find the number of pairs of integers l and r (1 ≀ l ≀ r ≀ |ai|) such that substring ai[l... r] is a substring to at least k strings from array a (including the i-th string). Help the Little Elephant solve this problem. If you are not familiar with the basic notation in string problems, you can find the corresponding definitions in the notes. Input The first line contains two space-separated integers β€” n and k (1 ≀ n, k ≀ 105). Next n lines contain array a. The i-th line contains a non-empty string ai, consisting of lowercase English letter. The total length of all strings ai does not exceed 105. Output On a single line print n space-separated integers β€” the i-th number is the answer for string ai. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 3 1 abc a ab Output 6 1 3 Input 7 4 rubik furik abab baba aaabbbababa abababababa zero Output 1 0 9 9 21 30 0 Note Let's assume that you are given string a = a1a2... a|a|, then let's denote the string's length as |a| and the string's i-th character as ai. A substring a[l... r] (1 ≀ l ≀ r ≀ |a|) of string a is string alal + 1... ar. String a is a substring of string b, if there exists such pair of integers l and r (1 ≀ l ≀ r ≀ |b|), that b[l... r] = a. Submitted Solution: ``` class Problem: def __init__(self, S, ind, length, n): self.s = S self.ind = ind self.length = length self.n = n self.sa = self.suffix_array() self.lcp = self.calc_lcp() self.range = self.build_range() self.table, self.logs = self.build_table() def build_range(self): vis = [0 for _ in range(len(self.s))] F = [] L = 0 cnt = 0 for i in range(len(self.s) - self.n): vis[ind[self.sa[i]]] += 1 if vis[ind[self.sa[i]]] == 1: cnt += 1 while L < i and cnt >= K: if vis[ind[self.sa[L]]] == 1 and cnt == K: break vis[ind[self.sa[L]]] -= 1 L += 1 if vis[ind[self.sa[L-1]]] == 0: cnt -= 1 F.append(L if cnt >= K else -1) return F def calc_lcp(self): rank = [0 for _ in range(len(self.s))] for i in range(len(self.s)): rank[self.sa[i]] = i lcp = [0 for _ in range(len(self.s) - 1)] h = 0 for i in range(len(self.s)): if rank[i] < len(self.s) - 1: while max(i, self.sa[rank[i] + 1]) + h < len(self.s) and self.s[i + h] == self.s[self.sa[rank[i] + 1] + h]: h += 1 lcp[rank[i]] = h if h > 0: h -= 1 return lcp def suffix_array(self): self.s.append(0) sa = [0 for _ in range(len(self.s))] cnt256 = [0 for _ in range(max(self.s) + 1)] for c in self.s: cnt256[c] += 1 for i in range(1, len(cnt256)): cnt256[i] += cnt256[i - 1] for i in range(len(self.s) - 1, -1, -1): cnt256[self.s[i]] -= 1 sa[cnt256[self.s[i]]] = i rank = 0 ranks = [0 for _ in range(len(self.s))] for i in range(1, len(self.s)): if self.s[sa[i - 1]] != self.s[sa[i]]: rank += 1 ranks[sa[i]] = rank k = 1 while k < len(self.s): sa_new = [0 for _ in range(len(self.s))] rank_new = [0 for _ in range(len(self.s))] for i in range(len(self.s)): sa_new[i] = sa[i] - k if sa_new[i] < 0: sa_new[i] += len(self.s) cnt = [0 for _ in range(len(self.s))] for i in range(len(self.s)): cnt[ranks[i]] += 1 for i in range(1, len(self.s)): cnt[i] += cnt[i - 1] for i in range(len(self.s) - 1, -1, -1): cnt[ranks[sa_new[i]]] -= 1 sa[cnt[ranks[sa_new[i]]]] = sa_new[i] rank = 0 for i in range(1, len(self.s)): if ranks[sa[i - 1]] != ranks[sa[i]] or ranks[sa[i - 1] + k] != ranks[sa[i] + k]: rank += 1 rank_new[sa[i]] = rank ranks = rank_new k *= 2 self.s.pop() return sa[1:] def build_table(self): size = len(self.range) table = [[i for i in self.lcp[:size]]] k = 1 while 2 * k < size: row = [] for i in range(size): min_val = table[-1][i] if i + k < size: min_val = min(min_val, table[-1][i + k]) row.append(min_val) k *= 2 table.append(row) logs = [] h = 0 for i in range(size): if (1 << (h + 1)) < i: h += 1 logs.append(h) return table, logs def query(self, l, r): if l == r: return len(self.s) + 1 log = self.logs[r - l] return min(self.table[log][l], self.table[log][r - (1 << log)]) def check(self, x, k): left = x right = len(self.range) - 1 while left < right - 1: mid = (left + right) >> 1 if self.query(x, mid) >= k: left = mid else: right = mid - 1 if self.query(x, right) >= k: R = right else: R = left left = 0 right = x while left < right - 1: mid = (left + right) >> 1 if self.query(mid, x) >= k: right = mid else: left = mid + 1 if self.query(left, x) >= k: L = left else: L = right return L <= self.range[R] def solve(self): ans = [0 for _ in range(self.n)] for i in range(len(self.s) - self.n): left = 0 right = length[self.sa[i]] while left < right - 1: mid = (left + right) >> 1 if self.check(i, mid): left = mid else: right = mid - 1 if self.check(i, right): ans[ind[self.sa[i]]] += right else: ans[ind[self.sa[i]]] += left print(' '.join(map(lambda x: str(x), ans))) line = input().split() n = int(line[0]) K = int(line[1]) S = [] ind = [] length = [] for i in range(n): s = input() strlen = len(s) for j in range(strlen): S.append(ord(s[j]) - ord('a') + 1) ind.append(i) length.append(strlen - j) S.append(26 + i) ind.append(-1) length.append(-1) p = Problem(S, ind, length, n) p.solve() ```
instruction
0
82,851
0
165,702
No
output
1
82,851
0
165,703
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a string s of length n consisting of lowercase English letters. For two given strings s and t, say S is the set of distinct characters of s and T is the set of distinct characters of t. The strings s and t are isomorphic if their lengths are equal and there is a one-to-one mapping (bijection) f between S and T for which f(si) = ti. Formally: 1. f(si) = ti for any index i, 2. for any character <image> there is exactly one character <image> that f(x) = y, 3. for any character <image> there is exactly one character <image> that f(x) = y. For example, the strings "aababc" and "bbcbcz" are isomorphic. Also the strings "aaaww" and "wwwaa" are isomorphic. The following pairs of strings are not isomorphic: "aab" and "bbb", "test" and "best". You have to handle m queries characterized by three integers x, y, len (1 ≀ x, y ≀ n - len + 1). For each query check if two substrings s[x... x + len - 1] and s[y... y + len - 1] are isomorphic. Input The first line contains two space-separated integers n and m (1 ≀ n ≀ 2Β·105, 1 ≀ m ≀ 2Β·105) β€” the length of the string s and the number of queries. The second line contains string s consisting of n lowercase English letters. The following m lines contain a single query on each line: xi, yi and leni (1 ≀ xi, yi ≀ n, 1 ≀ leni ≀ n - max(xi, yi) + 1) β€” the description of the pair of the substrings to check. Output For each query in a separate line print "YES" if substrings s[xi... xi + leni - 1] and s[yi... yi + leni - 1] are isomorphic and "NO" otherwise. Example Input 7 4 abacaba 1 1 1 1 4 2 2 1 3 2 4 3 Output YES YES NO YES Note The queries in the example are following: 1. substrings "a" and "a" are isomorphic: f(a) = a; 2. substrings "ab" and "ca" are isomorphic: f(a) = c, f(b) = a; 3. substrings "bac" and "aba" are not isomorphic since f(b) and f(c) must be equal to a at same time; 4. substrings "bac" and "cab" are isomorphic: f(b) = c, f(a) = a, f(c) = b.
instruction
0
83,132
0
166,264
Tags: hashing, strings Correct Solution: ``` def getIntList(): return list(map(int, input().split())) def getTransIntList(n): first=getIntList() m=len(first) result=[[0]*n for _ in range(m)] for i in range(m): result[i][0]=first[i] for j in range(1, n): curr=getIntList() for i in range(m): result[i][j]=curr[i] return result n, m = getIntList() s=input() orda=ord('a') a=[ord(s[i])-orda for i in range(n)] countSame=[1]*n upLim=0 for lowLim in range(n): if lowLim<upLim: continue for upLim in range(lowLim+1, n): if a[upLim]!=a[lowLim]: break else: upLim+=1 for i in range(lowLim, upLim): countSame[i]=upLim-i def judge(x, y, l): map1=[0]*27 map2=[0]*27 count=0 lowLim=min(countSame[x], countSame[y])-1 for i in range(lowLim, l): x1=map1[a[x+i]] x2=map2[a[y+i]] if x1!=x2: return 'NO' if x1==0: count+=1 map1[a[x+i]]=count map2[a[y+i]]=count return 'YES' results=[] for _ in range(m): x, y, l=getIntList() results.append(judge(x-1, y-1, l)) print('\n'.join(results)) ```
output
1
83,132
0
166,265
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a string s of length n consisting of lowercase English letters. For two given strings s and t, say S is the set of distinct characters of s and T is the set of distinct characters of t. The strings s and t are isomorphic if their lengths are equal and there is a one-to-one mapping (bijection) f between S and T for which f(si) = ti. Formally: 1. f(si) = ti for any index i, 2. for any character <image> there is exactly one character <image> that f(x) = y, 3. for any character <image> there is exactly one character <image> that f(x) = y. For example, the strings "aababc" and "bbcbcz" are isomorphic. Also the strings "aaaww" and "wwwaa" are isomorphic. The following pairs of strings are not isomorphic: "aab" and "bbb", "test" and "best". You have to handle m queries characterized by three integers x, y, len (1 ≀ x, y ≀ n - len + 1). For each query check if two substrings s[x... x + len - 1] and s[y... y + len - 1] are isomorphic. Input The first line contains two space-separated integers n and m (1 ≀ n ≀ 2Β·105, 1 ≀ m ≀ 2Β·105) β€” the length of the string s and the number of queries. The second line contains string s consisting of n lowercase English letters. The following m lines contain a single query on each line: xi, yi and leni (1 ≀ xi, yi ≀ n, 1 ≀ leni ≀ n - max(xi, yi) + 1) β€” the description of the pair of the substrings to check. Output For each query in a separate line print "YES" if substrings s[xi... xi + leni - 1] and s[yi... yi + leni - 1] are isomorphic and "NO" otherwise. Example Input 7 4 abacaba 1 1 1 1 4 2 2 1 3 2 4 3 Output YES YES NO YES Note The queries in the example are following: 1. substrings "a" and "a" are isomorphic: f(a) = a; 2. substrings "ab" and "ca" are isomorphic: f(a) = c, f(b) = a; 3. substrings "bac" and "aba" are not isomorphic since f(b) and f(c) must be equal to a at same time; 4. substrings "bac" and "cab" are isomorphic: f(b) = c, f(a) = a, f(c) = b.
instruction
0
83,133
0
166,266
Tags: hashing, strings Correct Solution: ``` def main(): import sys input = sys.stdin.buffer.readline N, M = map(int, input().split()) S = input().split() S = S[0].decode() B1 = [[0] * (N+1) for _ in range(26)] #B2 = [[0] * (N+1) for _ in range(26)] mod1 = 1000000007 #mod2 = 1000000009 base1 = 2 #base2 = 2009 base1_inv_list = [1] * N #base2_inv_list = [1] * N base1_inv = pow(base1, mod1-2, mod1) #base2_inv = pow(base2, mod2-2, mod2) for i in range(1, N): base1_inv_list[i] = (base1_inv_list[i-1] * base1_inv)%mod1 #base2_inv_list[i] = (base2_inv_list[i-1] * base2_inv)%mod2 p1 = p2 = 1 for i, s in enumerate(S): j = ord(s) - 97 p1 = (p1 * base1)%mod1 #p2 = (p2*base2)%mod2 B1[j][i+1] = p1 #B2[j][i+1] = p2 for j_ in range(26): for i in range(N): new = B1[j_][i+1] + B1[j_][i] if new >= mod1: new -= mod1 B1[j_][i+1] = new #B2[j_][i + 1] = (B2[j_][i + 1] + B2[j_][i]) % mod2 ans = [''] * M for m in range(M): x, y, L = map(int, input().split()) #X1 = [] #X2 = [0] * 26 #Y1 = [] #Y2 = [0] * 26 seen1 = {} for j in range(26): x1 = (((B1[j][x + L - 1] - B1[j][x - 1]) % mod1) * base1_inv_list[x - 1]) % mod1 # X2[j] = (((B2[j][x + L-1] - B2[j][x - 1]) % mod2) * base2_inv_list[x-1])%mod2 y1 = (((B1[j][y + L - 1] - B1[j][y - 1]) % mod1) * base1_inv_list[y - 1]) % mod1 # Y2[j] = (((B2[j][y + L-1] - B2[j][y - 1]) % mod2) * base2_inv_list[y-1])%mod2 if x1 not in seen1: seen1[x1] = 1 else: seen1[x1] += 1 if y1 not in seen1: seen1[y1] = 1 else: seen1[y1] += 1 #X1.sort() #X2.sort() #Y1.sort() #Y2.sort() ok = 1 #for j in range(26): #if heappop(X1) != heappop(Y1): # ok = 0 # break #if X2[j] != Y2[j]: # ok = 0 # break for z in seen1.values(): if z&1: ok = 0 break if ok: ans[m] = 'YES' else: ans[m] = 'NO' print('\n'.join(ans)) if __name__ == '__main__': main() ```
output
1
83,133
0
166,267
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a string s of length n consisting of lowercase English letters. For two given strings s and t, say S is the set of distinct characters of s and T is the set of distinct characters of t. The strings s and t are isomorphic if their lengths are equal and there is a one-to-one mapping (bijection) f between S and T for which f(si) = ti. Formally: 1. f(si) = ti for any index i, 2. for any character <image> there is exactly one character <image> that f(x) = y, 3. for any character <image> there is exactly one character <image> that f(x) = y. For example, the strings "aababc" and "bbcbcz" are isomorphic. Also the strings "aaaww" and "wwwaa" are isomorphic. The following pairs of strings are not isomorphic: "aab" and "bbb", "test" and "best". You have to handle m queries characterized by three integers x, y, len (1 ≀ x, y ≀ n - len + 1). For each query check if two substrings s[x... x + len - 1] and s[y... y + len - 1] are isomorphic. Input The first line contains two space-separated integers n and m (1 ≀ n ≀ 2Β·105, 1 ≀ m ≀ 2Β·105) β€” the length of the string s and the number of queries. The second line contains string s consisting of n lowercase English letters. The following m lines contain a single query on each line: xi, yi and leni (1 ≀ xi, yi ≀ n, 1 ≀ leni ≀ n - max(xi, yi) + 1) β€” the description of the pair of the substrings to check. Output For each query in a separate line print "YES" if substrings s[xi... xi + leni - 1] and s[yi... yi + leni - 1] are isomorphic and "NO" otherwise. Example Input 7 4 abacaba 1 1 1 1 4 2 2 1 3 2 4 3 Output YES YES NO YES Note The queries in the example are following: 1. substrings "a" and "a" are isomorphic: f(a) = a; 2. substrings "ab" and "ca" are isomorphic: f(a) = c, f(b) = a; 3. substrings "bac" and "aba" are not isomorphic since f(b) and f(c) must be equal to a at same time; 4. substrings "bac" and "cab" are isomorphic: f(b) = c, f(a) = a, f(c) = b.
instruction
0
83,134
0
166,268
Tags: hashing, strings Correct Solution: ``` import sys, time input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ MOD = 10 ** 9 + [7, 9, 21, 33][int(time.monotonic()) % 4] BASE = 2 ALPHA = 26 n, m = map(int, input().split()) s = [ord(c) - 97 for c in input()] h = [[0] * (n + 1) for _ in range(ALPHA)] p = [1] * (n + 1) for i in range(1, n + 1): p[i] = p[i - 1] * 2 % MOD for i in range(ALPHA): for j in range(n): h[i][j] = (h[i][j - 1] * BASE + (s[j] == i)) % MOD seq = [list(range(26))] * (n + 1) for i in range(n - 1, -1, -1): idx = seq[i + 1].index(s[i]) seq[i] = [s[i]] + seq[i + 1][:idx] + seq[i + 1][idx + 1:] def get(hz, x, l): return (hz[x + l - 1] - hz[x - 1] * p[l]) % MOD out = [] for _ in range(m): x, y, l = map(int, input().split()) x, y = x - 1, y - 1 out.append('YES' if all(get(h[k1], x, l) == get(h[k2], y, l) for k1, k2 in zip(seq[x], seq[y])) else 'NO') print(*out, sep='\n') ```
output
1
83,134
0
166,269
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a string s of length n consisting of lowercase English letters. For two given strings s and t, say S is the set of distinct characters of s and T is the set of distinct characters of t. The strings s and t are isomorphic if their lengths are equal and there is a one-to-one mapping (bijection) f between S and T for which f(si) = ti. Formally: 1. f(si) = ti for any index i, 2. for any character <image> there is exactly one character <image> that f(x) = y, 3. for any character <image> there is exactly one character <image> that f(x) = y. For example, the strings "aababc" and "bbcbcz" are isomorphic. Also the strings "aaaww" and "wwwaa" are isomorphic. The following pairs of strings are not isomorphic: "aab" and "bbb", "test" and "best". You have to handle m queries characterized by three integers x, y, len (1 ≀ x, y ≀ n - len + 1). For each query check if two substrings s[x... x + len - 1] and s[y... y + len - 1] are isomorphic. Input The first line contains two space-separated integers n and m (1 ≀ n ≀ 2Β·105, 1 ≀ m ≀ 2Β·105) β€” the length of the string s and the number of queries. The second line contains string s consisting of n lowercase English letters. The following m lines contain a single query on each line: xi, yi and leni (1 ≀ xi, yi ≀ n, 1 ≀ leni ≀ n - max(xi, yi) + 1) β€” the description of the pair of the substrings to check. Output For each query in a separate line print "YES" if substrings s[xi... xi + leni - 1] and s[yi... yi + leni - 1] are isomorphic and "NO" otherwise. Example Input 7 4 abacaba 1 1 1 1 4 2 2 1 3 2 4 3 Output YES YES NO YES Note The queries in the example are following: 1. substrings "a" and "a" are isomorphic: f(a) = a; 2. substrings "ab" and "ca" are isomorphic: f(a) = c, f(b) = a; 3. substrings "bac" and "aba" are not isomorphic since f(b) and f(c) must be equal to a at same time; 4. substrings "bac" and "cab" are isomorphic: f(b) = c, f(a) = a, f(c) = b.
instruction
0
83,135
0
166,270
Tags: hashing, strings Correct Solution: ``` def getIntList(): return list(map(int, input().split())); def getTransIntList(n): first=getIntList(); m=len(first); result=[[0]*n for _ in range(m)]; for i in range(m): result[i][0]=first[i]; for j in range(1, n): curr=getIntList(); for i in range(m): result[i][j]=curr[i]; return result; n, m = getIntList() s=input(); orda=ord('a'); a=[ord(s[i])-orda for i in range(n)]; countSame=[1]*n; upLim=0; for lowLim in range(n): if lowLim<upLim: continue; for upLim in range(lowLim+1, n): if a[upLim]!=a[lowLim]: break; else: upLim+=1; for i in range(lowLim, upLim): countSame[i]=upLim-i; def test(x, y, l): map1=[0]*27; map2=[0]*27; count=0; lowLim=min(countSame[x], countSame[y])-1; for i in range(lowLim, l): x1=map1[a[x+i]]; x2=map2[a[y+i]]; if x1!=x2: return 'NO'; if x1==0: count+=1; map1[a[x+i]]=count; map2[a[y+i]]=count; return 'YES'; results=[]; for _ in range(m): x, y, l=getIntList(); results.append(test(x-1, y-1, l)); print('\n'.join(results)); ```
output
1
83,135
0
166,271
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. For two given strings s and t, say S is the set of distinct characters of s and T is the set of distinct characters of t. The strings s and t are isomorphic if their lengths are equal and there is a one-to-one mapping (bijection) f between S and T for which f(si) = ti. Formally: 1. f(si) = ti for any index i, 2. for any character <image> there is exactly one character <image> that f(x) = y, 3. for any character <image> there is exactly one character <image> that f(x) = y. For example, the strings "aababc" and "bbcbcz" are isomorphic. Also the strings "aaaww" and "wwwaa" are isomorphic. The following pairs of strings are not isomorphic: "aab" and "bbb", "test" and "best". You have to handle m queries characterized by three integers x, y, len (1 ≀ x, y ≀ n - len + 1). For each query check if two substrings s[x... x + len - 1] and s[y... y + len - 1] are isomorphic. Input The first line contains two space-separated integers n and m (1 ≀ n ≀ 2Β·105, 1 ≀ m ≀ 2Β·105) β€” the length of the string s and the number of queries. The second line contains string s consisting of n lowercase English letters. The following m lines contain a single query on each line: xi, yi and leni (1 ≀ xi, yi ≀ n, 1 ≀ leni ≀ n - max(xi, yi) + 1) β€” the description of the pair of the substrings to check. Output For each query in a separate line print "YES" if substrings s[xi... xi + leni - 1] and s[yi... yi + leni - 1] are isomorphic and "NO" otherwise. Example Input 7 4 abacaba 1 1 1 1 4 2 2 1 3 2 4 3 Output YES YES NO YES Note The queries in the example are following: 1. substrings "a" and "a" are isomorphic: f(a) = a; 2. substrings "ab" and "ca" are isomorphic: f(a) = c, f(b) = a; 3. substrings "bac" and "aba" are not isomorphic since f(b) and f(c) must be equal to a at same time; 4. substrings "bac" and "cab" are isomorphic: f(b) = c, f(a) = a, f(c) = b. Submitted Solution: ``` #!/usr/bin/env python3 [n, m] = map(int, input().strip().split()) s = input().strip() intg = [[0 for _ in range(n + 1)] for j in range(26)] ia = ord('a') for i in range(n): for j in range(26): intg[j][i + 1] = intg[j][i] intg[ord(s[i]) - ia][i + 1] += 1 def get(x, l): return tuple(sorted((intg[i][x - 1 + l] - intg[i][x - 1]) for i in range(26))) for _ in range(m): [x, y, l] = map(int, input().strip().split()) if get(x, l) == get(y, l): print ('YES') else: print ('NO') ```
instruction
0
83,136
0
166,272
No
output
1
83,136
0
166,273
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. For two given strings s and t, say S is the set of distinct characters of s and T is the set of distinct characters of t. The strings s and t are isomorphic if their lengths are equal and there is a one-to-one mapping (bijection) f between S and T for which f(si) = ti. Formally: 1. f(si) = ti for any index i, 2. for any character <image> there is exactly one character <image> that f(x) = y, 3. for any character <image> there is exactly one character <image> that f(x) = y. For example, the strings "aababc" and "bbcbcz" are isomorphic. Also the strings "aaaww" and "wwwaa" are isomorphic. The following pairs of strings are not isomorphic: "aab" and "bbb", "test" and "best". You have to handle m queries characterized by three integers x, y, len (1 ≀ x, y ≀ n - len + 1). For each query check if two substrings s[x... x + len - 1] and s[y... y + len - 1] are isomorphic. Input The first line contains two space-separated integers n and m (1 ≀ n ≀ 2Β·105, 1 ≀ m ≀ 2Β·105) β€” the length of the string s and the number of queries. The second line contains string s consisting of n lowercase English letters. The following m lines contain a single query on each line: xi, yi and leni (1 ≀ xi, yi ≀ n, 1 ≀ leni ≀ n - max(xi, yi) + 1) β€” the description of the pair of the substrings to check. Output For each query in a separate line print "YES" if substrings s[xi... xi + leni - 1] and s[yi... yi + leni - 1] are isomorphic and "NO" otherwise. Example Input 7 4 abacaba 1 1 1 1 4 2 2 1 3 2 4 3 Output YES YES NO YES Note The queries in the example are following: 1. substrings "a" and "a" are isomorphic: f(a) = a; 2. substrings "ab" and "ca" are isomorphic: f(a) = c, f(b) = a; 3. substrings "bac" and "aba" are not isomorphic since f(b) and f(c) must be equal to a at same time; 4. substrings "bac" and "cab" are isomorphic: f(b) = c, f(a) = a, f(c) = b. Submitted Solution: ``` def isIso(s1, s2): m, n = len(s1), len(s2) if m != n: return False marked = [False] * 256 Map = [-1] * 256 for i in range(n): if Map[ord(s1[i])] == -1: if marked[ord(s2[i])] == True: return False marked[ord(s2[i])] = True Map[ord(s1[i])] = s2[i] elif Map[ord(s1[i])] != s2[i]: return False return True length, queries = map(int, input().split()) s = input() for q in range(queries): x, y, l = map(int, input().split()) if(isIso(s[x-1: x + l - 1], s[y - 1: y + l-1])): print("Yes") else: print("No") ```
instruction
0
83,137
0
166,274
No
output
1
83,137
0
166,275