message
stringlengths
2
23.8k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
97
109k
cluster
float64
0
0
__index_level_0__
int64
194
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, the Fair Nut has written k strings of length n, consisting of letters "a" and "b". He calculated c β€” the number of strings that are prefixes of at least one of the written strings. Every string was counted only one time. Then, he lost his sheet with strings. He remembers that all written strings were lexicographically not smaller than string s and not bigger than string t. He is interested: what is the maximum value of c that he could get. A string a is lexicographically smaller than a string b if and only if one of the following holds: * a is a prefix of b, but a β‰  b; * in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b. Input The first line contains two integers n and k (1 ≀ n ≀ 5 β‹… 10^5, 1 ≀ k ≀ 10^9). The second line contains a string s (|s| = n) β€” the string consisting of letters "a" and "b. The third line contains a string t (|t| = n) β€” the string consisting of letters "a" and "b. It is guaranteed that string s is lexicographically not bigger than t. Output Print one number β€” maximal value of c. Examples Input 2 4 aa bb Output 6 Input 3 3 aba bba Output 8 Input 4 5 abbb baaa Output 8 Note In the first example, Nut could write strings "aa", "ab", "ba", "bb". These 4 strings are prefixes of at least one of the written strings, as well as "a" and "b". Totally, 6 strings. In the second example, Nut could write strings "aba", "baa", "bba". In the third example, there are only two different strings that Nut could write. If both of them are written, c=8. Submitted Solution: ``` import sys readline = sys.stdin.readline N, K = map(int, readline().split()) S = [1 if s == 'b' else 0 for s in readline().strip()] T = [1 if s == 'b' else 0 for s in readline().strip()] diff = 0 for s, t in zip(S, T): if diff > K: break if s == t: diff <<= 1 elif s == 1: diff = (diff << 1) - 1 else: diff = (diff << 1) + 1 K = min(K, diff + 1) ans = 0 cnt = 1 ans = 0 for s, t in zip(S, T): if cnt == K: ans += cnt continue if cnt == 1: if s == t: ans += cnt else: cnt += 1 cnt = min(K, cnt) ans += cnt continue else: cnt *= 2 if s == 1: cnt -= 1 if t == 0: cnt -= 1 cnt = min(K, cnt) ans += cnt print(ans) ```
instruction
0
50,516
0
101,032
Yes
output
1
50,516
0
101,033
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, the Fair Nut has written k strings of length n, consisting of letters "a" and "b". He calculated c β€” the number of strings that are prefixes of at least one of the written strings. Every string was counted only one time. Then, he lost his sheet with strings. He remembers that all written strings were lexicographically not smaller than string s and not bigger than string t. He is interested: what is the maximum value of c that he could get. A string a is lexicographically smaller than a string b if and only if one of the following holds: * a is a prefix of b, but a β‰  b; * in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b. Input The first line contains two integers n and k (1 ≀ n ≀ 5 β‹… 10^5, 1 ≀ k ≀ 10^9). The second line contains a string s (|s| = n) β€” the string consisting of letters "a" and "b. The third line contains a string t (|t| = n) β€” the string consisting of letters "a" and "b. It is guaranteed that string s is lexicographically not bigger than t. Output Print one number β€” maximal value of c. Examples Input 2 4 aa bb Output 6 Input 3 3 aba bba Output 8 Input 4 5 abbb baaa Output 8 Note In the first example, Nut could write strings "aa", "ab", "ba", "bb". These 4 strings are prefixes of at least one of the written strings, as well as "a" and "b". Totally, 6 strings. In the second example, Nut could write strings "aba", "baa", "bba". In the third example, there are only two different strings that Nut could write. If both of them are written, c=8. Submitted Solution: ``` import math n,k = map(int,input().split()) s = input() t = input() boo = False for i in range(n): if s[i] != t[i]: boo = True s = s[i:] t = t[i:] break if not boo: print(n) else: dig = 0 ans = n-len(s) n = len(s) for i in range(n): num = 1 for j in range(i+1): if t[j] == 'b': num += 2**(i-j) if s[j] == 'b': num -= 2**(i-j) if num < k: ans += num else: dig = n-i break ans += dig*k print(ans) ```
instruction
0
50,517
0
101,034
Yes
output
1
50,517
0
101,035
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, the Fair Nut has written k strings of length n, consisting of letters "a" and "b". He calculated c β€” the number of strings that are prefixes of at least one of the written strings. Every string was counted only one time. Then, he lost his sheet with strings. He remembers that all written strings were lexicographically not smaller than string s and not bigger than string t. He is interested: what is the maximum value of c that he could get. A string a is lexicographically smaller than a string b if and only if one of the following holds: * a is a prefix of b, but a β‰  b; * in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b. Input The first line contains two integers n and k (1 ≀ n ≀ 5 β‹… 10^5, 1 ≀ k ≀ 10^9). The second line contains a string s (|s| = n) β€” the string consisting of letters "a" and "b. The third line contains a string t (|t| = n) β€” the string consisting of letters "a" and "b. It is guaranteed that string s is lexicographically not bigger than t. Output Print one number β€” maximal value of c. Examples Input 2 4 aa bb Output 6 Input 3 3 aba bba Output 8 Input 4 5 abbb baaa Output 8 Note In the first example, Nut could write strings "aa", "ab", "ba", "bb". These 4 strings are prefixes of at least one of the written strings, as well as "a" and "b". Totally, 6 strings. In the second example, Nut could write strings "aba", "baa", "bba". In the third example, there are only two different strings that Nut could write. If both of them are written, c=8. Submitted Solution: ``` n,k=map(int,input().split()) s,t,cu=input(),input(),[1] for i in range(n): cu+=[cu[-1]*2-(s[i]=='b')-(t[i]=='a')] if cu[-1]>=k:cu[-1]=k;break print(sum(cu)+(n-i-1)*k-1) ```
instruction
0
50,518
0
101,036
Yes
output
1
50,518
0
101,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, the Fair Nut has written k strings of length n, consisting of letters "a" and "b". He calculated c β€” the number of strings that are prefixes of at least one of the written strings. Every string was counted only one time. Then, he lost his sheet with strings. He remembers that all written strings were lexicographically not smaller than string s and not bigger than string t. He is interested: what is the maximum value of c that he could get. A string a is lexicographically smaller than a string b if and only if one of the following holds: * a is a prefix of b, but a β‰  b; * in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b. Input The first line contains two integers n and k (1 ≀ n ≀ 5 β‹… 10^5, 1 ≀ k ≀ 10^9). The second line contains a string s (|s| = n) β€” the string consisting of letters "a" and "b. The third line contains a string t (|t| = n) β€” the string consisting of letters "a" and "b. It is guaranteed that string s is lexicographically not bigger than t. Output Print one number β€” maximal value of c. Examples Input 2 4 aa bb Output 6 Input 3 3 aba bba Output 8 Input 4 5 abbb baaa Output 8 Note In the first example, Nut could write strings "aa", "ab", "ba", "bb". These 4 strings are prefixes of at least one of the written strings, as well as "a" and "b". Totally, 6 strings. In the second example, Nut could write strings "aba", "baa", "bba". In the third example, there are only two different strings that Nut could write. If both of them are written, c=8. Submitted Solution: ``` n, k = map(int, input().split()) s = input() t = input() Sum = -1 pos = 0 ans = 0 while pos < n and s[pos] == t[pos]: pos += 1 ans += 1 for i in range(pos, n): Sum = Sum * 2 + 1 - ord(s[i]) + ord(t[i]) if Sum + 2 >= k: ans += (n - i) * k break else: ans += Sum + 2 print(ans) ```
instruction
0
50,519
0
101,038
Yes
output
1
50,519
0
101,039
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, the Fair Nut has written k strings of length n, consisting of letters "a" and "b". He calculated c β€” the number of strings that are prefixes of at least one of the written strings. Every string was counted only one time. Then, he lost his sheet with strings. He remembers that all written strings were lexicographically not smaller than string s and not bigger than string t. He is interested: what is the maximum value of c that he could get. A string a is lexicographically smaller than a string b if and only if one of the following holds: * a is a prefix of b, but a β‰  b; * in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b. Input The first line contains two integers n and k (1 ≀ n ≀ 5 β‹… 10^5, 1 ≀ k ≀ 10^9). The second line contains a string s (|s| = n) β€” the string consisting of letters "a" and "b. The third line contains a string t (|t| = n) β€” the string consisting of letters "a" and "b. It is guaranteed that string s is lexicographically not bigger than t. Output Print one number β€” maximal value of c. Examples Input 2 4 aa bb Output 6 Input 3 3 aba bba Output 8 Input 4 5 abbb baaa Output 8 Note In the first example, Nut could write strings "aa", "ab", "ba", "bb". These 4 strings are prefixes of at least one of the written strings, as well as "a" and "b". Totally, 6 strings. In the second example, Nut could write strings "aba", "baa", "bba". In the third example, there are only two different strings that Nut could write. If both of them are written, c=8. Submitted Solution: ``` # x = int(input()) # m, n = map(int, input().split()) # nums = list(map(int, input().split())) n,k=map(int,input().split()) s1=input() s2=input() cnt=1 ans=0 for i in range(n): cnt*=2 if s1[i]=='b': cnt-=1 if s2[i]=='a': cnt-=1 cnt=min(1e9,cnt) ans+=min(cnt,k) print(ans) ```
instruction
0
50,520
0
101,040
No
output
1
50,520
0
101,041
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, the Fair Nut has written k strings of length n, consisting of letters "a" and "b". He calculated c β€” the number of strings that are prefixes of at least one of the written strings. Every string was counted only one time. Then, he lost his sheet with strings. He remembers that all written strings were lexicographically not smaller than string s and not bigger than string t. He is interested: what is the maximum value of c that he could get. A string a is lexicographically smaller than a string b if and only if one of the following holds: * a is a prefix of b, but a β‰  b; * in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b. Input The first line contains two integers n and k (1 ≀ n ≀ 5 β‹… 10^5, 1 ≀ k ≀ 10^9). The second line contains a string s (|s| = n) β€” the string consisting of letters "a" and "b. The third line contains a string t (|t| = n) β€” the string consisting of letters "a" and "b. It is guaranteed that string s is lexicographically not bigger than t. Output Print one number β€” maximal value of c. Examples Input 2 4 aa bb Output 6 Input 3 3 aba bba Output 8 Input 4 5 abbb baaa Output 8 Note In the first example, Nut could write strings "aa", "ab", "ba", "bb". These 4 strings are prefixes of at least one of the written strings, as well as "a" and "b". Totally, 6 strings. In the second example, Nut could write strings "aba", "baa", "bba". In the third example, there are only two different strings that Nut could write. If both of them are written, c=8. Submitted Solution: ``` n,k = [int(x) for x in input().split()] s = input() t = input() S = [] T = [] for i in s: if i == 'a': S.append(0) else: S.append(1) for i in t: if i == 'a': T.append(0) else: T.append(1) def subtraction(a,b,n): due = 0 ans = [] for i in range(0,n): if b[n-i-1]-a[n-i-1]-due >= 0: ans.append(b[n-i-1]-a[n-i-1]-due) else: ans.append(2+b[n-i-1]-a[n-i-1]-due) due = 1 ans.reverse() for i in range(0,n): if ans[i] == 1: break else: return [] return ans[i:] X = subtraction(S,T,n) if not X: print(n) else: ANS = 0 USED = 0 for i in range(0,n): temp = subtraction(S[:i+1],T[:i+1],i+1) s = 0 for j in range(1,len(temp)+1): if temp[-j] == 1: s += 2**(j-1) if USED + s +1<= k: ANS += max((s+1-USED),0)*(n-i) USED = USED+s+1 else: t = max(s+1-USED,0) ANS += (min(t,k-USED))*(n-i) break print(ANS) ```
instruction
0
50,521
0
101,042
No
output
1
50,521
0
101,043
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, the Fair Nut has written k strings of length n, consisting of letters "a" and "b". He calculated c β€” the number of strings that are prefixes of at least one of the written strings. Every string was counted only one time. Then, he lost his sheet with strings. He remembers that all written strings were lexicographically not smaller than string s and not bigger than string t. He is interested: what is the maximum value of c that he could get. A string a is lexicographically smaller than a string b if and only if one of the following holds: * a is a prefix of b, but a β‰  b; * in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b. Input The first line contains two integers n and k (1 ≀ n ≀ 5 β‹… 10^5, 1 ≀ k ≀ 10^9). The second line contains a string s (|s| = n) β€” the string consisting of letters "a" and "b. The third line contains a string t (|t| = n) β€” the string consisting of letters "a" and "b. It is guaranteed that string s is lexicographically not bigger than t. Output Print one number β€” maximal value of c. Examples Input 2 4 aa bb Output 6 Input 3 3 aba bba Output 8 Input 4 5 abbb baaa Output 8 Note In the first example, Nut could write strings "aa", "ab", "ba", "bb". These 4 strings are prefixes of at least one of the written strings, as well as "a" and "b". Totally, 6 strings. In the second example, Nut could write strings "aba", "baa", "bba". In the third example, there are only two different strings that Nut could write. If both of them are written, c=8. Submitted Solution: ``` n,k = [int(x) for x in input().split()] s = input() t = input() S = [] T = [] for i in s: if i == 'a': S.append(0) else: S.append(1) for i in t: if i == 'a': T.append(0) else: T.append(1) def subtraction(a,b,n): due = 0 ans = [] for i in range(0,n): if b[n-i-1]-a[n-i-1]-due >= 0: ans.append(b[n-i-1]-a[n-i-1]-due) else: ans.append(2+b[n-i-1]-a[n-i-1]-due) due = 1 ans.reverse() for i in range(0,n): if ans[i] == 1: break else: return [] return ans[i:] X = subtraction(S,T,n) if not X: print(n) else: ANS = 0 USED = 0 for i in range(0,n): temp = subtraction(S[:i+1],T[:i+1],i+1) s = 0 for j in range(1,len(temp)+1): if temp[-j] == 1: s += 2**(j-1) if s+1<= k: ANS += max((s+1-USED),0)*(n-i) USED = USED+max(s+1-USED,0) else: ANS += (k-USED)*(n-i) break print(ANS) ```
instruction
0
50,522
0
101,044
No
output
1
50,522
0
101,045
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently, the Fair Nut has written k strings of length n, consisting of letters "a" and "b". He calculated c β€” the number of strings that are prefixes of at least one of the written strings. Every string was counted only one time. Then, he lost his sheet with strings. He remembers that all written strings were lexicographically not smaller than string s and not bigger than string t. He is interested: what is the maximum value of c that he could get. A string a is lexicographically smaller than a string b if and only if one of the following holds: * a is a prefix of b, but a β‰  b; * in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b. Input The first line contains two integers n and k (1 ≀ n ≀ 5 β‹… 10^5, 1 ≀ k ≀ 10^9). The second line contains a string s (|s| = n) β€” the string consisting of letters "a" and "b. The third line contains a string t (|t| = n) β€” the string consisting of letters "a" and "b. It is guaranteed that string s is lexicographically not bigger than t. Output Print one number β€” maximal value of c. Examples Input 2 4 aa bb Output 6 Input 3 3 aba bba Output 8 Input 4 5 abbb baaa Output 8 Note In the first example, Nut could write strings "aa", "ab", "ba", "bb". These 4 strings are prefixes of at least one of the written strings, as well as "a" and "b". Totally, 6 strings. In the second example, Nut could write strings "aba", "baa", "bba". In the third example, there are only two different strings that Nut could write. If both of them are written, c=8. Submitted Solution: ``` def solve(n, k, start, end): tot = 0 lvl = 1 for i in range(n): lvl += lvl - int(start[i] == end[i]) if lvl >= k: tot += k * (n-i) break tot += lvl return tot n, k = map(int, input().split()) start = input() end = input() print(solve(n, k, start, end)) ```
instruction
0
50,523
0
101,046
No
output
1
50,523
0
101,047
Provide tags and a correct Python 3 solution for this coding contest problem. Two people are playing a game with a string s, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses. Your task is to determine which player will win if both play optimally. Input The only line contains the string s, consisting of lowercase latin letters (1 ≀ |s| ≀ 100 000), where |s| means the length of a string s. Output If the first player wins, print "Yes". If the second player wins, print "No". Examples Input abacaba Output No Input iiq Output Yes Input abba Output No Note In the first example the first player is unable to make a turn, so he loses. In the second example first player turns the string into "q", then second player is unable to move, so he loses.
instruction
0
50,524
0
101,048
Tags: data structures, implementation, math Correct Solution: ``` s = input() left = ['*'] cnt = 0 for ch in s: if ch == left[-1]: left.pop() cnt += 1 else: left.append(ch) print(['No', 'Yes'][cnt%2]) ```
output
1
50,524
0
101,049
Provide tags and a correct Python 3 solution for this coding contest problem. Two people are playing a game with a string s, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses. Your task is to determine which player will win if both play optimally. Input The only line contains the string s, consisting of lowercase latin letters (1 ≀ |s| ≀ 100 000), where |s| means the length of a string s. Output If the first player wins, print "Yes". If the second player wins, print "No". Examples Input abacaba Output No Input iiq Output Yes Input abba Output No Note In the first example the first player is unable to make a turn, so he loses. In the second example first player turns the string into "q", then second player is unable to move, so he loses.
instruction
0
50,525
0
101,050
Tags: data structures, implementation, math Correct Solution: ``` # test ramim's code string = input() s = [] c = 0 for i in range(len(string)): if s and s[-1] == string[i]: s.pop() c+=1 else: s.append(string[i]) if c&1:print('Yes') else:print('No') ```
output
1
50,525
0
101,051
Provide tags and a correct Python 3 solution for this coding contest problem. Two people are playing a game with a string s, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses. Your task is to determine which player will win if both play optimally. Input The only line contains the string s, consisting of lowercase latin letters (1 ≀ |s| ≀ 100 000), where |s| means the length of a string s. Output If the first player wins, print "Yes". If the second player wins, print "No". Examples Input abacaba Output No Input iiq Output Yes Input abba Output No Note In the first example the first player is unable to make a turn, so he loses. In the second example first player turns the string into "q", then second player is unable to move, so he loses.
instruction
0
50,526
0
101,052
Tags: data structures, implementation, math Correct Solution: ``` s=input() ct=0 i=0 stk=[] while(i<len(s)): if len(stk)!=0 and stk[-1]==s[i]: ct+=1 stk.pop() else: stk.append(s[i]) i+=1 if ct%2==1: print("Yes") else: print("No") ```
output
1
50,526
0
101,053
Provide tags and a correct Python 3 solution for this coding contest problem. Two people are playing a game with a string s, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses. Your task is to determine which player will win if both play optimally. Input The only line contains the string s, consisting of lowercase latin letters (1 ≀ |s| ≀ 100 000), where |s| means the length of a string s. Output If the first player wins, print "Yes". If the second player wins, print "No". Examples Input abacaba Output No Input iiq Output Yes Input abba Output No Note In the first example the first player is unable to make a turn, so he loses. In the second example first player turns the string into "q", then second player is unable to move, so he loses.
instruction
0
50,527
0
101,054
Tags: data structures, implementation, math Correct Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools import random sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def pe(s): return print(str(s), file=sys.stderr) def main(): s = S() l = len(s) a = collections.deque() r = 0 al = 0 for i in range(l): t = s[i] if al > 0 and a[-1] == t: r += 1 a.pop() al -= 1 else: a.append(t) al += 1 if r % 2 == 0: return 'No' return 'Yes' print(main()) ```
output
1
50,527
0
101,055
Provide tags and a correct Python 3 solution for this coding contest problem. Two people are playing a game with a string s, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses. Your task is to determine which player will win if both play optimally. Input The only line contains the string s, consisting of lowercase latin letters (1 ≀ |s| ≀ 100 000), where |s| means the length of a string s. Output If the first player wins, print "Yes". If the second player wins, print "No". Examples Input abacaba Output No Input iiq Output Yes Input abba Output No Note In the first example the first player is unable to make a turn, so he loses. In the second example first player turns the string into "q", then second player is unable to move, so he loses.
instruction
0
50,528
0
101,056
Tags: data structures, implementation, math Correct Solution: ``` counter=0 s=list(input()) n=len(s) ans=['#'] for i in range(0,n): if s[i]==ans[-1]: counter+=1 ans.pop() else: ans.append(s[i]) if counter%2==0: print("No") else: print("Yes") ```
output
1
50,528
0
101,057
Provide tags and a correct Python 3 solution for this coding contest problem. Two people are playing a game with a string s, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses. Your task is to determine which player will win if both play optimally. Input The only line contains the string s, consisting of lowercase latin letters (1 ≀ |s| ≀ 100 000), where |s| means the length of a string s. Output If the first player wins, print "Yes". If the second player wins, print "No". Examples Input abacaba Output No Input iiq Output Yes Input abba Output No Note In the first example the first player is unable to make a turn, so he loses. In the second example first player turns the string into "q", then second player is unable to move, so he loses.
instruction
0
50,529
0
101,058
Tags: data structures, implementation, math Correct Solution: ``` s='0'+input() tot=[' '] counter=0 for i in range(len(s)): if s[i]==tot[-1]: tot.pop() counter+=1 else: tot.append(s[i]) if counter%2==0: print('No') else: print('Yes') ```
output
1
50,529
0
101,059
Provide tags and a correct Python 3 solution for this coding contest problem. Two people are playing a game with a string s, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses. Your task is to determine which player will win if both play optimally. Input The only line contains the string s, consisting of lowercase latin letters (1 ≀ |s| ≀ 100 000), where |s| means the length of a string s. Output If the first player wins, print "Yes". If the second player wins, print "No". Examples Input abacaba Output No Input iiq Output Yes Input abba Output No Note In the first example the first player is unable to make a turn, so he loses. In the second example first player turns the string into "q", then second player is unable to move, so he loses.
instruction
0
50,530
0
101,060
Tags: data structures, implementation, math Correct Solution: ``` palavra = input() resp = "No" pilha = [] i = 0 while(i <= len(palavra) - 1): if(len(pilha) == 0): pilha.append(palavra[i]) elif(pilha[-1] == palavra[i]): pilha.pop() if(resp == "No"): resp = "Yes" else: resp = "No" else: pilha.append(palavra[i]) i = i + 1 print(resp) ```
output
1
50,530
0
101,061
Provide tags and a correct Python 3 solution for this coding contest problem. Two people are playing a game with a string s, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses. Your task is to determine which player will win if both play optimally. Input The only line contains the string s, consisting of lowercase latin letters (1 ≀ |s| ≀ 100 000), where |s| means the length of a string s. Output If the first player wins, print "Yes". If the second player wins, print "No". Examples Input abacaba Output No Input iiq Output Yes Input abba Output No Note In the first example the first player is unable to make a turn, so he loses. In the second example first player turns the string into "q", then second player is unable to move, so he loses.
instruction
0
50,531
0
101,062
Tags: data structures, implementation, math Correct Solution: ``` s = input() k = 0 class Stack: def __init__(self): self.data = [] def pop(self): return self.data.pop() def push(self, x): self.data.append(x) def isempty(self): if len(self.data) > 0: return False else: return True stk = Stack() for i in range(len(s)): stk.push(s[i]) while len(stk.data) >= 2 and stk.data[len(stk.data)-1] == stk.data[len(stk.data)-2]: stk.pop() stk.pop() k = k + 1 k = k % 2 if k == 0: print("No") else: print("Yes") ```
output
1
50,531
0
101,063
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two people are playing a game with a string s, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses. Your task is to determine which player will win if both play optimally. Input The only line contains the string s, consisting of lowercase latin letters (1 ≀ |s| ≀ 100 000), where |s| means the length of a string s. Output If the first player wins, print "Yes". If the second player wins, print "No". Examples Input abacaba Output No Input iiq Output Yes Input abba Output No Note In the first example the first player is unable to make a turn, so he loses. In the second example first player turns the string into "q", then second player is unable to move, so he loses. Submitted Solution: ``` s = input() a = [s[0]] k = 0 for i in range(1, len(s)): if len(a) == 0: a.append(s[i]) elif len(a) != 0 and s[i] == a[len(a) - 1]: k += 1 a.pop() else: a.append(s[i]) if k % 2 == 1: print('Yes') else: print('No') ```
instruction
0
50,532
0
101,064
Yes
output
1
50,532
0
101,065
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two people are playing a game with a string s, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses. Your task is to determine which player will win if both play optimally. Input The only line contains the string s, consisting of lowercase latin letters (1 ≀ |s| ≀ 100 000), where |s| means the length of a string s. Output If the first player wins, print "Yes". If the second player wins, print "No". Examples Input abacaba Output No Input iiq Output Yes Input abba Output No Note In the first example the first player is unable to make a turn, so he loses. In the second example first player turns the string into "q", then second player is unable to move, so he loses. Submitted Solution: ``` import sys import heapq import math lines = sys.stdin.read().splitlines() # s = [int(x) for x in lines[0].split(' ')] s = lines[0] i = 0 j = 1 count = 0 class Node: def __init__(self, letter): self.letter = letter self.next = None self.prev = None def add(last, letter): node = Node(letter) last.next = node node.prev = last return node head = Node(s[0]) last = head for i in range(1, len(s)): last = add(last, s[i]) cur = head next = head.next while next != None: if cur.letter == next.letter: count += 1 if cur.prev == None: cur = next.next if cur == None or cur.next == None: break next = cur.next cur.prev = None cur.next = next next.prev = cur else: next = next.next cur = cur.prev if next == None: break cur.next = next next.prev = cur else: next = next.next cur = cur.next print('Yes' if count%2 ==1 else 'No') ```
instruction
0
50,533
0
101,066
Yes
output
1
50,533
0
101,067
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two people are playing a game with a string s, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses. Your task is to determine which player will win if both play optimally. Input The only line contains the string s, consisting of lowercase latin letters (1 ≀ |s| ≀ 100 000), where |s| means the length of a string s. Output If the first player wins, print "Yes". If the second player wins, print "No". Examples Input abacaba Output No Input iiq Output Yes Input abba Output No Note In the first example the first player is unable to make a turn, so he loses. In the second example first player turns the string into "q", then second player is unable to move, so he loses. Submitted Solution: ``` s = input() r = 0 l = [s[0]] for i in range(1,len(s)): if s[i] == l[len(l)-1] : l.pop() if len(l) == 0 : l.append(0) r+=1 else : l.append(s[i]) if r % 2 ==0 : print("No") else : print("Yes") ```
instruction
0
50,534
0
101,068
Yes
output
1
50,534
0
101,069
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two people are playing a game with a string s, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses. Your task is to determine which player will win if both play optimally. Input The only line contains the string s, consisting of lowercase latin letters (1 ≀ |s| ≀ 100 000), where |s| means the length of a string s. Output If the first player wins, print "Yes". If the second player wins, print "No". Examples Input abacaba Output No Input iiq Output Yes Input abba Output No Note In the first example the first player is unable to make a turn, so he loses. In the second example first player turns the string into "q", then second player is unable to move, so he loses. Submitted Solution: ``` # n = int(input()) s = input() n = len(s) # a = list(map(int, input().split())) a = [] ans = 0 for c in s: if len(a) == 0: a.append(c) else: if c == a[-1]: ans += 1 a.pop() else: a.append(c) if ans % 2 == 0: print('No') else: print('Yes') ```
instruction
0
50,535
0
101,070
Yes
output
1
50,535
0
101,071
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two people are playing a game with a string s, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses. Your task is to determine which player will win if both play optimally. Input The only line contains the string s, consisting of lowercase latin letters (1 ≀ |s| ≀ 100 000), where |s| means the length of a string s. Output If the first player wins, print "Yes". If the second player wins, print "No". Examples Input abacaba Output No Input iiq Output Yes Input abba Output No Note In the first example the first player is unable to make a turn, so he loses. In the second example first player turns the string into "q", then second player is unable to move, so he loses. Submitted Solution: ``` s=input() arr=[] for i in s: arr.append(i) f=0 for i in range(1,len(s)): if s[i]==s[i-1]: f=1 break if f==0: print("No") exit() sx=set() for i in s: sx.add(i) if len(sx)==1: if len(s)%2==1: print("No") else: print("Yes") exit() # print(sx) pairs=0 i=0 while i+1<len(s): if s[i]==s[i+1]: i+=2 pairs+=1 else: i+=1 rt=(len(s)-(pairs*2)) if rt<2 and rt>0: if pairs%2==1: print("Yes") exit() else: print("No") exit() if rt==0: if pairs%2==0: print("No") exit() else: print("Yes") exit() re=s[::-1] if re==s: if len(s)%2==0: tt=len(s)//2 if tt%2==1: print("Yes") exit() else: print("No") exit() else: if pairs%2==0: print("No") exit() else: print("Yes") exit() if pairs%2==0: print("No") exit() else: print("Yes") exit() ```
instruction
0
50,536
0
101,072
No
output
1
50,536
0
101,073
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two people are playing a game with a string s, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses. Your task is to determine which player will win if both play optimally. Input The only line contains the string s, consisting of lowercase latin letters (1 ≀ |s| ≀ 100 000), where |s| means the length of a string s. Output If the first player wins, print "Yes". If the second player wins, print "No". Examples Input abacaba Output No Input iiq Output Yes Input abba Output No Note In the first example the first player is unable to make a turn, so he loses. In the second example first player turns the string into "q", then second player is unable to move, so he loses. Submitted Solution: ``` s = input() thisTurn = True alphabets = "abcdefghijklmnopqrstuvwxyz" while True: replaced = False for letter in alphabets: if (letter*2) in s: replaced = True s = s.replace(letter*2, "", 1) break if not replaced: break thisTurn = not thisTurn print("Yes" if thisTurn else "No") ```
instruction
0
50,537
0
101,074
No
output
1
50,537
0
101,075
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two people are playing a game with a string s, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses. Your task is to determine which player will win if both play optimally. Input The only line contains the string s, consisting of lowercase latin letters (1 ≀ |s| ≀ 100 000), where |s| means the length of a string s. Output If the first player wins, print "Yes". If the second player wins, print "No". Examples Input abacaba Output No Input iiq Output Yes Input abba Output No Note In the first example the first player is unable to make a turn, so he loses. In the second example first player turns the string into "q", then second player is unable to move, so he loses. Submitted Solution: ``` from sys import stdin input = stdin.readline s = input() s = list(s) c = 0 i = 1 while i < len(s): if len(s) <= 1: break if s[i] == s[i - 1]: c += 1 t = i - 2 y = i + 1 while 1: if t < 0 or y > len(s): i = y break if s[t] == s[y]: c += 1 t -= 1 y += 1 else: i = y break else: i += 1 if c % 2 == 0: print('No') else: print('Yes') ```
instruction
0
50,538
0
101,076
No
output
1
50,538
0
101,077
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two people are playing a game with a string s, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses. Your task is to determine which player will win if both play optimally. Input The only line contains the string s, consisting of lowercase latin letters (1 ≀ |s| ≀ 100 000), where |s| means the length of a string s. Output If the first player wins, print "Yes". If the second player wins, print "No". Examples Input abacaba Output No Input iiq Output Yes Input abba Output No Note In the first example the first player is unable to make a turn, so he loses. In the second example first player turns the string into "q", then second player is unable to move, so he loses. Submitted Solution: ``` s,k,f,h=input(),0,1,set() while f<len(s): if s[f-1]==s[f]: k+=1;m=f-2;n=f+1 h.add(m);h.add(n) if m not in h and n not in h: while m>=0 and n<len(s) and s[m]==s[n]: k+=1;m-=1;n+=1;f+=1 f+=1 print(('Yes','No')[not k%2]) ```
instruction
0
50,539
0
101,078
No
output
1
50,539
0
101,079
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si β‰  si + 1(1 ≀ i < n). 3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes. Input A single line contains two positive integers n and k (1 ≀ n ≀ 106, 1 ≀ k ≀ 26) β€” the string's length and the number of distinct letters. Output In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Examples Input 7 4 Output ababacd Input 4 7 Output -1
instruction
0
50,793
0
101,586
Tags: greedy Correct Solution: ``` import sys n, k = map(int, sys.stdin.readline().split()) if k > n or (k == 1 and n != 1): print(-1) else: l = [" " for i in range(n)] last = ord("a")+k-1 m = n-1 for i in range(k-2): l[m] = chr(last-i) m -= 1 start = ord("a") for i in range(n): if l[i] != " ": break else: l[i] = chr(start) if i % 2 == 1: start -= 1 else: start += 1 print("".join(l)) ```
output
1
50,793
0
101,587
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si β‰  si + 1(1 ≀ i < n). 3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes. Input A single line contains two positive integers n and k (1 ≀ n ≀ 106, 1 ≀ k ≀ 26) β€” the string's length and the number of distinct letters. Output In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Examples Input 7 4 Output ababacd Input 4 7 Output -1
instruction
0
50,795
0
101,590
Tags: greedy Correct Solution: ``` # coding: utf-8 letter = [chr(ord('a')+i) for i in range(26)] n, k = [int(i) for i in input().split()] if k>n or (k==1 and n>1): print(-1) exit() if k==1: print('a') exit() ans = [letter[i%2] for i in range(n-k+2)] ans += [letter[2+i] for i in range(k-2)] print(''.join(ans)) ```
output
1
50,795
0
101,591
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si β‰  si + 1(1 ≀ i < n). 3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes. Input A single line contains two positive integers n and k (1 ≀ n ≀ 106, 1 ≀ k ≀ 26) β€” the string's length and the number of distinct letters. Output In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Examples Input 7 4 Output ababacd Input 4 7 Output -1
instruction
0
50,796
0
101,592
Tags: greedy Correct Solution: ``` from string import ascii_lowercase n, k = [int(x) for x in input().split()] if n == 1 and k == 1: print('a') exit(0) if n < k or k == 1: print(-1) exit(0) print('ab' * ((n - k + 2) // 2) + ('a' if (n + k) % 2 == 1 else '') + ascii_lowercase[2: k]) ```
output
1
50,796
0
101,593
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si β‰  si + 1(1 ≀ i < n). 3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes. Input A single line contains two positive integers n and k (1 ≀ n ≀ 106, 1 ≀ k ≀ 26) β€” the string's length and the number of distinct letters. Output In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Examples Input 7 4 Output ababacd Input 4 7 Output -1
instruction
0
50,797
0
101,594
Tags: greedy Correct Solution: ``` alphabet = ["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"] string = input() numbers = string.split() a, b = int(numbers[0]), int(numbers[1]) condition = a > 1 and b == 1 if b > a or condition: print(-1) else: if a == 1: s = "a" else: s = "" for x in range(a - b + 2): s += alphabet[x % 2] for x in range(2, b): s += alphabet[x] print(s) ```
output
1
50,797
0
101,595
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si β‰  si + 1(1 ≀ i < n). 3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes. Input A single line contains two positive integers n and k (1 ≀ n ≀ 106, 1 ≀ k ≀ 26) β€” the string's length and the number of distinct letters. Output In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Examples Input 7 4 Output ababacd Input 4 7 Output -1
instruction
0
50,798
0
101,596
Tags: greedy Correct Solution: ``` n,k=map(int,input().split()) if k>n: print(-1) elif k==1: if n==1: print('a') else: print(-1) else: alph="" for i in range(26): alph+=(chr(i+97)) ans=alph[:k] n-=k if n%2: z=ans[0]+ans[1]+'ab'*(n//2)+'a'+ans[2:] else: z=ans[0]+ans[1]+'ab'*(n//2)+ans[2:] print(z) ```
output
1
50,798
0
101,597
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si β‰  si + 1(1 ≀ i < n). 3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes. Input A single line contains two positive integers n and k (1 ≀ n ≀ 106, 1 ≀ k ≀ 26) β€” the string's length and the number of distinct letters. Output In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Examples Input 7 4 Output ababacd Input 4 7 Output -1
instruction
0
50,799
0
101,598
Tags: greedy Correct Solution: ``` import sys import math n, k = [int(x) for x in (sys.stdin.readline()).split()] if(k == 1 and n == 1): print("a") exit() if(k == 1 or k > n): print(-1) exit() res = ['a', 'b'] * (int(n / 2)) if(n % 2 != 0): res.append('a') t = 2 for i in range(n - (k - 2), n): res[i] = (chr(t + 97)) t += 1 """t = 2 for i in range(n): if(n - (k - 2) > i): if(i % 2 == 0): res.append('a') else: res.append('b') else: res.append(chr(t + 97)) t += 1""" print("".join(res)) ```
output
1
50,799
0
101,599
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si β‰  si + 1(1 ≀ i < n). 3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes. Input A single line contains two positive integers n and k (1 ≀ n ≀ 106, 1 ≀ k ≀ 26) β€” the string's length and the number of distinct letters. Output In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Examples Input 7 4 Output ababacd Input 4 7 Output -1 Submitted Solution: ``` import sys import math n, k = [int(x) for x in (sys.stdin.readline()).split()] if(k == 1 and n == 1): print("a") exit() if(k == 1 or k > n): print(-1) exit() res = [] t = 2 for i in range(n): if(n - (k - 2) > i): if(i % 2 == 0): res.append('a') else: res.append('b') else: res.append(chr(t + 97)) t += 1 print("".join(res)) ```
instruction
0
50,800
0
101,600
Yes
output
1
50,800
0
101,601
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si β‰  si + 1(1 ≀ i < n). 3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes. Input A single line contains two positive integers n and k (1 ≀ n ≀ 106, 1 ≀ k ≀ 26) β€” the string's length and the number of distinct letters. Output In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Examples Input 7 4 Output ababacd Input 4 7 Output -1 Submitted Solution: ``` # single inheritance a,b=map(int,input().split()) s="cdefghijklmnopqrstuvwxyz" if(b>a or (b==1 and a!=1)): print(-1) else: if(a==1 and b==1): print("a") exit() if(a-b)%2!=0: q=("ab")*((a-b+2)//2) q=q+"a" for g in range(b-2): q=q+s[g] else: q = ("ab") * ((a - b + 2) // 2) for g in range(b-2): q=q+s[g] print(q) ```
instruction
0
50,801
0
101,602
Yes
output
1
50,801
0
101,603
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si β‰  si + 1(1 ≀ i < n). 3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes. Input A single line contains two positive integers n and k (1 ≀ n ≀ 106, 1 ≀ k ≀ 26) β€” the string's length and the number of distinct letters. Output In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Examples Input 7 4 Output ababacd Input 4 7 Output -1 Submitted Solution: ``` n,k=map(int, input().split()) if(n==1 and k==1): print('a') elif(k>n or k==1): print(-1) elif(k==2): s="" if(n%2==0): s=['a','b']*(n//2) else: s=['a','b']*(n//2) s.append('a') ans="".join(s) print(ans) elif(k==n): s="" for i in range(n): s=s+chr(i+97) print(s) else: s=[] k=k-2 rem=n-k if(rem%2==0): s=['a','b']*(rem//2) else: s=['a','b']*(rem//2) s.append('a') j=0 for i in range(n-k,n): s.append(chr(j+99)) j+=1 ans="".join(s) print(ans) ```
instruction
0
50,802
0
101,604
Yes
output
1
50,802
0
101,605
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si β‰  si + 1(1 ≀ i < n). 3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes. Input A single line contains two positive integers n and k (1 ≀ n ≀ 106, 1 ≀ k ≀ 26) β€” the string's length and the number of distinct letters. Output In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Examples Input 7 4 Output ababacd Input 4 7 Output -1 Submitted Solution: ``` X = list(map(int, input().split())) Temp = "".join([chr(ord("a") + i) for i in range(X[1])]) if X[1] == 1 and X[0] == 1: print("a") elif X[1] > X[0] or X[1] == 1: print(-1) else: print("ab" * ((X[0] - X[1] + 2) // 2) + "a" * ((X[0] - X[1] + 2) % 2) + Temp[2:]) # Hope the best for Ravens # Never give up ```
instruction
0
50,803
0
101,606
Yes
output
1
50,803
0
101,607
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si β‰  si + 1(1 ≀ i < n). 3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes. Input A single line contains two positive integers n and k (1 ≀ n ≀ 106, 1 ≀ k ≀ 26) β€” the string's length and the number of distinct letters. Output In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Examples Input 7 4 Output ababacd Input 4 7 Output -1 Submitted Solution: ``` n, k = list(map(int, input().split())) if k > n: print(-1) elif k == 1: print('a'*n) elif k == 2: print(('ab'*n)[:n]) else: al = sorted('qwertyuiopasdfghjklzxcvbnm') k -= 2 tail = ''.join(al[2:2+k]) #print(tail) left = n-k head = ('ab' * left)[:left] s = head + tail print(s) ```
instruction
0
50,804
0
101,608
No
output
1
50,804
0
101,609
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si β‰  si + 1(1 ≀ i < n). 3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes. Input A single line contains two positive integers n and k (1 ≀ n ≀ 106, 1 ≀ k ≀ 26) β€” the string's length and the number of distinct letters. Output In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Examples Input 7 4 Output ababacd Input 4 7 Output -1 Submitted Solution: ``` n, k = list(map(int, input().split())) if k > n: print(-1) if k == 1: print('a'*n) elif k == 2: print(('ab'*n)[:n]) else: al = sorted('qwertyuiopasdfghjklzxcvbnm') k -= 2 tail = ''.join(al[2:2+k]) #print(tail) left = n-k head = ('ab' * left)[:left] s = head + tail print(s) ```
instruction
0
50,805
0
101,610
No
output
1
50,805
0
101,611
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si β‰  si + 1(1 ≀ i < n). 3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes. Input A single line contains two positive integers n and k (1 ≀ n ≀ 106, 1 ≀ k ≀ 26) β€” the string's length and the number of distinct letters. Output In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Examples Input 7 4 Output ababacd Input 4 7 Output -1 Submitted Solution: ``` import sys (n,k)=map(int,sys.stdin.readline().split()) if k==1 or k>n: print(-1) else: tmp=n-k+2 s="ab"*(tmp//2) if tmp%2==1: s+="a" for i in range(2,k): s+=chr(ord('a')+i) print (s) ```
instruction
0
50,806
0
101,612
No
output
1
50,806
0
101,613
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct. 2. No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si β‰  si + 1(1 ≀ i < n). 3. Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist. String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes. Input A single line contains two positive integers n and k (1 ≀ n ≀ 106, 1 ≀ k ≀ 26) β€” the string's length and the number of distinct letters. Output In a single line print the required string. If there isn't such string, print "-1" (without the quotes). Examples Input 7 4 Output ababacd Input 4 7 Output -1 Submitted Solution: ``` li=list(map(int,input().split())) n=li[0] k=li[1] s="" if k>n: print(-1) else: if n-k==0: for i in range(97,97+k): s+=chr(i) else: for i in range(n-(k-2)): if i%2==0: s+=chr(97) else: s+=chr(98) if n!=k: for i in range(99,99+(k-2)): s+=chr(i) print(s) ```
instruction
0
50,807
0
101,614
No
output
1
50,807
0
101,615
Provide tags and a correct Python 3 solution for this coding contest problem. And where the are the phone numbers? You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s is lexicographically smaller than t. It's guaranteed that the answer exists. Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {a, b, d}. String p is lexicographically smaller than string q, if p is a prefix of q, is not equal to q or there exists i, such that pi < qi and for all j < i it is satisfied that pj = qj. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a. Input The first line of input contains two space separated integers n and k (1 ≀ n, k ≀ 100 000) β€” the length of s and the required length of t. The second line of input contains the string s consisting of n lowercase English letters. Output Output the string t conforming to the requirements above. It's guaranteed that the answer exists. Examples Input 3 3 abc Output aca Input 3 2 abc Output ac Input 3 3 ayy Output yaa Input 2 3 ba Output baa Note In the first example the list of strings t of length 3, such that the set of letters of t is a subset of letters of s is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca.
instruction
0
51,043
0
102,086
Tags: constructive algorithms, implementation, strings Correct Solution: ``` def f(s,k,n): l=sorted(list(set(s))) if len(s)<k: return s+l[0]*(k-len(s)) s=s[:k] ll=len(l) t="" kk=k for i in range(len(s)-1,-1,-1): # print(t,"sss",len(t)) if l.index(s[i])!=ll-1: t=l[l.index(s[i])+1]+t break else: if k>=i+1: t=l[0]+t if len(t)==k: break t=s[:k-len(t)]+t return t n,k=map(int,input().strip().split()) s=input().strip() print(f(s,k,n)) ```
output
1
51,043
0
102,087
Provide tags and a correct Python 3 solution for this coding contest problem. And where the are the phone numbers? You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s is lexicographically smaller than t. It's guaranteed that the answer exists. Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {a, b, d}. String p is lexicographically smaller than string q, if p is a prefix of q, is not equal to q or there exists i, such that pi < qi and for all j < i it is satisfied that pj = qj. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a. Input The first line of input contains two space separated integers n and k (1 ≀ n, k ≀ 100 000) β€” the length of s and the required length of t. The second line of input contains the string s consisting of n lowercase English letters. Output Output the string t conforming to the requirements above. It's guaranteed that the answer exists. Examples Input 3 3 abc Output aca Input 3 2 abc Output ac Input 3 3 ayy Output yaa Input 2 3 ba Output baa Note In the first example the list of strings t of length 3, such that the set of letters of t is a subset of letters of s is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca.
instruction
0
51,044
0
102,088
Tags: constructive algorithms, implementation, strings Correct Solution: ``` n, k = list(map(int, input().split())) s = input()[:n] digs = set(s) mind = min(digs) maxd = max(digs) if n<k: print (s+mind*(k-n)) exit() for i in range(min(n,k)-1, -1, -1): if s[i]<maxd: biggerchars = [ch for ch in digs if ch > s[i]] bestchar = min(biggerchars) res = s[:i] + bestchar + mind*(k-1-i) print (res) exit() print(maxd*k) ```
output
1
51,044
0
102,089
Provide tags and a correct Python 3 solution for this coding contest problem. And where the are the phone numbers? You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s is lexicographically smaller than t. It's guaranteed that the answer exists. Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {a, b, d}. String p is lexicographically smaller than string q, if p is a prefix of q, is not equal to q or there exists i, such that pi < qi and for all j < i it is satisfied that pj = qj. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a. Input The first line of input contains two space separated integers n and k (1 ≀ n, k ≀ 100 000) β€” the length of s and the required length of t. The second line of input contains the string s consisting of n lowercase English letters. Output Output the string t conforming to the requirements above. It's guaranteed that the answer exists. Examples Input 3 3 abc Output aca Input 3 2 abc Output ac Input 3 3 ayy Output yaa Input 2 3 ba Output baa Note In the first example the list of strings t of length 3, such that the set of letters of t is a subset of letters of s is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca.
instruction
0
51,045
0
102,090
Tags: constructive algorithms, implementation, strings Correct Solution: ``` n,k=map(int,input().split()) s=input() l=sorted(list(set(list(s)))) if k<=n: for i in range(k-1,-1,-1): z=[] for j in l: if s[i]<j: z.append(j) if len(z)>0: z.sort() t=s[:i]+z[0]+l[0]*(k-i-1) break else: t=s+(k-n)*l[0] print(t) ```
output
1
51,045
0
102,091
Provide tags and a correct Python 3 solution for this coding contest problem. And where the are the phone numbers? You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s is lexicographically smaller than t. It's guaranteed that the answer exists. Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {a, b, d}. String p is lexicographically smaller than string q, if p is a prefix of q, is not equal to q or there exists i, such that pi < qi and for all j < i it is satisfied that pj = qj. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a. Input The first line of input contains two space separated integers n and k (1 ≀ n, k ≀ 100 000) β€” the length of s and the required length of t. The second line of input contains the string s consisting of n lowercase English letters. Output Output the string t conforming to the requirements above. It's guaranteed that the answer exists. Examples Input 3 3 abc Output aca Input 3 2 abc Output ac Input 3 3 ayy Output yaa Input 2 3 ba Output baa Note In the first example the list of strings t of length 3, such that the set of letters of t is a subset of letters of s is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca.
instruction
0
51,046
0
102,092
Tags: constructive algorithms, implementation, strings Correct Solution: ``` def solve(): n, k = map(int, input().split()) S = input() L = list(set(list(map(ord,S)))) L.sort() I = {} for i, l in enumerate(L): I[l] = i first = L[0] last = L[-1] res = "" if k > n: res += S res += chr(first)*(k-n) print(res) return else: for i in reversed(range(k)): if ord(S[i]) < last: remained = L[I[ord(S[i])] + 1] res += S[:i] res += chr(remained) res += chr(first) * (k-i-1) print(res) return if __name__ == "__main__": solve() ```
output
1
51,046
0
102,093
Provide tags and a correct Python 3 solution for this coding contest problem. And where the are the phone numbers? You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s is lexicographically smaller than t. It's guaranteed that the answer exists. Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {a, b, d}. String p is lexicographically smaller than string q, if p is a prefix of q, is not equal to q or there exists i, such that pi < qi and for all j < i it is satisfied that pj = qj. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a. Input The first line of input contains two space separated integers n and k (1 ≀ n, k ≀ 100 000) β€” the length of s and the required length of t. The second line of input contains the string s consisting of n lowercase English letters. Output Output the string t conforming to the requirements above. It's guaranteed that the answer exists. Examples Input 3 3 abc Output aca Input 3 2 abc Output ac Input 3 3 ayy Output yaa Input 2 3 ba Output baa Note In the first example the list of strings t of length 3, such that the set of letters of t is a subset of letters of s is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca.
instruction
0
51,047
0
102,094
Tags: constructive algorithms, implementation, strings Correct Solution: ``` a,b = map(int,input().split()) s = input() f = s[::-1] cn = 0 d = sorted(set(s)) l = list(d) ans = "" if b>a: print(s+d[0]*(b-a)) else: for i in range(1,b+1): if s[b-i]==d[-1]: ans+=d[0] cn+=1 else: # print(l[l.index(s[b-i])+1]) ans+=l[l.index(s[b-i])+1] break print(s[0:b-cn-1]+ans[::-1]) ```
output
1
51,047
0
102,095
Provide tags and a correct Python 3 solution for this coding contest problem. And where the are the phone numbers? You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s is lexicographically smaller than t. It's guaranteed that the answer exists. Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {a, b, d}. String p is lexicographically smaller than string q, if p is a prefix of q, is not equal to q or there exists i, such that pi < qi and for all j < i it is satisfied that pj = qj. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a. Input The first line of input contains two space separated integers n and k (1 ≀ n, k ≀ 100 000) β€” the length of s and the required length of t. The second line of input contains the string s consisting of n lowercase English letters. Output Output the string t conforming to the requirements above. It's guaranteed that the answer exists. Examples Input 3 3 abc Output aca Input 3 2 abc Output ac Input 3 3 ayy Output yaa Input 2 3 ba Output baa Note In the first example the list of strings t of length 3, such that the set of letters of t is a subset of letters of s is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca.
instruction
0
51,048
0
102,096
Tags: constructive algorithms, implementation, strings Correct Solution: ``` n,k = map(int,input().split()) s = list(input()) aa='abcdefghijklmnopqrstuvwxyz' has=[0]*26 for i in s: has[ord(i)-ord('a')]=1 if k>n: i=0 while has[i]==0: i+=1 ans=''.join(s) + (k-n)*(aa[i]) print(ans) exit() j=0 m = k ans=s[:m] for i in range(m-1,-1,-1): kk=ord(s[i])-ord('a') j=(kk+1)%26 while has[j]==0: j=(j+1)%26 ans[i]=aa[j] if j>kk: break ans=''.join(ans) print(ans) ```
output
1
51,048
0
102,097
Provide tags and a correct Python 3 solution for this coding contest problem. And where the are the phone numbers? You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s is lexicographically smaller than t. It's guaranteed that the answer exists. Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {a, b, d}. String p is lexicographically smaller than string q, if p is a prefix of q, is not equal to q or there exists i, such that pi < qi and for all j < i it is satisfied that pj = qj. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a. Input The first line of input contains two space separated integers n and k (1 ≀ n, k ≀ 100 000) β€” the length of s and the required length of t. The second line of input contains the string s consisting of n lowercase English letters. Output Output the string t conforming to the requirements above. It's guaranteed that the answer exists. Examples Input 3 3 abc Output aca Input 3 2 abc Output ac Input 3 3 ayy Output yaa Input 2 3 ba Output baa Note In the first example the list of strings t of length 3, such that the set of letters of t is a subset of letters of s is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca.
instruction
0
51,049
0
102,098
Tags: constructive algorithms, implementation, strings Correct Solution: ``` n,k = map(int,input().split(" ")) s = list(input()) s1 = s[:] s2 = sorted(list(set(s))) if k == 1: for ch in s2: if s1[0] < ch: print(ch) exit(0) if n < k: s1.extend([s2[0]]*(k-n)) t = "".join(s1) print(t) else: for i in range(k-1,-1,-1): if s1[i] != s2[-1]: ans = s1[:i] ans.append(s2[s2.index(s1[i])+1]) ans.extend([s2[0]]*(k-i-1)) print("".join(ans)) exit(0) ```
output
1
51,049
0
102,099
Provide tags and a correct Python 3 solution for this coding contest problem. And where the are the phone numbers? You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s is lexicographically smaller than t. It's guaranteed that the answer exists. Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {a, b, d}. String p is lexicographically smaller than string q, if p is a prefix of q, is not equal to q or there exists i, such that pi < qi and for all j < i it is satisfied that pj = qj. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a. Input The first line of input contains two space separated integers n and k (1 ≀ n, k ≀ 100 000) β€” the length of s and the required length of t. The second line of input contains the string s consisting of n lowercase English letters. Output Output the string t conforming to the requirements above. It's guaranteed that the answer exists. Examples Input 3 3 abc Output aca Input 3 2 abc Output ac Input 3 3 ayy Output yaa Input 2 3 ba Output baa Note In the first example the list of strings t of length 3, such that the set of letters of t is a subset of letters of s is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca.
instruction
0
51,050
0
102,100
Tags: constructive algorithms, implementation, strings Correct Solution: ``` def run(): n, k = map(int, input().split()) s = input() s_sorted = sorted(set(s)) big = s_sorted[-1] small = s_sorted[0] if k > n: t = s + ''.join([small] * (k - n)) else: if len(s) == 1: t = s else: to_replace = big ind_replace = 0 for i in range(k-1, -1, -1): if s[i] == big: continue else: to_replace = s[i] ind_replace = i break ind = s_sorted.index(to_replace) ind += 1 t = s[:ind_replace] + s_sorted[ind] + ''.join([small]*(k - ind_replace - 1)) print(t) if __name__ == '__main__': run() ```
output
1
51,050
0
102,101
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. And where the are the phone numbers? You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s is lexicographically smaller than t. It's guaranteed that the answer exists. Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {a, b, d}. String p is lexicographically smaller than string q, if p is a prefix of q, is not equal to q or there exists i, such that pi < qi and for all j < i it is satisfied that pj = qj. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a. Input The first line of input contains two space separated integers n and k (1 ≀ n, k ≀ 100 000) β€” the length of s and the required length of t. The second line of input contains the string s consisting of n lowercase English letters. Output Output the string t conforming to the requirements above. It's guaranteed that the answer exists. Examples Input 3 3 abc Output aca Input 3 2 abc Output ac Input 3 3 ayy Output yaa Input 2 3 ba Output baa Note In the first example the list of strings t of length 3, such that the set of letters of t is a subset of letters of s is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca. Submitted Solution: ``` def f(s,k,n): l=sorted(list(set(s))) if len(s)<k: return s+l[0]*(k-len(s)) s=s[:k] ll=len(l) t="" # print(l,s) kk=k for i in range(len(s)-1,-1,-1): # print(t,"sss",len(t)) if l.index(s[i])!=ll-1: t=l[l.index(s[i])+1]+t break else: if k>=i+1: t=l[0]+t if len(t)==k: break t=s[:k-len(t)]+t if t<=s: # t=list(s[:k]) t=l[l.index(s[0])+1]+l[0]*(k-1) return t n,k=map(int,input().strip().split()) s=input().strip() print(f(s,k,n)) ```
instruction
0
51,051
0
102,102
Yes
output
1
51,051
0
102,103
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. And where the are the phone numbers? You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s is lexicographically smaller than t. It's guaranteed that the answer exists. Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {a, b, d}. String p is lexicographically smaller than string q, if p is a prefix of q, is not equal to q or there exists i, such that pi < qi and for all j < i it is satisfied that pj = qj. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a. Input The first line of input contains two space separated integers n and k (1 ≀ n, k ≀ 100 000) β€” the length of s and the required length of t. The second line of input contains the string s consisting of n lowercase English letters. Output Output the string t conforming to the requirements above. It's guaranteed that the answer exists. Examples Input 3 3 abc Output aca Input 3 2 abc Output ac Input 3 3 ayy Output yaa Input 2 3 ba Output baa Note In the first example the list of strings t of length 3, such that the set of letters of t is a subset of letters of s is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca. Submitted Solution: ``` raw = [int(x) for x in input().split(' ')] k = raw[1] instr = input() letters = [] for l in instr: if l not in letters: letters.append(l) letters.sort() if k <= len(instr): for i in range(k-1,-1,-1): if instr[i] != letters[-1]: repl = instr[:i]+letters[letters.index(instr[i])+1]+(k-i-1)*letters[0] break else: repl = instr+(k-len(instr))*letters[0] print(repl) ```
instruction
0
51,052
0
102,104
Yes
output
1
51,052
0
102,105
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. And where the are the phone numbers? You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s is lexicographically smaller than t. It's guaranteed that the answer exists. Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {a, b, d}. String p is lexicographically smaller than string q, if p is a prefix of q, is not equal to q or there exists i, such that pi < qi and for all j < i it is satisfied that pj = qj. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a. Input The first line of input contains two space separated integers n and k (1 ≀ n, k ≀ 100 000) β€” the length of s and the required length of t. The second line of input contains the string s consisting of n lowercase English letters. Output Output the string t conforming to the requirements above. It's guaranteed that the answer exists. Examples Input 3 3 abc Output aca Input 3 2 abc Output ac Input 3 3 ayy Output yaa Input 2 3 ba Output baa Note In the first example the list of strings t of length 3, such that the set of letters of t is a subset of letters of s is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca. Submitted Solution: ``` def run(): n, k = [int(x) for x in input().split()] s = input() cs = sorted(set(s)) kcs = {c: i for i, c in enumerate(cs)} # print(kcs);return # print(cs) if k > len(s): print(s + (cs[0] * (k - len(s)))) return s = s[:k] nr = [kcs[x] for x in s] ptr = k-1 while True: if nr[ptr] < len(cs)-1: nr[ptr] += 1 break nr[ptr] = 0 ptr-=1 print(''.join((cs[x] for x in nr))) run() ```
instruction
0
51,053
0
102,106
Yes
output
1
51,053
0
102,107
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. And where the are the phone numbers? You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s is lexicographically smaller than t. It's guaranteed that the answer exists. Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {a, b, d}. String p is lexicographically smaller than string q, if p is a prefix of q, is not equal to q or there exists i, such that pi < qi and for all j < i it is satisfied that pj = qj. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a. Input The first line of input contains two space separated integers n and k (1 ≀ n, k ≀ 100 000) β€” the length of s and the required length of t. The second line of input contains the string s consisting of n lowercase English letters. Output Output the string t conforming to the requirements above. It's guaranteed that the answer exists. Examples Input 3 3 abc Output aca Input 3 2 abc Output ac Input 3 3 ayy Output yaa Input 2 3 ba Output baa Note In the first example the list of strings t of length 3, such that the set of letters of t is a subset of letters of s is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca. Submitted Solution: ``` def main(): (n, k) = map(int, input().split()) s = input() letters = [ord(c) for c in set(s)] letters.sort() if(n < k): print(s+chr(letters[0])*(k-n)) return t = bytearray(s[:k].encode()) for i in range(k-1, -1, -1): if t[i] == letters[-1]: t[i] = letters[0] else: t[i] = letters[letters.index(t[i])+1] break print(t.decode()) main() ```
instruction
0
51,054
0
102,108
Yes
output
1
51,054
0
102,109