message
stringlengths
2
23.8k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
97
109k
cluster
float64
0
0
__index_level_0__
int64
194
217k
Provide tags and a correct Python 3 solution for this coding contest problem. This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You may also refer to the guide on interactive problems: <https://codeforces.com/blog/entry/45307>. You are given a string t consisting of n lowercase Latin letters. This string was cyphered as follows: initially, the jury had a string s consisting of n lowercase Latin letters. Then they applied a sequence of no more than n (possibly zero) operations. i-th operation is denoted by two integers a_i and b_i (1 ≀ a_i, b_i ≀ n), and means swapping two elements of the string with indices a_i and b_i. All operations were done in the order they were placed in the sequence. For example, if s is xyz and 2 following operations are performed: a_1 = 1, b_1 = 2; a_2 = 2, b_2 = 3, then after the first operation the current string is yxz, and after the second operation the current string is yzx, so t is yzx. You are asked to restore the original string s. Unfortunately, you have no information about the operations used in the algorithm (you don't even know if there were any operations in the sequence). But you may run the same sequence of operations on any string you want, provided that it contains only lowercase Latin letters and its length is n, and get the resulting string after those operations. Can you guess the original string s asking the testing system to run the sequence of swaps no more than 3 times? The string s and the sequence of swaps are fixed in each test; the interactor doesn't try to adapt the test to your solution. Input Initially the testing system sends one string t, consisting of lowercase Latin letters (1 ≀ |t| = n ≀ 10^4). Output To give the answer, your program should print one line ! s with a line break in the end. After that, it should flush the output and terminate gracefully. Interaction Before giving the answer, you may submit no more than 3 queries. To ask a query, print one line in the following format: ? s', where s' should be a string consisting of exaclty n lowercase Latin letters. The line should be ended with a line break character. After submitting a query, flush the output and read the answer to your query β€” a string t' consisting of n lowercase Latin letters, which is the result of applying the sequence of swaps to string s'. This string will be given on a separate line ended by a line break character. If you submit an incorrect query (or ask more than 3 queries), the answer to it will be one string 0. After receiving such an answer, your program should terminate immediately β€” otherwise you may receive verdict "Runtime error", "Time limit exceeded" or some other verdict instead of "Wrong answer". Example Input yzx aab baa aba Output ? baa ? aba ? aab ! xyz Note In the sample, the testcase described in the statement is used. The participant asks the first query with string baa, which is transformed to aab. The second query contains string aba, which is transformed to baa. The third query contains string aab, which is transformed to aba. The participant can deduce that the initial string s was xyz. Note for hacking phase: To submit a test in hacking phase, you should provide it in the following format: The first line should contain the string s you guess, consisting of n ∈ [1, 10000] lowercase Latin letters. The second line should contain k (0 ≀ k ≀ n) β€” the number of swap operations in the sequence. Then k lines should follow, i-th of them should denote i-th operation with two integers a_i and b_i (1 ≀ a_i, b_i ≀ n). For example, the sample test would look like that: xyz 2 1 2 2 3
instruction
0
15,999
0
31,998
Tags: bitmasks, chinese remainder theorem, constructive algorithms, interactive, math Correct Solution: ``` from itertools import chain, cycle, islice, repeat from operator import itemgetter d = 26 a = ord('a') t = input() n = len(t) p = [0]*n for b in (d ** 2, d, 1): if n >= b: q = (repeat(chr(a + i), b) for i in range(d)) q = chain.from_iterable(q) q = cycle(q) q = islice(q, n) q = ''.join(q) print('?', q, flush=True) s = input() for i, c in enumerate(s): p[i] += b * (ord(c) - a) p = zip(range(n), p) p = sorted(p, key=itemgetter(1)) p = next(zip(*p)) ans = list(t) ans = ''.join(ans[p[i]] for i in range(n)) print('!', ans, flush=True) ```
output
1
15,999
0
31,999
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" and "dabcef". The following string are not diverse: "az", "aa", "bad" and "babc". Note that the letters 'a' and 'z' are not adjacent. Formally, consider positions of all letters in the string in the alphabet. These positions should form contiguous segment, i.e. they should come one by one without any gaps. And all letters in the string should be distinct (duplicates are not allowed). You are given a sequence of strings. For each string, if it is diverse, print "Yes". Otherwise, print "No". Input The first line contains integer n (1 ≀ n ≀ 100), denoting the number of strings to process. The following n lines contains strings, one string per line. Each string contains only lowercase Latin letters, its length is between 1 and 100, inclusive. Output Print n lines, one line per a string in the input. The line should contain "Yes" if the corresponding string is diverse and "No" if the corresponding string is not diverse. You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable. Example Input 8 fced xyz r dabcef az aa bad babc Output Yes Yes Yes Yes No No No No Submitted Solution: ``` for i in range(int(input())): s = sorted(input()) if len(set(s)) == len(s) and ord(s[-1])-ord(s[0]) == len(s)-1: print("YES") else: print("NO") ```
instruction
0
16,012
0
32,024
Yes
output
1
16,012
0
32,025
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" and "dabcef". The following string are not diverse: "az", "aa", "bad" and "babc". Note that the letters 'a' and 'z' are not adjacent. Formally, consider positions of all letters in the string in the alphabet. These positions should form contiguous segment, i.e. they should come one by one without any gaps. And all letters in the string should be distinct (duplicates are not allowed). You are given a sequence of strings. For each string, if it is diverse, print "Yes". Otherwise, print "No". Input The first line contains integer n (1 ≀ n ≀ 100), denoting the number of strings to process. The following n lines contains strings, one string per line. Each string contains only lowercase Latin letters, its length is between 1 and 100, inclusive. Output Print n lines, one line per a string in the input. The line should contain "Yes" if the corresponding string is diverse and "No" if the corresponding string is not diverse. You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable. Example Input 8 fced xyz r dabcef az aa bad babc Output Yes Yes Yes Yes No No No No Submitted Solution: ``` for i in range(int(input())): s=sorted(input()) f=0 for i in range(len(s)-1): if(ord(s[i+1])-ord(s[i])==1): f=f+1 if(f==len(s)-1): print('YES') else: print('NO') ```
instruction
0
16,013
0
32,026
Yes
output
1
16,013
0
32,027
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" and "dabcef". The following string are not diverse: "az", "aa", "bad" and "babc". Note that the letters 'a' and 'z' are not adjacent. Formally, consider positions of all letters in the string in the alphabet. These positions should form contiguous segment, i.e. they should come one by one without any gaps. And all letters in the string should be distinct (duplicates are not allowed). You are given a sequence of strings. For each string, if it is diverse, print "Yes". Otherwise, print "No". Input The first line contains integer n (1 ≀ n ≀ 100), denoting the number of strings to process. The following n lines contains strings, one string per line. Each string contains only lowercase Latin letters, its length is between 1 and 100, inclusive. Output Print n lines, one line per a string in the input. The line should contain "Yes" if the corresponding string is diverse and "No" if the corresponding string is not diverse. You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable. Example Input 8 fced xyz r dabcef az aa bad babc Output Yes Yes Yes Yes No No No No Submitted Solution: ``` n = int(input()) for i in range(n): string = input() leng = len(string) if leng == 1: print("Yes") continue arr = [0] * leng for j in range(leng): arr[j] = ord(string[j]) arr.sort() result = "" for j in range(1,leng): if arr[j] != arr[j-1] + 1: result = "No" break else: result = "Yes" print(result) ```
instruction
0
16,014
0
32,028
Yes
output
1
16,014
0
32,029
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" and "dabcef". The following string are not diverse: "az", "aa", "bad" and "babc". Note that the letters 'a' and 'z' are not adjacent. Formally, consider positions of all letters in the string in the alphabet. These positions should form contiguous segment, i.e. they should come one by one without any gaps. And all letters in the string should be distinct (duplicates are not allowed). You are given a sequence of strings. For each string, if it is diverse, print "Yes". Otherwise, print "No". Input The first line contains integer n (1 ≀ n ≀ 100), denoting the number of strings to process. The following n lines contains strings, one string per line. Each string contains only lowercase Latin letters, its length is between 1 and 100, inclusive. Output Print n lines, one line per a string in the input. The line should contain "Yes" if the corresponding string is diverse and "No" if the corresponding string is not diverse. You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable. Example Input 8 fced xyz r dabcef az aa bad babc Output Yes Yes Yes Yes No No No No Submitted Solution: ``` t=int(input()) l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] for j in range (t): s=input() s=sorted(list(s)) flag=0 if len(s)==1: print("YES") flag=1 elif len(s)==len(set(s)): k=1 prev=s[0] while(flag==0 and k<len(s)): i=s[k] if abs(l.index(prev)-l.index(i))!=1: flag=1 k+=1 prev=i if flag==0: print("YES") else: print("NO") else: print("NO") ```
instruction
0
16,015
0
32,030
Yes
output
1
16,015
0
32,031
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" and "dabcef". The following string are not diverse: "az", "aa", "bad" and "babc". Note that the letters 'a' and 'z' are not adjacent. Formally, consider positions of all letters in the string in the alphabet. These positions should form contiguous segment, i.e. they should come one by one without any gaps. And all letters in the string should be distinct (duplicates are not allowed). You are given a sequence of strings. For each string, if it is diverse, print "Yes". Otherwise, print "No". Input The first line contains integer n (1 ≀ n ≀ 100), denoting the number of strings to process. The following n lines contains strings, one string per line. Each string contains only lowercase Latin letters, its length is between 1 and 100, inclusive. Output Print n lines, one line per a string in the input. The line should contain "Yes" if the corresponding string is diverse and "No" if the corresponding string is not diverse. You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable. Example Input 8 fced xyz r dabcef az aa bad babc Output Yes Yes Yes Yes No No No No Submitted Solution: ``` def loop_line(line): line_set = set() for i in line: if ord(i) + 1 in line_set: print("no") break elif ord(i) - 1 in line_set: print("no") break else: line_set.add(ord(i)) else: print("yes") def loop_n(n, lst): for i in range(n): loop_line(lst[i]) n = int(input()) lst = [] for i in range(n): str_ = map(str, input()) lst.append(str_) loop_n(n, lst) ```
instruction
0
16,016
0
32,032
No
output
1
16,016
0
32,033
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" and "dabcef". The following string are not diverse: "az", "aa", "bad" and "babc". Note that the letters 'a' and 'z' are not adjacent. Formally, consider positions of all letters in the string in the alphabet. These positions should form contiguous segment, i.e. they should come one by one without any gaps. And all letters in the string should be distinct (duplicates are not allowed). You are given a sequence of strings. For each string, if it is diverse, print "Yes". Otherwise, print "No". Input The first line contains integer n (1 ≀ n ≀ 100), denoting the number of strings to process. The following n lines contains strings, one string per line. Each string contains only lowercase Latin letters, its length is between 1 and 100, inclusive. Output Print n lines, one line per a string in the input. The line should contain "Yes" if the corresponding string is diverse and "No" if the corresponding string is not diverse. You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable. Example Input 8 fced xyz r dabcef az aa bad babc Output Yes Yes Yes Yes No No No No Submitted Solution: ``` # https://codeforces.com/gym/298388/problem/A def checkDiverse(arr): arr = list(arr) arr_codes = [ ord(x) for x in list(arr)] big = max(arr_codes) small = min(arr_codes) # print('Big ',big) # print('Small ',small) # print('Len ',len(arr)) if(big-small+1 == len(arr)): return True return False # print('hello world') tc = int(input()) # # print(tc) while tc > 0: string = input() isYes = checkDiverse(string) if isYes: print('Yes') else: print('No') tc -=1 # print('TC ', tc) # print(checkDiverse(list('az'))) ```
instruction
0
16,017
0
32,034
No
output
1
16,017
0
32,035
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" and "dabcef". The following string are not diverse: "az", "aa", "bad" and "babc". Note that the letters 'a' and 'z' are not adjacent. Formally, consider positions of all letters in the string in the alphabet. These positions should form contiguous segment, i.e. they should come one by one without any gaps. And all letters in the string should be distinct (duplicates are not allowed). You are given a sequence of strings. For each string, if it is diverse, print "Yes". Otherwise, print "No". Input The first line contains integer n (1 ≀ n ≀ 100), denoting the number of strings to process. The following n lines contains strings, one string per line. Each string contains only lowercase Latin letters, its length is between 1 and 100, inclusive. Output Print n lines, one line per a string in the input. The line should contain "Yes" if the corresponding string is diverse and "No" if the corresponding string is not diverse. You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable. Example Input 8 fced xyz r dabcef az aa bad babc Output Yes Yes Yes Yes No No No No Submitted Solution: ``` t=int(input()) for i in range(t): a=input() c=0 if len(list(set(a)))==len(a): b=list(set(a)) for j in range(len(a)-1): if ord(a[j])+1==ord(a[j+1]): c=c+1 if c==len(a)-1: print('Yes') else: print('Yes') else: print('No') ```
instruction
0
16,018
0
32,036
No
output
1
16,018
0
32,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" and "dabcef". The following string are not diverse: "az", "aa", "bad" and "babc". Note that the letters 'a' and 'z' are not adjacent. Formally, consider positions of all letters in the string in the alphabet. These positions should form contiguous segment, i.e. they should come one by one without any gaps. And all letters in the string should be distinct (duplicates are not allowed). You are given a sequence of strings. For each string, if it is diverse, print "Yes". Otherwise, print "No". Input The first line contains integer n (1 ≀ n ≀ 100), denoting the number of strings to process. The following n lines contains strings, one string per line. Each string contains only lowercase Latin letters, its length is between 1 and 100, inclusive. Output Print n lines, one line per a string in the input. The line should contain "Yes" if the corresponding string is diverse and "No" if the corresponding string is not diverse. You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable. Example Input 8 fced xyz r dabcef az aa bad babc Output Yes Yes Yes Yes No No No No Submitted Solution: ``` n = int(input()) for _ in range(n): s=input() if len(set(s))==len(s): print("YES") else: print("NO") ```
instruction
0
16,019
0
32,038
No
output
1
16,019
0
32,039
Provide tags and a correct Python 3 solution for this coding contest problem. Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. <image> Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions x1 < x2 < ... < xk where p matches s. More formally, for each xi (1 ≀ i ≀ k) he condition sxisxi + 1... sxi + |p| - 1 = p is fullfilled. Then Malekas wrote down one of subsequences of x1, x2, ... xk (possibly, he didn't write anything) on a piece of paper. Here a sequence b is a subsequence of sequence a if and only if we can turn a into b by removing some of its elements (maybe no one of them or all). After Tavas woke up, Malekas told him everything. He couldn't remember string s, but he knew that both p and s only contains lowercase English letters and also he had the subsequence he had written on that piece of paper. Tavas wonders, what is the number of possible values of s? He asked SaDDas, but he wasn't smart enough to solve this. So, Tavas asked you to calculate this number for him. Answer can be very large, so Tavas wants you to print the answer modulo 109 + 7. Input The first line contains two integers n and m, the length of s and the length of the subsequence Malekas wrote down (1 ≀ n ≀ 106 and 0 ≀ m ≀ n - |p| + 1). The second line contains string p (1 ≀ |p| ≀ n). The next line contains m space separated integers y1, y2, ..., ym, Malekas' subsequence (1 ≀ y1 < y2 < ... < ym ≀ n - |p| + 1). Output In a single line print the answer modulo 1000 000 007. Examples Input 6 2 ioi 1 3 Output 26 Input 5 2 ioi 1 2 Output 0 Note In the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy. Here |x| denotes the length of string x. Please note that it's possible that there is no such string (answer is 0).
instruction
0
16,378
0
32,756
Tags: greedy, hashing, string suffix structures, strings Correct Solution: ``` n, m = map(int, input().split()) s = input() sl = len(s) if m: y = map(int, input().split()) else: y = [] def prefix_func(s): pi = [0] * len(s) for i in range(1, len(s)): j = pi[i - 1] while j > 0 and s[i] != s[j]: j = pi[j - 1] pi[i] = j + 1 if s[i] == s[j] else j return pi pi = prefix_func(s) good = [False] * sl j = sl - 1 while j >= 0: good[j] = True j = pi[j] - 1 end = 0 s = 0 # print good for x in y: if x > end: s += x - end - 1 else: if not good[end - x]: print('0') exit() end = x + sl - 1 s += max(0, n - end) print (pow(26, s, 1000000007)) ```
output
1
16,378
0
32,757
Provide tags and a correct Python 3 solution for this coding contest problem. Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. <image> Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions x1 < x2 < ... < xk where p matches s. More formally, for each xi (1 ≀ i ≀ k) he condition sxisxi + 1... sxi + |p| - 1 = p is fullfilled. Then Malekas wrote down one of subsequences of x1, x2, ... xk (possibly, he didn't write anything) on a piece of paper. Here a sequence b is a subsequence of sequence a if and only if we can turn a into b by removing some of its elements (maybe no one of them or all). After Tavas woke up, Malekas told him everything. He couldn't remember string s, but he knew that both p and s only contains lowercase English letters and also he had the subsequence he had written on that piece of paper. Tavas wonders, what is the number of possible values of s? He asked SaDDas, but he wasn't smart enough to solve this. So, Tavas asked you to calculate this number for him. Answer can be very large, so Tavas wants you to print the answer modulo 109 + 7. Input The first line contains two integers n and m, the length of s and the length of the subsequence Malekas wrote down (1 ≀ n ≀ 106 and 0 ≀ m ≀ n - |p| + 1). The second line contains string p (1 ≀ |p| ≀ n). The next line contains m space separated integers y1, y2, ..., ym, Malekas' subsequence (1 ≀ y1 < y2 < ... < ym ≀ n - |p| + 1). Output In a single line print the answer modulo 1000 000 007. Examples Input 6 2 ioi 1 3 Output 26 Input 5 2 ioi 1 2 Output 0 Note In the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy. Here |x| denotes the length of string x. Please note that it's possible that there is no such string (answer is 0).
instruction
0
16,379
0
32,758
Tags: greedy, hashing, string suffix structures, strings Correct Solution: ``` # -*- coding: utf-8 -*- def solve(): n, m = map(int, input().split()) p = input() if m == 0: return powmod(n) delta = len(p) - 1 ys = map(int, input().split()) tail = 0 free_chars = 0 for y in ys: if y > tail: free_chars += y - tail - 1 elif not is_consistent(p, tail - y + 1): return 0 tail = y + delta free_chars += n - tail return powmod(free_chars) ok_set = set() def is_consistent(p, margin): global ok_set if margin in ok_set: return True elif p[:margin] == p[-margin:]: ok_set.add(margin) return True else: return False def powmod(p): mod = 10**9 + 7 pbin = bin(p)[2:][-1::-1] result = 26 if pbin[0] == '1' else 1 tmp = 26 for bit in pbin[1:]: tmp *= tmp tmp %= mod if bit == '1': result *= tmp result %= mod return result print(solve()) ```
output
1
16,379
0
32,759
Provide tags and a correct Python 3 solution for this coding contest problem. Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. <image> Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions x1 < x2 < ... < xk where p matches s. More formally, for each xi (1 ≀ i ≀ k) he condition sxisxi + 1... sxi + |p| - 1 = p is fullfilled. Then Malekas wrote down one of subsequences of x1, x2, ... xk (possibly, he didn't write anything) on a piece of paper. Here a sequence b is a subsequence of sequence a if and only if we can turn a into b by removing some of its elements (maybe no one of them or all). After Tavas woke up, Malekas told him everything. He couldn't remember string s, but he knew that both p and s only contains lowercase English letters and also he had the subsequence he had written on that piece of paper. Tavas wonders, what is the number of possible values of s? He asked SaDDas, but he wasn't smart enough to solve this. So, Tavas asked you to calculate this number for him. Answer can be very large, so Tavas wants you to print the answer modulo 109 + 7. Input The first line contains two integers n and m, the length of s and the length of the subsequence Malekas wrote down (1 ≀ n ≀ 106 and 0 ≀ m ≀ n - |p| + 1). The second line contains string p (1 ≀ |p| ≀ n). The next line contains m space separated integers y1, y2, ..., ym, Malekas' subsequence (1 ≀ y1 < y2 < ... < ym ≀ n - |p| + 1). Output In a single line print the answer modulo 1000 000 007. Examples Input 6 2 ioi 1 3 Output 26 Input 5 2 ioi 1 2 Output 0 Note In the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy. Here |x| denotes the length of string x. Please note that it's possible that there is no such string (answer is 0).
instruction
0
16,380
0
32,760
Tags: greedy, hashing, string suffix structures, strings Correct Solution: ``` import sys def prefix(s): m = len(s) v = [0]*len(s) for i in range(1,len(s)): k = v[i-1] while k > 0 and s[k] != s[i]: k = v[k-1] if s[k] == s[i]: k = k + 1 v[i] = k w = set() i = m-1 while v[i] != 0: w.add(m-v[i]) i = v[i]-1 return w n,m = map(int, input().split()) if m == 0: print(pow(26, n, 1000000007)) sys.exit(0) p = input() l = len(p) x = list(map(int,input().split())) w = prefix(p) busy = l for i in range(1,m): if x[i]-x[i-1] < l and (x[i] - x[i-1]) not in w: print(0) sys.exit(0) busy += min(x[i]-x[i-1], l) print(pow(26,n-busy, 1000000007)) ```
output
1
16,380
0
32,761
Provide tags and a correct Python 3 solution for this coding contest problem. Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. <image> Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions x1 < x2 < ... < xk where p matches s. More formally, for each xi (1 ≀ i ≀ k) he condition sxisxi + 1... sxi + |p| - 1 = p is fullfilled. Then Malekas wrote down one of subsequences of x1, x2, ... xk (possibly, he didn't write anything) on a piece of paper. Here a sequence b is a subsequence of sequence a if and only if we can turn a into b by removing some of its elements (maybe no one of them or all). After Tavas woke up, Malekas told him everything. He couldn't remember string s, but he knew that both p and s only contains lowercase English letters and also he had the subsequence he had written on that piece of paper. Tavas wonders, what is the number of possible values of s? He asked SaDDas, but he wasn't smart enough to solve this. So, Tavas asked you to calculate this number for him. Answer can be very large, so Tavas wants you to print the answer modulo 109 + 7. Input The first line contains two integers n and m, the length of s and the length of the subsequence Malekas wrote down (1 ≀ n ≀ 106 and 0 ≀ m ≀ n - |p| + 1). The second line contains string p (1 ≀ |p| ≀ n). The next line contains m space separated integers y1, y2, ..., ym, Malekas' subsequence (1 ≀ y1 < y2 < ... < ym ≀ n - |p| + 1). Output In a single line print the answer modulo 1000 000 007. Examples Input 6 2 ioi 1 3 Output 26 Input 5 2 ioi 1 2 Output 0 Note In the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy. Here |x| denotes the length of string x. Please note that it's possible that there is no such string (answer is 0).
instruction
0
16,381
0
32,762
Tags: greedy, hashing, string suffix structures, strings Correct Solution: ``` def preZ(s): #preprocessing by Z algo n = len(s) z = [0]*n z[0] = n r = 0 if n==1: return z while r+1<n and s[r]==s[r+1]: r+=1 z[1] = r #note z=length! not 0-indexed l = 1 if r>0 else 0 for k in range(2,n): bl = r+1-k #|\beta| gl = z[k-l] #|\gamma| if gl<bl: z[k]=z[k-l] #Case2a else: j=max(0,r-k+1) #Case1 & 2b while k+j<n and s[j]==s[k+j]: j+=1 z[k]=j l,r =k,k+j-1 return z pp = int(1e9)+7 def binpow(b,e): r = 1 while True: if e &1: r=(r*b)%pp e = e>>1 if e==0: break b = (b*b)%pp return r def f(p,l,n): #pattern, match list, size of text m = len(p) if len(l)==0: return binpow(26,n) z = preZ(p) s = set([i for i in range(m) if z[i]+i==m]) fc = l[0]-1 for i in range(1,len(l)): r = l[i-1]+m if l[i]>r: fc += l[i]-r continue if l[i]<r and l[i]-l[i-1] not in s: return 0 fc += n-(l[-1]+m-1) return binpow(26,fc) n,m = list(map(int,input().split())) p = input() l = list(map(int,input().split())) if m>0 else [] print(f(p,l,n)) ```
output
1
16,381
0
32,763
Provide tags and a correct Python 3 solution for this coding contest problem. Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. <image> Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions x1 < x2 < ... < xk where p matches s. More formally, for each xi (1 ≀ i ≀ k) he condition sxisxi + 1... sxi + |p| - 1 = p is fullfilled. Then Malekas wrote down one of subsequences of x1, x2, ... xk (possibly, he didn't write anything) on a piece of paper. Here a sequence b is a subsequence of sequence a if and only if we can turn a into b by removing some of its elements (maybe no one of them or all). After Tavas woke up, Malekas told him everything. He couldn't remember string s, but he knew that both p and s only contains lowercase English letters and also he had the subsequence he had written on that piece of paper. Tavas wonders, what is the number of possible values of s? He asked SaDDas, but he wasn't smart enough to solve this. So, Tavas asked you to calculate this number for him. Answer can be very large, so Tavas wants you to print the answer modulo 109 + 7. Input The first line contains two integers n and m, the length of s and the length of the subsequence Malekas wrote down (1 ≀ n ≀ 106 and 0 ≀ m ≀ n - |p| + 1). The second line contains string p (1 ≀ |p| ≀ n). The next line contains m space separated integers y1, y2, ..., ym, Malekas' subsequence (1 ≀ y1 < y2 < ... < ym ≀ n - |p| + 1). Output In a single line print the answer modulo 1000 000 007. Examples Input 6 2 ioi 1 3 Output 26 Input 5 2 ioi 1 2 Output 0 Note In the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy. Here |x| denotes the length of string x. Please note that it's possible that there is no such string (answer is 0).
instruction
0
16,382
0
32,764
Tags: greedy, hashing, string suffix structures, strings Correct Solution: ``` # -*- coding: utf-8 -*- def solve(): n, m = map(int, input().split()) p = input() if m == 0: return powmod(n) delta = len(p) - 1 ys = map(int, input().split()) tail = 0 free_chars = 0 for y in ys: if y > tail: free_chars += y - tail - 1 elif not is_consistent(p, tail - y + 1): return 0 tail = y + delta free_chars += n - tail return powmod(free_chars) ok_set = set() def is_consistent(p, margin): global ok_set if margin in ok_set: return True elif p[:margin] == p[-margin:]: ok_set.add(margin) return True else: return False def powmod(p): mod = 10**9 + 7 pbin = bin(p)[2:][-1::-1] result = 26 if pbin[0] == '1' else 1 tmp = 26 for bit in pbin[1:]: tmp *= tmp tmp %= mod if bit == '1': result *= tmp result %= mod return result print(solve()) # Made By Mostafa_Khaled ```
output
1
16,382
0
32,765
Provide tags and a correct Python 3 solution for this coding contest problem. Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. <image> Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions x1 < x2 < ... < xk where p matches s. More formally, for each xi (1 ≀ i ≀ k) he condition sxisxi + 1... sxi + |p| - 1 = p is fullfilled. Then Malekas wrote down one of subsequences of x1, x2, ... xk (possibly, he didn't write anything) on a piece of paper. Here a sequence b is a subsequence of sequence a if and only if we can turn a into b by removing some of its elements (maybe no one of them or all). After Tavas woke up, Malekas told him everything. He couldn't remember string s, but he knew that both p and s only contains lowercase English letters and also he had the subsequence he had written on that piece of paper. Tavas wonders, what is the number of possible values of s? He asked SaDDas, but he wasn't smart enough to solve this. So, Tavas asked you to calculate this number for him. Answer can be very large, so Tavas wants you to print the answer modulo 109 + 7. Input The first line contains two integers n and m, the length of s and the length of the subsequence Malekas wrote down (1 ≀ n ≀ 106 and 0 ≀ m ≀ n - |p| + 1). The second line contains string p (1 ≀ |p| ≀ n). The next line contains m space separated integers y1, y2, ..., ym, Malekas' subsequence (1 ≀ y1 < y2 < ... < ym ≀ n - |p| + 1). Output In a single line print the answer modulo 1000 000 007. Examples Input 6 2 ioi 1 3 Output 26 Input 5 2 ioi 1 2 Output 0 Note In the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy. Here |x| denotes the length of string x. Please note that it's possible that there is no such string (answer is 0).
instruction
0
16,383
0
32,766
Tags: greedy, hashing, string suffix structures, 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,defaultdict import math #for _ in range(int(input())): #n=int(input()) def matching(s): le = len(s) pi=[0]*le for i in range(1,le): j=pi[i-1] while j>0 and s[i]!=s[j]: j=pi[j-1] if(s[i]==s[j]): j+=1 pi[i]=j #return pi ## to return list of values w=set() i=le-1 while pi[i]!=0: w.add(le-pi[i]) i=pi[i]-1 return w n,m=map(int,input().split()) p=input() if m==0: print(pow(26,n,10**9+7)) sys.exit() arr=list(map(int, input().split())) #a1=list(map(int, input().split())) ans=0 l=len(p) pre=matching(p) filled=l for i in range(1,m): if (arr[i]-arr[i-1]<l and (arr[i]-arr[i-1]) not in pre): print(0) sys.exit() filled+=min(l,arr[i]-arr[i-1]) print(pow(26,n-filled,10**9+7)) ```
output
1
16,383
0
32,767
Provide tags and a correct Python 3 solution for this coding contest problem. Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. <image> Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions x1 < x2 < ... < xk where p matches s. More formally, for each xi (1 ≀ i ≀ k) he condition sxisxi + 1... sxi + |p| - 1 = p is fullfilled. Then Malekas wrote down one of subsequences of x1, x2, ... xk (possibly, he didn't write anything) on a piece of paper. Here a sequence b is a subsequence of sequence a if and only if we can turn a into b by removing some of its elements (maybe no one of them or all). After Tavas woke up, Malekas told him everything. He couldn't remember string s, but he knew that both p and s only contains lowercase English letters and also he had the subsequence he had written on that piece of paper. Tavas wonders, what is the number of possible values of s? He asked SaDDas, but he wasn't smart enough to solve this. So, Tavas asked you to calculate this number for him. Answer can be very large, so Tavas wants you to print the answer modulo 109 + 7. Input The first line contains two integers n and m, the length of s and the length of the subsequence Malekas wrote down (1 ≀ n ≀ 106 and 0 ≀ m ≀ n - |p| + 1). The second line contains string p (1 ≀ |p| ≀ n). The next line contains m space separated integers y1, y2, ..., ym, Malekas' subsequence (1 ≀ y1 < y2 < ... < ym ≀ n - |p| + 1). Output In a single line print the answer modulo 1000 000 007. Examples Input 6 2 ioi 1 3 Output 26 Input 5 2 ioi 1 2 Output 0 Note In the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy. Here |x| denotes the length of string x. Please note that it's possible that there is no such string (answer is 0).
instruction
0
16,384
0
32,768
Tags: greedy, hashing, string suffix structures, strings Correct Solution: ``` # -*- coding: utf-8 -*- def solve(): mod = 10**9 + 7 n, m = map(int, input().split()) p = input() if m == 0: return powmod(n) delta = len(p) - 1 ys = map(int, input().split()) answer = 1 tail = 0 for y in ys: if y > tail: answer *= powmod(y - tail - 1) answer %= mod elif not is_consistent(p, tail - y + 1): return 0 tail = y + delta answer *= powmod(n - tail) return answer % mod ok_set = set() def is_consistent(p, margin): global ok_set if margin in ok_set: return True elif p[:margin] == p[-margin:]: ok_set.add(margin) return True else: return False def powmod(p): mod = 10**9 + 7 pbin = bin(p)[2:][-1::-1] result = 26 if pbin[0] == '1' else 1 tmp = 26 for bit in pbin[1:]: tmp *= tmp tmp %= mod if bit == '1': result *= tmp result %= mod return result print(solve()) ```
output
1
16,384
0
32,769
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. <image> Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions x1 < x2 < ... < xk where p matches s. More formally, for each xi (1 ≀ i ≀ k) he condition sxisxi + 1... sxi + |p| - 1 = p is fullfilled. Then Malekas wrote down one of subsequences of x1, x2, ... xk (possibly, he didn't write anything) on a piece of paper. Here a sequence b is a subsequence of sequence a if and only if we can turn a into b by removing some of its elements (maybe no one of them or all). After Tavas woke up, Malekas told him everything. He couldn't remember string s, but he knew that both p and s only contains lowercase English letters and also he had the subsequence he had written on that piece of paper. Tavas wonders, what is the number of possible values of s? He asked SaDDas, but he wasn't smart enough to solve this. So, Tavas asked you to calculate this number for him. Answer can be very large, so Tavas wants you to print the answer modulo 109 + 7. Input The first line contains two integers n and m, the length of s and the length of the subsequence Malekas wrote down (1 ≀ n ≀ 106 and 0 ≀ m ≀ n - |p| + 1). The second line contains string p (1 ≀ |p| ≀ n). The next line contains m space separated integers y1, y2, ..., ym, Malekas' subsequence (1 ≀ y1 < y2 < ... < ym ≀ n - |p| + 1). Output In a single line print the answer modulo 1000 000 007. Examples Input 6 2 ioi 1 3 Output 26 Input 5 2 ioi 1 2 Output 0 Note In the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy. Here |x| denotes the length of string x. Please note that it's possible that there is no such string (answer is 0). Submitted Solution: ``` import sys n, m = map(int, str(input()).split(" ")) p = str(input()) l = map(int, str(input()).split(" ")) s = " "*n st = list(s) for i in l: j = i-1 if(len(s) < j+len(p)): print(0) sys.exit(0) for c in p: if st[j] == " ": st[j] = c elif st[j] == c: pass else: print(0) sys.exit(0) j+=1 product = 1 for i in st: if i == " ": product*=26 print(product) ```
instruction
0
16,385
0
32,770
No
output
1
16,385
0
32,771
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. <image> Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions x1 < x2 < ... < xk where p matches s. More formally, for each xi (1 ≀ i ≀ k) he condition sxisxi + 1... sxi + |p| - 1 = p is fullfilled. Then Malekas wrote down one of subsequences of x1, x2, ... xk (possibly, he didn't write anything) on a piece of paper. Here a sequence b is a subsequence of sequence a if and only if we can turn a into b by removing some of its elements (maybe no one of them or all). After Tavas woke up, Malekas told him everything. He couldn't remember string s, but he knew that both p and s only contains lowercase English letters and also he had the subsequence he had written on that piece of paper. Tavas wonders, what is the number of possible values of s? He asked SaDDas, but he wasn't smart enough to solve this. So, Tavas asked you to calculate this number for him. Answer can be very large, so Tavas wants you to print the answer modulo 109 + 7. Input The first line contains two integers n and m, the length of s and the length of the subsequence Malekas wrote down (1 ≀ n ≀ 106 and 0 ≀ m ≀ n - |p| + 1). The second line contains string p (1 ≀ |p| ≀ n). The next line contains m space separated integers y1, y2, ..., ym, Malekas' subsequence (1 ≀ y1 < y2 < ... < ym ≀ n - |p| + 1). Output In a single line print the answer modulo 1000 000 007. Examples Input 6 2 ioi 1 3 Output 26 Input 5 2 ioi 1 2 Output 0 Note In the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy. Here |x| denotes the length of string x. Please note that it's possible that there is no such string (answer is 0). Submitted Solution: ``` import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ########################################################## from collections import Counter,defaultdict import math #for _ in range(int(input())): #n=int(input()) def matching(s): le = len(s) pi=[0]*le for i in range(1,le): j=pi[i-1] while j>0 and s[i]!=s[j]: j=pi[j-1] if(s[i]==s[j]): j+=1 pi[i]=j #return pi ## to return list of values w=set() i=le-1 while pi[i]!=0: w.add(le-pi[i]) i=pi[i]-1 return w n,m=map(int,input().split()) p=input() arr=list(map(int, input().split())) #a1=list(map(int, input().split())) ans=0 l=len(p) pre=matching(p) filled=l for i in range(1,m): if (arr[i]-arr[i-1]<l and (arr[i]-arr[i-1]) not in pre): print(0) sys.exit() filled+=min(l,arr[i]-arr[i-1]) print(pow(26,n-filled,10**9+7)) ```
instruction
0
16,386
0
32,772
No
output
1
16,386
0
32,773
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. <image> Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions x1 < x2 < ... < xk where p matches s. More formally, for each xi (1 ≀ i ≀ k) he condition sxisxi + 1... sxi + |p| - 1 = p is fullfilled. Then Malekas wrote down one of subsequences of x1, x2, ... xk (possibly, he didn't write anything) on a piece of paper. Here a sequence b is a subsequence of sequence a if and only if we can turn a into b by removing some of its elements (maybe no one of them or all). After Tavas woke up, Malekas told him everything. He couldn't remember string s, but he knew that both p and s only contains lowercase English letters and also he had the subsequence he had written on that piece of paper. Tavas wonders, what is the number of possible values of s? He asked SaDDas, but he wasn't smart enough to solve this. So, Tavas asked you to calculate this number for him. Answer can be very large, so Tavas wants you to print the answer modulo 109 + 7. Input The first line contains two integers n and m, the length of s and the length of the subsequence Malekas wrote down (1 ≀ n ≀ 106 and 0 ≀ m ≀ n - |p| + 1). The second line contains string p (1 ≀ |p| ≀ n). The next line contains m space separated integers y1, y2, ..., ym, Malekas' subsequence (1 ≀ y1 < y2 < ... < ym ≀ n - |p| + 1). Output In a single line print the answer modulo 1000 000 007. Examples Input 6 2 ioi 1 3 Output 26 Input 5 2 ioi 1 2 Output 0 Note In the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy. Here |x| denotes the length of string x. Please note that it's possible that there is no such string (answer is 0). Submitted Solution: ``` class CodeforcesTask536BSolution: def __init__(self): self.result = '' self.n_m = [] self.p = '' self.y = [] def read_input(self): self.n_m = [int(x) for x in input().split(" ")] self.p = input() self.y = [int(x) for x in input().split(" ")] def process_task(self): if self.p == self.p[0] * len(self.p): go = [1] * self.n_m[0] for y in self.y: go = go[:y] + [0] * len(self.p) + go[y + len(self.p):] result = 1 non_zero = sum(go) d = 1000000007 for i in range(non_zero): result = result * 26 % d self.result = str(result) else: projection = {} for x in range(self.n_m[0]): projection[x] = "?" canbe = True for y in self.y: for x in range(len(self.p)): if y + x <= self.n_m[0]: c = projection[y + x - 1] if c == "?": projection[y + x - 1] = self.p[x] elif c != self.p[x]: canbe = False break else: canbe = False break if not canbe: break if not canbe: self.result = "0" else: non_zero = 0 for x in range(self.n_m[0]): if projection[x] == "?": non_zero += 1 result = 1 d = 1000000007 for i in range(non_zero): result = result * 26 % d self.result = str(result) def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask536BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
instruction
0
16,387
0
32,774
No
output
1
16,387
0
32,775
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. <image> Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions x1 < x2 < ... < xk where p matches s. More formally, for each xi (1 ≀ i ≀ k) he condition sxisxi + 1... sxi + |p| - 1 = p is fullfilled. Then Malekas wrote down one of subsequences of x1, x2, ... xk (possibly, he didn't write anything) on a piece of paper. Here a sequence b is a subsequence of sequence a if and only if we can turn a into b by removing some of its elements (maybe no one of them or all). After Tavas woke up, Malekas told him everything. He couldn't remember string s, but he knew that both p and s only contains lowercase English letters and also he had the subsequence he had written on that piece of paper. Tavas wonders, what is the number of possible values of s? He asked SaDDas, but he wasn't smart enough to solve this. So, Tavas asked you to calculate this number for him. Answer can be very large, so Tavas wants you to print the answer modulo 109 + 7. Input The first line contains two integers n and m, the length of s and the length of the subsequence Malekas wrote down (1 ≀ n ≀ 106 and 0 ≀ m ≀ n - |p| + 1). The second line contains string p (1 ≀ |p| ≀ n). The next line contains m space separated integers y1, y2, ..., ym, Malekas' subsequence (1 ≀ y1 < y2 < ... < ym ≀ n - |p| + 1). Output In a single line print the answer modulo 1000 000 007. Examples Input 6 2 ioi 1 3 Output 26 Input 5 2 ioi 1 2 Output 0 Note In the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy. Here |x| denotes the length of string x. Please note that it's possible that there is no such string (answer is 0). Submitted Solution: ``` import sys def prefix(s): m = len(s) v = [0]*len(s) for i in range(1,len(s)): k = v[i-1] while k > 0 and s[k] != s[i]: k = v[k-1] if s[k] == s[i]: k = k + 1 v[i] = k w = set() i = m-1 while v[i] != 0: w.add(m-v[i]) i = v[i]-1 return w n,m = map(int, input().split()) p = input() l = len(p) x = list(map(int,input().split())) w = prefix(p) busy = l for i in range(1,m): if x[i]-x[i-1] <= l and (x[i] - x[i-1]) not in w: print(0) sys.exit(0) busy += min(x[i]-x[i-1], l) print(pow(26,n-busy, 1000000007)) ```
instruction
0
16,388
0
32,776
No
output
1
16,388
0
32,777
Provide a correct Python 3 solution for this coding contest problem. We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly: * Insert a letter `x` to any position in s of his choice, including the beginning and end of s. Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required. Constraints * 1 \leq |s| \leq 10^5 * s consists of lowercase English letters. Input Input is given from Standard Input in the following format: s Output If the objective is achievable, print the number of operations required. If it is not, print `-1` instead. Examples Input xabxa Output 2 Input ab Output -1 Input a Output 0 Input oxxx Output 3
instruction
0
16,664
0
33,328
"Correct Solution: ``` s = input() t= "".join(c for c in s if c!="x") if t!=t[::-1]: print(-1) else: ans=0 i=0 j=0 l=len(s) while i+j<l-1: if s[i] != s[l-1-j]: ans+=1 if s[i] == "x" : i+=1 else : j+=1 else: i+=1 j+=1 print(ans) ```
output
1
16,664
0
33,329
Provide a correct Python 3 solution for this coding contest problem. We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly: * Insert a letter `x` to any position in s of his choice, including the beginning and end of s. Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required. Constraints * 1 \leq |s| \leq 10^5 * s consists of lowercase English letters. Input Input is given from Standard Input in the following format: s Output If the objective is achievable, print the number of operations required. If it is not, print `-1` instead. Examples Input xabxa Output 2 Input ab Output -1 Input a Output 0 Input oxxx Output 3
instruction
0
16,669
0
33,338
"Correct Solution: ``` s=input() S="a"+s[::]+"a" s=s.replace("x","") if s[:len(s)//2]!=s[:-(len(s)//2)-1:-1]: print(-1) quit() r=0 l=len(S)-1 ans=0 while r<l: R,L=0,0 while S[r+R]=="x": R+=1 while S[l-L]=="x": L+=1 ans+=abs(R-L) r+=R+1 l-=L+1 print(ans) ```
output
1
16,669
0
33,339
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan wants to play a game with you. He picked some string s of length n consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from 1 to n-1), but he didn't tell you which strings are prefixes and which are suffixes. Ivan wants you to guess which of the given 2n-2 strings are prefixes of the given string and which are suffixes. It may be impossible to guess the string Ivan picked (since multiple strings may give the same set of suffixes and prefixes), but Ivan will accept your answer if there is at least one string that is consistent with it. Let the game begin! Input The first line of the input contains one integer number n (2 ≀ n ≀ 100) β€” the length of the guessed string s. The next 2n-2 lines are contain prefixes and suffixes, one per line. Each of them is the string of length from 1 to n-1 consisting only of lowercase Latin letters. They can be given in arbitrary order. It is guaranteed that there are exactly 2 strings of each length from 1 to n-1. It is also guaranteed that these strings are prefixes and suffixes of some existing string of length n. Output Print one string of length 2n-2 β€” the string consisting only of characters 'P' and 'S'. The number of characters 'P' should be equal to the number of characters 'S'. The i-th character of this string should be 'P' if the i-th of the input strings is the prefix and 'S' otherwise. If there are several possible answers, you can print any. Examples Input 5 ba a abab a aba baba ab aba Output SPPSPSPS Input 3 a aa aa a Output PPSS Input 2 a c Output PS Note The only string which Ivan can guess in the first example is "ababa". The only string which Ivan can guess in the second example is "aaa". Answers "SPSP", "SSPP" and "PSPS" are also acceptable. In the third example Ivan can guess the string "ac" or the string "ca". The answer "SP" is also acceptable.
instruction
0
16,863
0
33,726
Tags: strings Correct Solution: ``` def solve(e): g=[0 for i in range(2*n-2)] check=[0 for i in range(2*n-2)] for i in range(n): f=e[0:i+1] for j in range(2*n-2): if(a[j]==f and check[j]==0): g[j]=1 check[j]=1 break for i in range(2*n-2): if(g[i]==1): print("P",end="") else: print("S",end="") n=int(input()) a=[] for i in range(2*n-2): b=input() a.append(b) if(n==2):print("PS") else: c=[] d=[] for i in range(2*n-2): if(len(a[i])==1): c.append(a[i]) elif(len(a[i])==n-1): d.append(a[i]) e1=c[0]+d[0] b1=[] for i in range(len(e1)-1): f=e1[0:i+1] g=e1[i+1:n] b1.append(f) b1.append(g) e2=c[0]+d[1] b2=[] for i in range(len(e2)-1): f=e2[0:i+1] g=e2[i+1:n] b2.append(f) b2.append(g) e3=c[1]+d[1] b3=[] for i in range(len(e3)-1): f=e3[0:i+1] g=e3[i+1:n] b3.append(f) b3.append(g) e4=c[1]+d[0] b4=[] for i in range(len(e4)-1): f=e4[0:i+1] g=e4[i+1:n] b4.append(f) b4.append(g) e5=d[0]+c[0] b5=[] for i in range(len(e5)-1): f=e5[0:i+1] g=e5[i+1:n] b5.append(f) b5.append(g) e6=d[0]+c[1] b6=[] for i in range(len(e6)-1): f=e6[0:i+1] g=e6[i+1:n] b6.append(f) b6.append(g) e7=d[1]+c[1] b7=[] for i in range(len(e7)-1): f=e7[0:i+1] g=e7[i+1:n] b7.append(f) b7.append(g) e8=d[1]+c[0] b8=[] for i in range(len(e8)-1): f=e8[0:i+1] g=e8[i+1:n] b8.append(f) b8.append(g) c1=[] for i in range(2*n-2): c1.append(a[i]) c1.sort() b1.sort() b2.sort() b3.sort() b4.sort() b5.sort() b6.sort() b7.sort() b8.sort() if(c1==b1): #print(b1) solve(e1) elif(c1==b2): #print(b2) solve(e2) elif(c1==b3): #print(b3) solve(e3) elif(c1==b4): #print(b4) solve(e4) elif(c1==b5): #print(b5) solve(e5) elif(c1==b6): #print(b6) solve(e6) elif(c1==b7): #print(b7) solve(e7) else: #print("#",b8) solve(e8) ```
output
1
16,863
0
33,727
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan wants to play a game with you. He picked some string s of length n consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from 1 to n-1), but he didn't tell you which strings are prefixes and which are suffixes. Ivan wants you to guess which of the given 2n-2 strings are prefixes of the given string and which are suffixes. It may be impossible to guess the string Ivan picked (since multiple strings may give the same set of suffixes and prefixes), but Ivan will accept your answer if there is at least one string that is consistent with it. Let the game begin! Input The first line of the input contains one integer number n (2 ≀ n ≀ 100) β€” the length of the guessed string s. The next 2n-2 lines are contain prefixes and suffixes, one per line. Each of them is the string of length from 1 to n-1 consisting only of lowercase Latin letters. They can be given in arbitrary order. It is guaranteed that there are exactly 2 strings of each length from 1 to n-1. It is also guaranteed that these strings are prefixes and suffixes of some existing string of length n. Output Print one string of length 2n-2 β€” the string consisting only of characters 'P' and 'S'. The number of characters 'P' should be equal to the number of characters 'S'. The i-th character of this string should be 'P' if the i-th of the input strings is the prefix and 'S' otherwise. If there are several possible answers, you can print any. Examples Input 5 ba a abab a aba baba ab aba Output SPPSPSPS Input 3 a aa aa a Output PPSS Input 2 a c Output PS Note The only string which Ivan can guess in the first example is "ababa". The only string which Ivan can guess in the second example is "aaa". Answers "SPSP", "SSPP" and "PSPS" are also acceptable. In the third example Ivan can guess the string "ac" or the string "ca". The answer "SP" is also acceptable.
instruction
0
16,864
0
33,728
Tags: strings Correct Solution: ``` n = int(input()) a = [] for i in range(2*n-2): a.append(input()) S = '' P = '' Lnm1 = [] Lnm2 = [] ans = [] for i in a: if len(i) == n-1: Lnm1.append(i) elif len(i) == n-2: Lnm2.append(i) flag = 0 if n == 2: print("PS") elif n == 1: print("P") else: S = Lnm2[0] P = Lnm2[1] if (Lnm2[0] == Lnm1[0][:n-2] and Lnm2[1] == Lnm1[1][1:]): S = Lnm1[0] P = Lnm1[1] elif (Lnm2[1] == Lnm1[0][:n-2] and Lnm2[0] == Lnm1[1][1:]): S = Lnm1[0] P = Lnm1[1] else: S = Lnm1[1] P = Lnm1[0] flag = [0 for i in range(n)] for i in a: if flag[len(i)] == 0: if len(i) <= len(P): if i == S[:len(i)]: ans.append("P") flag[len(i)] = 'S' else: ans.append('S') flag[len(i)] = 'P' else: ans.append(flag[len(i)]) print(*ans, sep = "") ```
output
1
16,864
0
33,729
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan wants to play a game with you. He picked some string s of length n consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from 1 to n-1), but he didn't tell you which strings are prefixes and which are suffixes. Ivan wants you to guess which of the given 2n-2 strings are prefixes of the given string and which are suffixes. It may be impossible to guess the string Ivan picked (since multiple strings may give the same set of suffixes and prefixes), but Ivan will accept your answer if there is at least one string that is consistent with it. Let the game begin! Input The first line of the input contains one integer number n (2 ≀ n ≀ 100) β€” the length of the guessed string s. The next 2n-2 lines are contain prefixes and suffixes, one per line. Each of them is the string of length from 1 to n-1 consisting only of lowercase Latin letters. They can be given in arbitrary order. It is guaranteed that there are exactly 2 strings of each length from 1 to n-1. It is also guaranteed that these strings are prefixes and suffixes of some existing string of length n. Output Print one string of length 2n-2 β€” the string consisting only of characters 'P' and 'S'. The number of characters 'P' should be equal to the number of characters 'S'. The i-th character of this string should be 'P' if the i-th of the input strings is the prefix and 'S' otherwise. If there are several possible answers, you can print any. Examples Input 5 ba a abab a aba baba ab aba Output SPPSPSPS Input 3 a aa aa a Output PPSS Input 2 a c Output PS Note The only string which Ivan can guess in the first example is "ababa". The only string which Ivan can guess in the second example is "aaa". Answers "SPSP", "SSPP" and "PSPS" are also acceptable. In the third example Ivan can guess the string "ac" or the string "ca". The answer "SP" is also acceptable.
instruction
0
16,865
0
33,730
Tags: strings Correct Solution: ``` n=int(input()) k=2*n-2 a=[] b=[] c=[] for i in range(k): s=input() a.append(s) c.append(s) a.sort() for i in range(k): if(len(a[i])==n-1): b.append(a[i]) s1=b[0][1:n-1] s2=b[1][0:n-2] if(s1==s2): x=b[0][0] p=b[0] su=b[1] else: x=b[1][0] p=b[1] su=b[0] cnt=[1]*n p1=0; res=[] rest=[] for i in range(k): l=len(c[i]) if(cnt[l]==1 and c[i]==p[0:l]): cnt[l]=0 res.append("P") p1+=1 else: cnt[l]=1 res.append("S") if(p1==n-1): print("".join(res)) else: cnt=[1]*n for i in range(k): l=len(c[i]) if(cnt[l]==1 and c[i]==su[0:l]): cnt[l]=0 rest.append("P") p1+=1 else: cnt[l]=1 rest.append("S") print("".join(rest)) ```
output
1
16,865
0
33,731
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan wants to play a game with you. He picked some string s of length n consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from 1 to n-1), but he didn't tell you which strings are prefixes and which are suffixes. Ivan wants you to guess which of the given 2n-2 strings are prefixes of the given string and which are suffixes. It may be impossible to guess the string Ivan picked (since multiple strings may give the same set of suffixes and prefixes), but Ivan will accept your answer if there is at least one string that is consistent with it. Let the game begin! Input The first line of the input contains one integer number n (2 ≀ n ≀ 100) β€” the length of the guessed string s. The next 2n-2 lines are contain prefixes and suffixes, one per line. Each of them is the string of length from 1 to n-1 consisting only of lowercase Latin letters. They can be given in arbitrary order. It is guaranteed that there are exactly 2 strings of each length from 1 to n-1. It is also guaranteed that these strings are prefixes and suffixes of some existing string of length n. Output Print one string of length 2n-2 β€” the string consisting only of characters 'P' and 'S'. The number of characters 'P' should be equal to the number of characters 'S'. The i-th character of this string should be 'P' if the i-th of the input strings is the prefix and 'S' otherwise. If there are several possible answers, you can print any. Examples Input 5 ba a abab a aba baba ab aba Output SPPSPSPS Input 3 a aa aa a Output PPSS Input 2 a c Output PS Note The only string which Ivan can guess in the first example is "ababa". The only string which Ivan can guess in the second example is "aaa". Answers "SPSP", "SSPP" and "PSPS" are also acceptable. In the third example Ivan can guess the string "ac" or the string "ca". The answer "SP" is also acceptable.
instruction
0
16,866
0
33,732
Tags: strings Correct Solution: ``` for _ in range(1): n = int(input()) limit = (2*n)-2 ind = {} e = {} d = {} for i in range(1,limit+1): s = input() if len(s) in d: d[len(s)].append(s) else: d[len(s)] = [s] if s in ind: ind[s].append(i) else: ind[s] = [i] if s in e: e[s] += 1 else: e[s] = 1 candidates = [d[n-1][0]+d[1][0],d[n-1][0]+d[1][1],d[n-1][1]+d[1][0],d[n-1][1]+d[1][1],d[1][0]+d[n-1][0],d[1][1]+d[n-1][0],d[1][0]+d[n-1][1],d[1][1]+d[n-1][1]] for i in candidates: te = {} tind = {} # print(i) for j in e: te[j] = e[j] for j in ind: tind[j] = ind[j].copy() flag = 1 ans = ["Z"]*(limit+1) for j in range(n-1): w = i[0:j+1] if w not in tind: flag = 0 break if len(tind[w]) == 0: flag = 0 break ans[tind[w].pop()] = "P" if w in te: te[w] -= 1 if te[w] == 0: del te[w] else: flag = 0 break i = i[::-1] for j in range(n-1): w = i[0:j+1][::-1] if w not in tind: flag = 0 break if len(tind[w]) == 0: flag = 0 break ans[tind[w].pop()] = "S" if w in te: te[w] -= 1 if te[w] == 0: del te[w] else: flag = 0 break if flag: print("".join(ans[1:])) exit() ```
output
1
16,866
0
33,733
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan wants to play a game with you. He picked some string s of length n consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from 1 to n-1), but he didn't tell you which strings are prefixes and which are suffixes. Ivan wants you to guess which of the given 2n-2 strings are prefixes of the given string and which are suffixes. It may be impossible to guess the string Ivan picked (since multiple strings may give the same set of suffixes and prefixes), but Ivan will accept your answer if there is at least one string that is consistent with it. Let the game begin! Input The first line of the input contains one integer number n (2 ≀ n ≀ 100) β€” the length of the guessed string s. The next 2n-2 lines are contain prefixes and suffixes, one per line. Each of them is the string of length from 1 to n-1 consisting only of lowercase Latin letters. They can be given in arbitrary order. It is guaranteed that there are exactly 2 strings of each length from 1 to n-1. It is also guaranteed that these strings are prefixes and suffixes of some existing string of length n. Output Print one string of length 2n-2 β€” the string consisting only of characters 'P' and 'S'. The number of characters 'P' should be equal to the number of characters 'S'. The i-th character of this string should be 'P' if the i-th of the input strings is the prefix and 'S' otherwise. If there are several possible answers, you can print any. Examples Input 5 ba a abab a aba baba ab aba Output SPPSPSPS Input 3 a aa aa a Output PPSS Input 2 a c Output PS Note The only string which Ivan can guess in the first example is "ababa". The only string which Ivan can guess in the second example is "aaa". Answers "SPSP", "SSPP" and "PSPS" are also acceptable. In the third example Ivan can guess the string "ac" or the string "ca". The answer "SP" is also acceptable.
instruction
0
16,867
0
33,734
Tags: strings Correct Solution: ``` n = int(input()) a = [input() for i in range(2*n - 2)] sorted_a = sorted(a, key=len, reverse=True) guess = sorted_a[0] + sorted_a[1][-1] guess2 = sorted_a[1] + sorted_a[0][-1] check = [0]* len(a) for i in range(0,len(a),2): if(not((guess.startswith(sorted_a[i]) and guess.endswith(sorted_a[i+1])) or (guess.startswith(sorted_a[1+i]) and guess.endswith(sorted_a[i])))): guess = guess2 break for word in a: if guess.startswith(word): if check[len(word)] == 0: print('P', end='') check[len(word)] = 1 else: print('S', end='') else: print('S', end='') ```
output
1
16,867
0
33,735
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan wants to play a game with you. He picked some string s of length n consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from 1 to n-1), but he didn't tell you which strings are prefixes and which are suffixes. Ivan wants you to guess which of the given 2n-2 strings are prefixes of the given string and which are suffixes. It may be impossible to guess the string Ivan picked (since multiple strings may give the same set of suffixes and prefixes), but Ivan will accept your answer if there is at least one string that is consistent with it. Let the game begin! Input The first line of the input contains one integer number n (2 ≀ n ≀ 100) β€” the length of the guessed string s. The next 2n-2 lines are contain prefixes and suffixes, one per line. Each of them is the string of length from 1 to n-1 consisting only of lowercase Latin letters. They can be given in arbitrary order. It is guaranteed that there are exactly 2 strings of each length from 1 to n-1. It is also guaranteed that these strings are prefixes and suffixes of some existing string of length n. Output Print one string of length 2n-2 β€” the string consisting only of characters 'P' and 'S'. The number of characters 'P' should be equal to the number of characters 'S'. The i-th character of this string should be 'P' if the i-th of the input strings is the prefix and 'S' otherwise. If there are several possible answers, you can print any. Examples Input 5 ba a abab a aba baba ab aba Output SPPSPSPS Input 3 a aa aa a Output PPSS Input 2 a c Output PS Note The only string which Ivan can guess in the first example is "ababa". The only string which Ivan can guess in the second example is "aaa". Answers "SPSP", "SSPP" and "PSPS" are also acceptable. In the third example Ivan can guess the string "ac" or the string "ca". The answer "SP" is also acceptable.
instruction
0
16,868
0
33,736
Tags: strings Correct Solution: ``` from collections import namedtuple SPos = namedtuple("SPos", "string, pos") n = int(input()) levels = [[] for _ in range(n)] for i in range(2 * n - 2): s = input() levels[len(s)].append(SPos(string=s, pos=i)) checkpoint = 1 for i in range(2, n): # Try to see if anything fits if levels[i][0].string[:-1] == levels[i - 1][0].string and \ levels[i][1].string[1:] == levels[i - 1][1].string: pass elif levels[i][1].string[:-1] == levels[i - 1][0].string and \ levels[i][0].string[1:] == levels[i - 1][1].string: # Swap the order in the case of the current level levels[i][0], levels[i][1] = levels[i][1], levels[i][0] else: # Change the order of everything beneath for j in range(i - 1, checkpoint - 1, -1): if not(levels[j + 1][0].string[:-1] == levels[j][0].string and \ levels[j + 1][1].string[1:] == levels[j][1].string): levels[j][0], levels[j][1] = levels[j][1], levels[j][0] # Recheck the current level if not(levels[i][0].string[:-1] == levels[i - 1][0].string and \ levels[i][1].string[1:] == levels[i - 1][1].string): levels[i][0], levels[i][1] = levels[i][1], levels[i][0] checkpoint = i result = ['' for _ in range(2 * n - 2)] for level in levels[1:]: result[level[0].pos] = 'P' result[level[1].pos] = 'S' print(''.join(result)) ```
output
1
16,868
0
33,737
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan wants to play a game with you. He picked some string s of length n consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from 1 to n-1), but he didn't tell you which strings are prefixes and which are suffixes. Ivan wants you to guess which of the given 2n-2 strings are prefixes of the given string and which are suffixes. It may be impossible to guess the string Ivan picked (since multiple strings may give the same set of suffixes and prefixes), but Ivan will accept your answer if there is at least one string that is consistent with it. Let the game begin! Input The first line of the input contains one integer number n (2 ≀ n ≀ 100) β€” the length of the guessed string s. The next 2n-2 lines are contain prefixes and suffixes, one per line. Each of them is the string of length from 1 to n-1 consisting only of lowercase Latin letters. They can be given in arbitrary order. It is guaranteed that there are exactly 2 strings of each length from 1 to n-1. It is also guaranteed that these strings are prefixes and suffixes of some existing string of length n. Output Print one string of length 2n-2 β€” the string consisting only of characters 'P' and 'S'. The number of characters 'P' should be equal to the number of characters 'S'. The i-th character of this string should be 'P' if the i-th of the input strings is the prefix and 'S' otherwise. If there are several possible answers, you can print any. Examples Input 5 ba a abab a aba baba ab aba Output SPPSPSPS Input 3 a aa aa a Output PPSS Input 2 a c Output PS Note The only string which Ivan can guess in the first example is "ababa". The only string which Ivan can guess in the second example is "aaa". Answers "SPSP", "SSPP" and "PSPS" are also acceptable. In the third example Ivan can guess the string "ac" or the string "ca". The answer "SP" is also acceptable.
instruction
0
16,869
0
33,738
Tags: strings Correct Solution: ``` n = int(input()) a = [] fe = -1 se = -1 for i in range(2*n - 2): s = input() if len(s) == n - 1: if fe == -1: fe = i else: se = i a.append(s) fl = True s = a[fe] + a[se][-1] b = [''] * len(a) pr = [False] * n su = [False] * n for i in range(len(a)): #pr flp = False ss = a[i] if not pr[len(ss) - 1]: if s[:len(ss)] == ss: b[i] = 'P' pr[len(ss) - 1] = True flp = True if not flp: if not su[-len(ss)]: if s[-len(ss):] == ss: b[i] = 'S' su[-len(ss)] = True flp = True if not flp: fl = False break if not fl: s = a[se] + a[fe][-1] pr = [False] * n su = [False] * n for i in range(len(a)): #pr flp = False ss = a[i] if not pr[len(ss) - 1]: if s[:len(ss)] == ss: b[i] = 'P' pr[len(ss) - 1] = True flp = True if not flp: if not su[-len(ss)]: if s[-len(ss):] == ss: b[i] = 'S' su[-len(ss)] = True flp = True for i in b: print(i, end = '') ```
output
1
16,869
0
33,739
Provide tags and a correct Python 3 solution for this coding contest problem. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010" is an unique substring of s, because l = 2 is the only one suitable number. But, for example t = "10" isn't a unique substring of s, because l = 1 and l = 3 are suitable. And for example t ="00" at all isn't a substring of s, because there is no suitable l. Today Vasya solved the following problem at the informatics lesson: given a string consisting of symbols "0" and "1", the task is to find the length of its minimal unique substring. He has written a solution to this problem and wants to test it. He is asking you to help him. You are given 2 positive integers n and k, such that (n mod 2) = (k mod 2), where (x mod 2) is operation of taking remainder of x by dividing on 2. Find any string s consisting of n symbols "0" or "1", such that the length of its minimal unique substring is equal to k. Input The first line contains two integers n and k, separated by spaces (1 ≀ k ≀ n ≀ 100 000, (k mod 2) = (n mod 2)). Output Print a string s of length n, consisting of symbols "0" and "1". Minimal length of the unique substring of s should be equal to k. You can find any suitable string. It is guaranteed, that there exists at least one such string. Examples Input 4 4 Output 1111 Input 5 3 Output 01010 Input 7 3 Output 1011011 Note In the first test, it's easy to see, that the only unique substring of string s = "1111" is all string s, which has length 4. In the second test a string s = "01010" has minimal unique substring t ="101", which has length 3. In the third test a string s = "1011011" has minimal unique substring t ="110", which has length 3.
instruction
0
16,896
0
33,792
Tags: constructive algorithms, math, strings Correct Solution: ``` n, k = [int(x) for x in input().split()] if k == 1: print("1" + "0"*(n-1)) elif 3*k <= n: # print("2") print(("0" * ((n-k)//2)) + "1" + ("0"*(k-2)) + "1" + "0" * ((n-k)//2)) else: tmp = "0" * ((n-k)//2) + "1" s = tmp s = tmp * (n // len(tmp) + 1) s = s[:n] print(s) ```
output
1
16,896
0
33,793
Provide tags and a correct Python 3 solution for this coding contest problem. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010" is an unique substring of s, because l = 2 is the only one suitable number. But, for example t = "10" isn't a unique substring of s, because l = 1 and l = 3 are suitable. And for example t ="00" at all isn't a substring of s, because there is no suitable l. Today Vasya solved the following problem at the informatics lesson: given a string consisting of symbols "0" and "1", the task is to find the length of its minimal unique substring. He has written a solution to this problem and wants to test it. He is asking you to help him. You are given 2 positive integers n and k, such that (n mod 2) = (k mod 2), where (x mod 2) is operation of taking remainder of x by dividing on 2. Find any string s consisting of n symbols "0" or "1", such that the length of its minimal unique substring is equal to k. Input The first line contains two integers n and k, separated by spaces (1 ≀ k ≀ n ≀ 100 000, (k mod 2) = (n mod 2)). Output Print a string s of length n, consisting of symbols "0" and "1". Minimal length of the unique substring of s should be equal to k. You can find any suitable string. It is guaranteed, that there exists at least one such string. Examples Input 4 4 Output 1111 Input 5 3 Output 01010 Input 7 3 Output 1011011 Note In the first test, it's easy to see, that the only unique substring of string s = "1111" is all string s, which has length 4. In the second test a string s = "01010" has minimal unique substring t ="101", which has length 3. In the third test a string s = "1011011" has minimal unique substring t ="110", which has length 3.
instruction
0
16,897
0
33,794
Tags: constructive algorithms, math, strings Correct Solution: ``` N, K = map(int, input().split()) if N == K: print("0"*N) elif K == 1: print("0"*(N-1) + "1") elif K == 3: print("1" + "0"*(N-4) + "101") else: res = ["0"]*N for i in range(0, N, N//2-K//2+1): res[i] = "1" print(''.join(res)) ```
output
1
16,897
0
33,795
Provide tags and a correct Python 3 solution for this coding contest problem. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010" is an unique substring of s, because l = 2 is the only one suitable number. But, for example t = "10" isn't a unique substring of s, because l = 1 and l = 3 are suitable. And for example t ="00" at all isn't a substring of s, because there is no suitable l. Today Vasya solved the following problem at the informatics lesson: given a string consisting of symbols "0" and "1", the task is to find the length of its minimal unique substring. He has written a solution to this problem and wants to test it. He is asking you to help him. You are given 2 positive integers n and k, such that (n mod 2) = (k mod 2), where (x mod 2) is operation of taking remainder of x by dividing on 2. Find any string s consisting of n symbols "0" or "1", such that the length of its minimal unique substring is equal to k. Input The first line contains two integers n and k, separated by spaces (1 ≀ k ≀ n ≀ 100 000, (k mod 2) = (n mod 2)). Output Print a string s of length n, consisting of symbols "0" and "1". Minimal length of the unique substring of s should be equal to k. You can find any suitable string. It is guaranteed, that there exists at least one such string. Examples Input 4 4 Output 1111 Input 5 3 Output 01010 Input 7 3 Output 1011011 Note In the first test, it's easy to see, that the only unique substring of string s = "1111" is all string s, which has length 4. In the second test a string s = "01010" has minimal unique substring t ="101", which has length 3. In the third test a string s = "1011011" has minimal unique substring t ="110", which has length 3.
instruction
0
16,898
0
33,796
Tags: constructive algorithms, math, strings Correct Solution: ``` n, k = map( int, input().split() ) d = n - k d = d // 2 l = [] while n > 0: i = min(n,d) while i>0: l.append('1') i -= 1 n -= 1 if n > 0: l.append('0') n -= 1 print( "".join( l ) ) ```
output
1
16,898
0
33,797
Provide tags and a correct Python 3 solution for this coding contest problem. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010" is an unique substring of s, because l = 2 is the only one suitable number. But, for example t = "10" isn't a unique substring of s, because l = 1 and l = 3 are suitable. And for example t ="00" at all isn't a substring of s, because there is no suitable l. Today Vasya solved the following problem at the informatics lesson: given a string consisting of symbols "0" and "1", the task is to find the length of its minimal unique substring. He has written a solution to this problem and wants to test it. He is asking you to help him. You are given 2 positive integers n and k, such that (n mod 2) = (k mod 2), where (x mod 2) is operation of taking remainder of x by dividing on 2. Find any string s consisting of n symbols "0" or "1", such that the length of its minimal unique substring is equal to k. Input The first line contains two integers n and k, separated by spaces (1 ≀ k ≀ n ≀ 100 000, (k mod 2) = (n mod 2)). Output Print a string s of length n, consisting of symbols "0" and "1". Minimal length of the unique substring of s should be equal to k. You can find any suitable string. It is guaranteed, that there exists at least one such string. Examples Input 4 4 Output 1111 Input 5 3 Output 01010 Input 7 3 Output 1011011 Note In the first test, it's easy to see, that the only unique substring of string s = "1111" is all string s, which has length 4. In the second test a string s = "01010" has minimal unique substring t ="101", which has length 3. In the third test a string s = "1011011" has minimal unique substring t ="110", which has length 3.
instruction
0
16,899
0
33,798
Tags: constructive algorithms, math, strings Correct Solution: ``` n,k=map(int,input().split()) a=(n-k)//2 for i in range(n): if((i+1)%(a+1)==0): print("1",end='') else: print("0",end='') ```
output
1
16,899
0
33,799
Provide tags and a correct Python 3 solution for this coding contest problem. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010" is an unique substring of s, because l = 2 is the only one suitable number. But, for example t = "10" isn't a unique substring of s, because l = 1 and l = 3 are suitable. And for example t ="00" at all isn't a substring of s, because there is no suitable l. Today Vasya solved the following problem at the informatics lesson: given a string consisting of symbols "0" and "1", the task is to find the length of its minimal unique substring. He has written a solution to this problem and wants to test it. He is asking you to help him. You are given 2 positive integers n and k, such that (n mod 2) = (k mod 2), where (x mod 2) is operation of taking remainder of x by dividing on 2. Find any string s consisting of n symbols "0" or "1", such that the length of its minimal unique substring is equal to k. Input The first line contains two integers n and k, separated by spaces (1 ≀ k ≀ n ≀ 100 000, (k mod 2) = (n mod 2)). Output Print a string s of length n, consisting of symbols "0" and "1". Minimal length of the unique substring of s should be equal to k. You can find any suitable string. It is guaranteed, that there exists at least one such string. Examples Input 4 4 Output 1111 Input 5 3 Output 01010 Input 7 3 Output 1011011 Note In the first test, it's easy to see, that the only unique substring of string s = "1111" is all string s, which has length 4. In the second test a string s = "01010" has minimal unique substring t ="101", which has length 3. In the third test a string s = "1011011" has minimal unique substring t ="110", which has length 3.
instruction
0
16,900
0
33,800
Tags: constructive algorithms, math, strings Correct Solution: ``` #saved n, k = map(int, input().split()) if n == k: print('1' * n) elif k == 1: print('0' + '1' * (n - 1)) else: x = (n - k) // 2 a = '0' * x + '1' print(a * (n // (x + 1)) + '0' * (n % (x + 1))) ```
output
1
16,900
0
33,801
Provide tags and a correct Python 3 solution for this coding contest problem. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010" is an unique substring of s, because l = 2 is the only one suitable number. But, for example t = "10" isn't a unique substring of s, because l = 1 and l = 3 are suitable. And for example t ="00" at all isn't a substring of s, because there is no suitable l. Today Vasya solved the following problem at the informatics lesson: given a string consisting of symbols "0" and "1", the task is to find the length of its minimal unique substring. He has written a solution to this problem and wants to test it. He is asking you to help him. You are given 2 positive integers n and k, such that (n mod 2) = (k mod 2), where (x mod 2) is operation of taking remainder of x by dividing on 2. Find any string s consisting of n symbols "0" or "1", such that the length of its minimal unique substring is equal to k. Input The first line contains two integers n and k, separated by spaces (1 ≀ k ≀ n ≀ 100 000, (k mod 2) = (n mod 2)). Output Print a string s of length n, consisting of symbols "0" and "1". Minimal length of the unique substring of s should be equal to k. You can find any suitable string. It is guaranteed, that there exists at least one such string. Examples Input 4 4 Output 1111 Input 5 3 Output 01010 Input 7 3 Output 1011011 Note In the first test, it's easy to see, that the only unique substring of string s = "1111" is all string s, which has length 4. In the second test a string s = "01010" has minimal unique substring t ="101", which has length 3. In the third test a string s = "1011011" has minimal unique substring t ="110", which has length 3.
instruction
0
16,901
0
33,802
Tags: constructive algorithms, math, strings Correct Solution: ``` #------------------------template--------------------------# import os import sys from math import * from collections import * # from fractions import * # from functools import * from heapq import * from bisect import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') 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") ALPHA='abcdefghijklmnopqrstuvwxyz' M = 998244353 EPS = 1e-6 def Ceil(a,b): return a//b+int(a%b>0) def value():return tuple(map(int,input().split())) def array():return [int(i) for i in input().split()] def Int():return int(input()) def Str():return input() def arrayS():return [i for i in input().split()] #-------------------------code---------------------------# # vsInput() for _ in range(1): n,k = value() rep = [1] + [0]*((n-k)//2) cur = 0 ans = [] j = 0 for i in range(n): ans.append(rep[j]) j = (j + 1)%len(rep) if(k == 1): ans = [1] + [0]*(n - 1) print(*ans,sep = '') ```
output
1
16,901
0
33,803
Provide tags and a correct Python 3 solution for this coding contest problem. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010" is an unique substring of s, because l = 2 is the only one suitable number. But, for example t = "10" isn't a unique substring of s, because l = 1 and l = 3 are suitable. And for example t ="00" at all isn't a substring of s, because there is no suitable l. Today Vasya solved the following problem at the informatics lesson: given a string consisting of symbols "0" and "1", the task is to find the length of its minimal unique substring. He has written a solution to this problem and wants to test it. He is asking you to help him. You are given 2 positive integers n and k, such that (n mod 2) = (k mod 2), where (x mod 2) is operation of taking remainder of x by dividing on 2. Find any string s consisting of n symbols "0" or "1", such that the length of its minimal unique substring is equal to k. Input The first line contains two integers n and k, separated by spaces (1 ≀ k ≀ n ≀ 100 000, (k mod 2) = (n mod 2)). Output Print a string s of length n, consisting of symbols "0" and "1". Minimal length of the unique substring of s should be equal to k. You can find any suitable string. It is guaranteed, that there exists at least one such string. Examples Input 4 4 Output 1111 Input 5 3 Output 01010 Input 7 3 Output 1011011 Note In the first test, it's easy to see, that the only unique substring of string s = "1111" is all string s, which has length 4. In the second test a string s = "01010" has minimal unique substring t ="101", which has length 3. In the third test a string s = "1011011" has minimal unique substring t ="110", which has length 3.
instruction
0
16,902
0
33,804
Tags: constructive algorithms, math, strings Correct Solution: ``` n, k = list(map(int,input().split())) chuj_twojej_starej = (n - k) // 2 + 1 i = 1 while True: if i % chuj_twojej_starej == 0: print(0, end = "") else: print(1, end = "") if i == n: break i += 1 ```
output
1
16,902
0
33,805
Provide tags and a correct Python 3 solution for this coding contest problem. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010" is an unique substring of s, because l = 2 is the only one suitable number. But, for example t = "10" isn't a unique substring of s, because l = 1 and l = 3 are suitable. And for example t ="00" at all isn't a substring of s, because there is no suitable l. Today Vasya solved the following problem at the informatics lesson: given a string consisting of symbols "0" and "1", the task is to find the length of its minimal unique substring. He has written a solution to this problem and wants to test it. He is asking you to help him. You are given 2 positive integers n and k, such that (n mod 2) = (k mod 2), where (x mod 2) is operation of taking remainder of x by dividing on 2. Find any string s consisting of n symbols "0" or "1", such that the length of its minimal unique substring is equal to k. Input The first line contains two integers n and k, separated by spaces (1 ≀ k ≀ n ≀ 100 000, (k mod 2) = (n mod 2)). Output Print a string s of length n, consisting of symbols "0" and "1". Minimal length of the unique substring of s should be equal to k. You can find any suitable string. It is guaranteed, that there exists at least one such string. Examples Input 4 4 Output 1111 Input 5 3 Output 01010 Input 7 3 Output 1011011 Note In the first test, it's easy to see, that the only unique substring of string s = "1111" is all string s, which has length 4. In the second test a string s = "01010" has minimal unique substring t ="101", which has length 3. In the third test a string s = "1011011" has minimal unique substring t ="110", which has length 3.
instruction
0
16,903
0
33,806
Tags: constructive algorithms, math, strings Correct Solution: ``` from collections import * from math import * n,k = map(int,input().split()) x = (n-k)//2+1 for i in range(1,n+1): if(i%x) == 0: print(1,end="") else: print(0,end="") print() ```
output
1
16,903
0
33,807
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010" is an unique substring of s, because l = 2 is the only one suitable number. But, for example t = "10" isn't a unique substring of s, because l = 1 and l = 3 are suitable. And for example t ="00" at all isn't a substring of s, because there is no suitable l. Today Vasya solved the following problem at the informatics lesson: given a string consisting of symbols "0" and "1", the task is to find the length of its minimal unique substring. He has written a solution to this problem and wants to test it. He is asking you to help him. You are given 2 positive integers n and k, such that (n mod 2) = (k mod 2), where (x mod 2) is operation of taking remainder of x by dividing on 2. Find any string s consisting of n symbols "0" or "1", such that the length of its minimal unique substring is equal to k. Input The first line contains two integers n and k, separated by spaces (1 ≀ k ≀ n ≀ 100 000, (k mod 2) = (n mod 2)). Output Print a string s of length n, consisting of symbols "0" and "1". Minimal length of the unique substring of s should be equal to k. You can find any suitable string. It is guaranteed, that there exists at least one such string. Examples Input 4 4 Output 1111 Input 5 3 Output 01010 Input 7 3 Output 1011011 Note In the first test, it's easy to see, that the only unique substring of string s = "1111" is all string s, which has length 4. In the second test a string s = "01010" has minimal unique substring t ="101", which has length 3. In the third test a string s = "1011011" has minimal unique substring t ="110", which has length 3. Submitted Solution: ``` import os import sys def log(*args, **kwargs): if os.environ.get('CODEFR'): print(*args, **kwargs) n, k = tuple(map(int, input().split())) s = '0'*((n-k)//2) + '1' for i in range(n): print(s[i % len(s)], end='') print() ```
instruction
0
16,904
0
33,808
Yes
output
1
16,904
0
33,809
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010" is an unique substring of s, because l = 2 is the only one suitable number. But, for example t = "10" isn't a unique substring of s, because l = 1 and l = 3 are suitable. And for example t ="00" at all isn't a substring of s, because there is no suitable l. Today Vasya solved the following problem at the informatics lesson: given a string consisting of symbols "0" and "1", the task is to find the length of its minimal unique substring. He has written a solution to this problem and wants to test it. He is asking you to help him. You are given 2 positive integers n and k, such that (n mod 2) = (k mod 2), where (x mod 2) is operation of taking remainder of x by dividing on 2. Find any string s consisting of n symbols "0" or "1", such that the length of its minimal unique substring is equal to k. Input The first line contains two integers n and k, separated by spaces (1 ≀ k ≀ n ≀ 100 000, (k mod 2) = (n mod 2)). Output Print a string s of length n, consisting of symbols "0" and "1". Minimal length of the unique substring of s should be equal to k. You can find any suitable string. It is guaranteed, that there exists at least one such string. Examples Input 4 4 Output 1111 Input 5 3 Output 01010 Input 7 3 Output 1011011 Note In the first test, it's easy to see, that the only unique substring of string s = "1111" is all string s, which has length 4. In the second test a string s = "01010" has minimal unique substring t ="101", which has length 3. In the third test a string s = "1011011" has minimal unique substring t ="110", which has length 3. Submitted Solution: ``` # ========= /\ /| |====/| # | / \ | | / | # | /____\ | | / | # | / \ | | / | # ========= / \ ===== |/====| # code if __name__ == "__main__": n,k = map(int,input().split()) a = (n - k)//2 ps = '0'*a + '1' s = "" i = 0 while i + a + 1 <= n: s += ps i += a+1 if i < n: x = n - i s += ps[:x] print(s) ```
instruction
0
16,905
0
33,810
Yes
output
1
16,905
0
33,811
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010" is an unique substring of s, because l = 2 is the only one suitable number. But, for example t = "10" isn't a unique substring of s, because l = 1 and l = 3 are suitable. And for example t ="00" at all isn't a substring of s, because there is no suitable l. Today Vasya solved the following problem at the informatics lesson: given a string consisting of symbols "0" and "1", the task is to find the length of its minimal unique substring. He has written a solution to this problem and wants to test it. He is asking you to help him. You are given 2 positive integers n and k, such that (n mod 2) = (k mod 2), where (x mod 2) is operation of taking remainder of x by dividing on 2. Find any string s consisting of n symbols "0" or "1", such that the length of its minimal unique substring is equal to k. Input The first line contains two integers n and k, separated by spaces (1 ≀ k ≀ n ≀ 100 000, (k mod 2) = (n mod 2)). Output Print a string s of length n, consisting of symbols "0" and "1". Minimal length of the unique substring of s should be equal to k. You can find any suitable string. It is guaranteed, that there exists at least one such string. Examples Input 4 4 Output 1111 Input 5 3 Output 01010 Input 7 3 Output 1011011 Note In the first test, it's easy to see, that the only unique substring of string s = "1111" is all string s, which has length 4. In the second test a string s = "01010" has minimal unique substring t ="101", which has length 3. In the third test a string s = "1011011" has minimal unique substring t ="110", which has length 3. Submitted Solution: ``` n,k=map(int,input().strip().split()) d=(n-k)//2+1 x=['1' if (i+1)%d==0 else '0' for i in range(n)] print(''.join(x)) ```
instruction
0
16,906
0
33,812
Yes
output
1
16,906
0
33,813
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010" is an unique substring of s, because l = 2 is the only one suitable number. But, for example t = "10" isn't a unique substring of s, because l = 1 and l = 3 are suitable. And for example t ="00" at all isn't a substring of s, because there is no suitable l. Today Vasya solved the following problem at the informatics lesson: given a string consisting of symbols "0" and "1", the task is to find the length of its minimal unique substring. He has written a solution to this problem and wants to test it. He is asking you to help him. You are given 2 positive integers n and k, such that (n mod 2) = (k mod 2), where (x mod 2) is operation of taking remainder of x by dividing on 2. Find any string s consisting of n symbols "0" or "1", such that the length of its minimal unique substring is equal to k. Input The first line contains two integers n and k, separated by spaces (1 ≀ k ≀ n ≀ 100 000, (k mod 2) = (n mod 2)). Output Print a string s of length n, consisting of symbols "0" and "1". Minimal length of the unique substring of s should be equal to k. You can find any suitable string. It is guaranteed, that there exists at least one such string. Examples Input 4 4 Output 1111 Input 5 3 Output 01010 Input 7 3 Output 1011011 Note In the first test, it's easy to see, that the only unique substring of string s = "1111" is all string s, which has length 4. In the second test a string s = "01010" has minimal unique substring t ="101", which has length 3. In the third test a string s = "1011011" has minimal unique substring t ="110", which has length 3. Submitted Solution: ``` t=1 def solve(): k1=(n-k)//2 for i in range(n): print(int((i+1)%(k1+1)==0),end="") print() for _ in range(t): #n=int(input()) #n1=n #a=int(input()) #b=int(input()) #a,b,c,r=map(int,input().split()) #x2,y2=map(int,input().split()) #n=int(input()) n,k=(map(int,input().split())) #s=input() #l1=list(map(int,input().split())) #l2=list(map(int,input().split())) #l=str(n) #l.sort(reverse=True) #l2.sort(reverse=True) #l1.sort(reverse=True) solve() ```
instruction
0
16,907
0
33,814
Yes
output
1
16,907
0
33,815
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010" is an unique substring of s, because l = 2 is the only one suitable number. But, for example t = "10" isn't a unique substring of s, because l = 1 and l = 3 are suitable. And for example t ="00" at all isn't a substring of s, because there is no suitable l. Today Vasya solved the following problem at the informatics lesson: given a string consisting of symbols "0" and "1", the task is to find the length of its minimal unique substring. He has written a solution to this problem and wants to test it. He is asking you to help him. You are given 2 positive integers n and k, such that (n mod 2) = (k mod 2), where (x mod 2) is operation of taking remainder of x by dividing on 2. Find any string s consisting of n symbols "0" or "1", such that the length of its minimal unique substring is equal to k. Input The first line contains two integers n and k, separated by spaces (1 ≀ k ≀ n ≀ 100 000, (k mod 2) = (n mod 2)). Output Print a string s of length n, consisting of symbols "0" and "1". Minimal length of the unique substring of s should be equal to k. You can find any suitable string. It is guaranteed, that there exists at least one such string. Examples Input 4 4 Output 1111 Input 5 3 Output 01010 Input 7 3 Output 1011011 Note In the first test, it's easy to see, that the only unique substring of string s = "1111" is all string s, which has length 4. In the second test a string s = "01010" has minimal unique substring t ="101", which has length 3. In the third test a string s = "1011011" has minimal unique substring t ="110", which has length 3. Submitted Solution: ``` n,k=map(int,input().split()) s="0" for i in range(1,k): if(s[i-1]=="0"): s=s+"1" else: s=s+"0" a="1"*(n-k) s=a+s s=s+"1"*(n-len(s)) print(s) ```
instruction
0
16,908
0
33,816
No
output
1
16,908
0
33,817
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010" is an unique substring of s, because l = 2 is the only one suitable number. But, for example t = "10" isn't a unique substring of s, because l = 1 and l = 3 are suitable. And for example t ="00" at all isn't a substring of s, because there is no suitable l. Today Vasya solved the following problem at the informatics lesson: given a string consisting of symbols "0" and "1", the task is to find the length of its minimal unique substring. He has written a solution to this problem and wants to test it. He is asking you to help him. You are given 2 positive integers n and k, such that (n mod 2) = (k mod 2), where (x mod 2) is operation of taking remainder of x by dividing on 2. Find any string s consisting of n symbols "0" or "1", such that the length of its minimal unique substring is equal to k. Input The first line contains two integers n and k, separated by spaces (1 ≀ k ≀ n ≀ 100 000, (k mod 2) = (n mod 2)). Output Print a string s of length n, consisting of symbols "0" and "1". Minimal length of the unique substring of s should be equal to k. You can find any suitable string. It is guaranteed, that there exists at least one such string. Examples Input 4 4 Output 1111 Input 5 3 Output 01010 Input 7 3 Output 1011011 Note In the first test, it's easy to see, that the only unique substring of string s = "1111" is all string s, which has length 4. In the second test a string s = "01010" has minimal unique substring t ="101", which has length 3. In the third test a string s = "1011011" has minimal unique substring t ="110", which has length 3. Submitted Solution: ``` n, k = map(int, input().split()) if n == k: print('1' * n) elif n == k + 2: print('01' * (n // 2) + '0' * (n % 2)) elif n >= 2 * k: print('0' * k + '10' * ((n - k) // 2)) else: x = (n - k) // 2 a = '0' * x c = '0' * x r = '1' + '0' * x z = '1' if (k - 1) % (x + 1) == 0: z = '' b = r * ((k - 1) // (x + 1)) + z + '0' * (max(0, (k - 1) % (x + 1))) print(a+b+'1'+c) ```
instruction
0
16,909
0
33,818
No
output
1
16,909
0
33,819
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010" is an unique substring of s, because l = 2 is the only one suitable number. But, for example t = "10" isn't a unique substring of s, because l = 1 and l = 3 are suitable. And for example t ="00" at all isn't a substring of s, because there is no suitable l. Today Vasya solved the following problem at the informatics lesson: given a string consisting of symbols "0" and "1", the task is to find the length of its minimal unique substring. He has written a solution to this problem and wants to test it. He is asking you to help him. You are given 2 positive integers n and k, such that (n mod 2) = (k mod 2), where (x mod 2) is operation of taking remainder of x by dividing on 2. Find any string s consisting of n symbols "0" or "1", such that the length of its minimal unique substring is equal to k. Input The first line contains two integers n and k, separated by spaces (1 ≀ k ≀ n ≀ 100 000, (k mod 2) = (n mod 2)). Output Print a string s of length n, consisting of symbols "0" and "1". Minimal length of the unique substring of s should be equal to k. You can find any suitable string. It is guaranteed, that there exists at least one such string. Examples Input 4 4 Output 1111 Input 5 3 Output 01010 Input 7 3 Output 1011011 Note In the first test, it's easy to see, that the only unique substring of string s = "1111" is all string s, which has length 4. In the second test a string s = "01010" has minimal unique substring t ="101", which has length 3. In the third test a string s = "1011011" has minimal unique substring t ="110", which has length 3. Submitted Solution: ``` n, k = map(int, input().split()) if n == k: print('1' * n) elif n >= 2 * k: print('0' * k + '10' * ((n - k) // 2)) else: x = (n - k) // 2 a = '0' * x + '1' print(a * (n // (x + 1)) + '0' * (n % (x + 1))) ```
instruction
0
16,910
0
33,820
No
output
1
16,910
0
33,821
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≀ l ≀ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010" is an unique substring of s, because l = 2 is the only one suitable number. But, for example t = "10" isn't a unique substring of s, because l = 1 and l = 3 are suitable. And for example t ="00" at all isn't a substring of s, because there is no suitable l. Today Vasya solved the following problem at the informatics lesson: given a string consisting of symbols "0" and "1", the task is to find the length of its minimal unique substring. He has written a solution to this problem and wants to test it. He is asking you to help him. You are given 2 positive integers n and k, such that (n mod 2) = (k mod 2), where (x mod 2) is operation of taking remainder of x by dividing on 2. Find any string s consisting of n symbols "0" or "1", such that the length of its minimal unique substring is equal to k. Input The first line contains two integers n and k, separated by spaces (1 ≀ k ≀ n ≀ 100 000, (k mod 2) = (n mod 2)). Output Print a string s of length n, consisting of symbols "0" and "1". Minimal length of the unique substring of s should be equal to k. You can find any suitable string. It is guaranteed, that there exists at least one such string. Examples Input 4 4 Output 1111 Input 5 3 Output 01010 Input 7 3 Output 1011011 Note In the first test, it's easy to see, that the only unique substring of string s = "1111" is all string s, which has length 4. In the second test a string s = "01010" has minimal unique substring t ="101", which has length 3. In the third test a string s = "1011011" has minimal unique substring t ="110", which has length 3. Submitted Solution: ``` n, k = map(int, input().split()) if n == k: print('1' * n) elif n == k + 2: print('01' * (n // 2) + '0' * (n % 2)) else: z = '0' * ((n - k) // 2) print(z + '10' * (k // 2) + '1' * (k % 2) + z) ```
instruction
0
16,911
0
33,822
No
output
1
16,911
0
33,823
Provide tags and a correct Python 3 solution for this coding contest problem. While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other. A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself. Input The first line contains string a, and the second line β€” string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. Output If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b. Examples Input abcd defgh Output 5 Input a a Output -1 Note In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
instruction
0
17,314
0
34,628
Tags: constructive algorithms, strings Correct Solution: ``` strng1, strng2 = input(), input() if strng1 == strng2: print(-1) elif len(strng1) > len(strng2): print(len(strng1)) else: print(len(strng2)) ```
output
1
17,314
0
34,629
Provide tags and a correct Python 3 solution for this coding contest problem. While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other. A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself. Input The first line contains string a, and the second line β€” string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. Output If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b. Examples Input abcd defgh Output 5 Input a a Output -1 Note In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
instruction
0
17,315
0
34,630
Tags: constructive algorithms, strings Correct Solution: ``` first = input() second = input() m = '' counter = 0 def compute(a, b): m = a[:] counter = len(m) if a == b: return -1 for i in range(0, len(m)): if m not in b: return counter else: counter-=1 m = m[i:] return counter print(max(compute(first, second), compute(second, first))) ```
output
1
17,315
0
34,631
Provide tags and a correct Python 3 solution for this coding contest problem. While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other. A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself. Input The first line contains string a, and the second line β€” string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. Output If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b. Examples Input abcd defgh Output 5 Input a a Output -1 Note In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
instruction
0
17,316
0
34,632
Tags: constructive algorithms, strings Correct Solution: ``` a=str(input()) b=str(input()) c=list(b) d=list(a) if a==b: print(-1) elif len(c)==0 or len(d)==0: print(-1) else: print(max(len(c),len(d))) ```
output
1
17,316
0
34,633
Provide tags and a correct Python 3 solution for this coding contest problem. While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other. A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself. Input The first line contains string a, and the second line β€” string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. Output If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b. Examples Input abcd defgh Output 5 Input a a Output -1 Note In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
instruction
0
17,317
0
34,634
Tags: constructive algorithms, strings Correct Solution: ``` a = input() b = input() if a == b: otv = -1 elif len(a) > len(b): otv = len(a) else: otv = len(b) print(otv) ```
output
1
17,317
0
34,635
Provide tags and a correct Python 3 solution for this coding contest problem. While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other. A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself. Input The first line contains string a, and the second line β€” string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. Output If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b. Examples Input abcd defgh Output 5 Input a a Output -1 Note In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
instruction
0
17,318
0
34,636
Tags: constructive algorithms, strings Correct Solution: ``` s = input() w = input() print('-1' if s == w else max(len(s), len(w))) ```
output
1
17,318
0
34,637