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. You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones. Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a. You can apply the following operations any number of times: * Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»); * Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones? Input The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string a of length n, consisting of zeros and ones. Output Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations. Examples Input 5 1 10 01000 Output 11 Input 5 10 1 01000 Output 2 Input 7 2 3 1111111 Output 0 Note In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5]. Then the string was changed as follows: «01000» → «10000» → «11111». The total cost of operations is 1 + 10 = 11. In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5]. Then the string was changed as follows: «01000» → «11000» → «11111». The overall cost is 1 + 1 = 2. In the third example, string already consists only of ones, so the answer is 0.
instruction
0
50,255
0
100,510
Tags: brute force, greedy, implementation, math Correct Solution: ``` [n, x, y] = [int(x) for x in input().split()] A = input() if len(A) == 1: if A[0] == "1": print("0") else: print(y) else: c = 0 if A[0] == "0": c = 1 for i in range(1, len(A)): if A[i] == "0" and A[i-1] == "1": c += 1 m = y*c for i in range(1, c): temp = x*i + y*(c-i) if temp < m: m = temp print(m) ```
output
1
50,255
0
100,511
Provide tags and a correct Python 3 solution for this coding contest problem. You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones. Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a. You can apply the following operations any number of times: * Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»); * Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones? Input The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string a of length n, consisting of zeros and ones. Output Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations. Examples Input 5 1 10 01000 Output 11 Input 5 10 1 01000 Output 2 Input 7 2 3 1111111 Output 0 Note In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5]. Then the string was changed as follows: «01000» → «10000» → «11111». The total cost of operations is 1 + 10 = 11. In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5]. Then the string was changed as follows: «01000» → «11000» → «11111». The overall cost is 1 + 1 = 2. In the third example, string already consists only of ones, so the answer is 0.
instruction
0
50,256
0
100,512
Tags: brute force, greedy, implementation, math Correct Solution: ``` n,x,y=map(int,input().strip().split()) count=0 r=input() if r[0]=="0": count=count+1 for i in range(1,n): if r[i]=="0" and r[i-1]!="0": count=count+1 if count==0: print (0) exit(0) else: if y<x: print (y*count) else: print (x*(count-1)+y) ```
output
1
50,256
0
100,513
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones. Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a. You can apply the following operations any number of times: * Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»); * Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones? Input The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string a of length n, consisting of zeros and ones. Output Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations. Examples Input 5 1 10 01000 Output 11 Input 5 10 1 01000 Output 2 Input 7 2 3 1111111 Output 0 Note In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5]. Then the string was changed as follows: «01000» → «10000» → «11111». The total cost of operations is 1 + 10 = 11. In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5]. Then the string was changed as follows: «01000» → «11000» → «11111». The overall cost is 1 + 1 = 2. In the third example, string already consists only of ones, so the answer is 0. Submitted Solution: ``` n,x,y=map(int,input().split()) s=input() sl=[] for i in s: sl+=[int(i)] sl.append(1) count=0 for i in range(n): if sl[i]==0 and sl[i+1]==1 : count+=1 if count!=0: print(y+min(x,y)*(count-1)) else: print("0") ```
instruction
0
50,257
0
100,514
Yes
output
1
50,257
0
100,515
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones. Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a. You can apply the following operations any number of times: * Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»); * Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones? Input The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string a of length n, consisting of zeros and ones. Output Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations. Examples Input 5 1 10 01000 Output 11 Input 5 10 1 01000 Output 2 Input 7 2 3 1111111 Output 0 Note In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5]. Then the string was changed as follows: «01000» → «10000» → «11111». The total cost of operations is 1 + 10 = 11. In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5]. Then the string was changed as follows: «01000» → «11000» → «11111». The overall cost is 1 + 1 = 2. In the third example, string already consists only of ones, so the answer is 0. Submitted Solution: ``` def f(reverse_cost, inverse_cost, bit_string): prev_value = True zero_section_count = 0 for v in bit_string: cur_value = bool(v == "1") if prev_value != cur_value: if not cur_value: zero_section_count += 1 prev_value = cur_value if zero_section_count: return min(reverse_cost, inverse_cost) * (zero_section_count - 1) + inverse_cost else: return 0 n, x, y = [int(i) for i in input().split()] s = input() print(f(x, y, s)) ```
instruction
0
50,258
0
100,516
Yes
output
1
50,258
0
100,517
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones. Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a. You can apply the following operations any number of times: * Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»); * Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones? Input The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string a of length n, consisting of zeros and ones. Output Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations. Examples Input 5 1 10 01000 Output 11 Input 5 10 1 01000 Output 2 Input 7 2 3 1111111 Output 0 Note In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5]. Then the string was changed as follows: «01000» → «10000» → «11111». The total cost of operations is 1 + 10 = 11. In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5]. Then the string was changed as follows: «01000» → «11000» → «11111». The overall cost is 1 + 1 = 2. In the third example, string already consists only of ones, so the answer is 0. Submitted Solution: ``` N,x,y = input().split() x=int(x) y=int(y) array=input() the_list=array.split('1') length=len(the_list) for k in the_list: if k=='': length-=1 if length==0: print(0) elif x<y: print((length-1)*x+y) else: print((length)*y) ```
instruction
0
50,259
0
100,518
Yes
output
1
50,259
0
100,519
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones. Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a. You can apply the following operations any number of times: * Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»); * Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones? Input The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string a of length n, consisting of zeros and ones. Output Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations. Examples Input 5 1 10 01000 Output 11 Input 5 10 1 01000 Output 2 Input 7 2 3 1111111 Output 0 Note In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5]. Then the string was changed as follows: «01000» → «10000» → «11111». The total cost of operations is 1 + 10 = 11. In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5]. Then the string was changed as follows: «01000» → «11000» → «11111». The overall cost is 1 + 1 = 2. In the third example, string already consists only of ones, so the answer is 0. Submitted Solution: ``` n, x, y = map(int, input().split(" ")) s = input() isolated = 0 ones = 0 last = "1" for digit in s: if digit == "1" and last == "0": isolated += 1 if digit == "0": ones += 1 last = digit if last == "0": isolated += 1 if ones == 0: print(0) else: print(min(isolated * y, (isolated - 1) * x + y)) ```
instruction
0
50,260
0
100,520
Yes
output
1
50,260
0
100,521
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones. Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a. You can apply the following operations any number of times: * Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»); * Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones? Input The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string a of length n, consisting of zeros and ones. Output Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations. Examples Input 5 1 10 01000 Output 11 Input 5 10 1 01000 Output 2 Input 7 2 3 1111111 Output 0 Note In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5]. Then the string was changed as follows: «01000» → «10000» → «11111». The total cost of operations is 1 + 10 = 11. In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5]. Then the string was changed as follows: «01000» → «11000» → «11111». The overall cost is 1 + 1 = 2. In the third example, string already consists only of ones, so the answer is 0. Submitted Solution: ``` ''' CODED WITH LOVE BY SATYAM KUMAR ''' from sys import stdin, stdout import cProfile, math from collections import Counter from bisect import bisect_left,bisect,bisect_right import itertools from copy import deepcopy from fractions import Fraction import sys, threading import operator as op from functools import reduce sys.setrecursionlimit(10**6) # max depth of recursion threading.stack_size(2**27) # new thread will get stack of such size fac_warmup = False printHeap = str() memory_constrained = False P = 10**9+7 import sys class Operation: def __init__(self, name, function, function_on_equal, neutral_value=0): self.name = name self.f = function self.f_on_equal = function_on_equal def add_multiple(x, count): return x * count def min_multiple(x, count): return x def max_multiple(x, count): return x sum_operation = Operation("sum", sum, add_multiple, 0) min_operation = Operation("min", min, min_multiple, 1e9) max_operation = Operation("max", max, max_multiple, -1e9) class SegmentTree: def __init__(self, array, operations=[sum_operation, min_operation, max_operation]): self.array = array if type(operations) != list: raise TypeError("operations must be a list") self.operations = {} for op in operations: self.operations[op.name] = op self.root = SegmentTreeNode(0, len(array) - 1, self) def query(self, start, end, operation_name): if self.operations.get(operation_name) == None: raise Exception("This operation is not available") return self.root._query(start, end, self.operations[operation_name]) def summary(self): return self.root.values def update(self, position, value): self.root._update(position, value) def update_range(self, start, end, value): self.root._update_range(start, end, value) def __repr__(self): return self.root.__repr__() class SegmentTreeNode: def __init__(self, start, end, segment_tree): self.range = (start, end) self.parent_tree = segment_tree self.range_value = None self.values = {} self.left = None self.right = None if start == end: self._sync() return self.left = SegmentTreeNode(start, start + (end - start) // 2, segment_tree) self.right = SegmentTreeNode(start + (end - start) // 2 + 1, end, segment_tree) self._sync() def _query(self, start, end, operation): if end < self.range[0] or start > self.range[1]: return None if start <= self.range[0] and self.range[1] <= end: return self.values[operation.name] self._push() left_res = self.left._query(start, end, operation) if self.left else None right_res = self.right._query(start, end, operation) if self.right else None if left_res is None: return right_res if right_res is None: return left_res return operation.f([left_res, right_res]) def _update(self, position, value): if position < self.range[0] or position > self.range[1]: return if position == self.range[0] and self.range[1] == position: self.parent_tree.array[position] = value self._sync() return self._push() self.left._update(position, value) self.right._update(position, value) self._sync() def _update_range(self, start, end, value): if end < self.range[0] or start > self.range[1]: return if start <= self.range[0] and self.range[1] <= end: self.range_value = value self._sync() return self._push() self.left._update_range(start, end, value) self.right._update_range(start, end, value) self._sync() def _sync(self): if self.range[0] == self.range[1]: for op in self.parent_tree.operations.values(): current_value = self.parent_tree.array[self.range[0]] if self.range_value is not None: current_value = self.range_value self.values[op.name] = op.f([current_value]) else: for op in self.parent_tree.operations.values(): result = op.f( [self.left.values[op.name], self.right.values[op.name]]) if self.range_value is not None: bound_length = self.range[1] - self.range[0] + 1 result = op.f_on_equal(self.range_value, bound_length) self.values[op.name] = result def _push(self): if self.range_value is None: return if self.left: self.left.range_value = self.range_value self.right.range_value = self.range_value self.left._sync() self.right._sync() self.range_value = None def __repr__(self): ans = "({}, {}): {}\n".format(self.range[0], self.range[1], self.values) if self.left: ans += self.left.__repr__() if self.right: ans += self.right.__repr__() return ans def display(string_to_print): stdout.write(str(string_to_print) + "\n") def primeFactors(n): #n**0.5 complex factors = dict() for i in range(2,math.ceil(math.sqrt(n))+1): while n % i== 0: if i in factors: factors[i]+=1 else: factors[i]=1 n = n // i if n>2: factors[n]=1 return (factors) def binary(n,digits = 20): b = bin(n)[2:] b = '0'*(20-len(b))+b return b def isprime(n): """Returns True if n is prime.""" if n < 4: return True if n % 2 == 0: return False if n % 3 == 0: return False i = 5 w = 2 while i * i <= n: if n % i == 0: return False i += w w = 6 - w return True factorial_modP = [] def warm_up_fac(MOD): global factorial_modP,fac_warmup if fac_warmup: return factorial_modP= [1 for _ in range(fac_warmup_size+1)] for i in range(2,fac_warmup_size): factorial_modP[i]= (factorial_modP[i-1]*i) % MOD fac_warmup = True def InverseEuler(n,MOD): return pow(n,MOD-2,MOD) def nCr(n, r, MOD): global fac_warmup,factorial_modP if not fac_warmup: warm_up_fac(MOD) fac_warmup = True return (factorial_modP[n]*((pow(factorial_modP[r], MOD-2, MOD) * pow(factorial_modP[n-r], MOD-2, MOD)) % MOD)) % MOD def test_print(*args): if testingMode: print(args) def display_list(list1, sep=" "): stdout.write(sep.join(map(str, list1)) + "\n") def get_int(): return int(stdin.readline().strip()) def get_tuple(): return map(int, stdin.readline().split()) def get_list(): return list(map(int, stdin.readline().split())) import heapq,itertools pq = [] # list of entries arranged in a heap entry_finder = {} # mapping of tasks to entries REMOVED = '<removed-task>' def add_task(task, priority=0): 'Add a new task or update the priority of an existing task' if task in entry_finder: remove_task(task) count = next(counter) entry = [priority, count, task] entry_finder[task] = entry heapq.heappush(pq, entry) def remove_task(task): 'Mark an existing task as REMOVED. Raise KeyError if not found.' entry = entry_finder.pop(task) entry[-1] = REMOVED def pop_task(): 'Remove and return the lowest priority task. Raise KeyError if empty.' while pq: priority, count, task = heapq.heappop(pq) if task is not REMOVED: del entry_finder[task] return task raise KeyError('pop from an empty priority queue') memory = dict() def clear_cache(): global memory memory = dict() def cached_fn(fn, *args): global memory if args in memory: return memory[args] else: result = fn(*args) memory[args] = result return result # -------------------------------------------------------------- MAIN PROGRAM TestCases = False testingMode = False fac_warmup_size = 10**5+100 optimiseForReccursion = True #Can not be used clubbed with TestCases def binary_serach(i,li): #print("Search for ",i) fn = lambda x: li[x]-x//i x = -1 b = len(li) while b>=1: #print(b,x) while b+x<len(li) and fn(b+x)>0: x+=b b=b//2 return x def bs(front,end,i): global li,n mid = (front+end)//2 print(mid,flush = True) stdout.flush() x = get_int()*li[i%n] if x==0: return elif x>0: bs(mid+1,end,i+1) else: bs(front,mid-1,i+1) def main(): #global li,n n,x,y = get_tuple() li = list(input()) bblocks = 0 last_zero = False for i in li: if i=='0' and not last_zero: bblocks+=1 last_zero = True elif i=='1' and last_zero: last_zero=False #print(bblocks) costs = [bblocks*y] merges = 0 while bblocks!=0: if bblocks%2==0 or y<x: merges += bblocks//2 bblocks = bblocks//2 elif bblocks%2!=0: merges += (bblocks+1)//2 bblocks = (bblocks+1)//2 costs.append(bblocks*y+merges*x) if bblocks==1: break #print(costs) print(min(costs)) # --------------------------------------------------------------------- END= if TestCases: for _ in range(get_int()): cProfile.run('main()') if testingMode else main() else: (cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start() ```
instruction
0
50,261
0
100,522
No
output
1
50,261
0
100,523
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones. Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a. You can apply the following operations any number of times: * Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»); * Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones? Input The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string a of length n, consisting of zeros and ones. Output Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations. Examples Input 5 1 10 01000 Output 11 Input 5 10 1 01000 Output 2 Input 7 2 3 1111111 Output 0 Note In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5]. Then the string was changed as follows: «01000» → «10000» → «11111». The total cost of operations is 1 + 10 = 11. In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5]. Then the string was changed as follows: «01000» → «11000» → «11111». The overall cost is 1 + 1 = 2. In the third example, string already consists only of ones, so the answer is 0. Submitted Solution: ``` n, x, y = map(int, input().split()) s = input() c0 = s.split('1') c1 = s.split('0') cnt0 = 0 for c in c0: if c != '': cnt0 += 1 cnt1 = 0 for c in c1: if c != '': cnt1 += 1 print(min(cnt1 * x + y, cnt0 * y)) ```
instruction
0
50,262
0
100,524
No
output
1
50,262
0
100,525
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones. Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a. You can apply the following operations any number of times: * Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»); * Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones? Input The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string a of length n, consisting of zeros and ones. Output Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations. Examples Input 5 1 10 01000 Output 11 Input 5 10 1 01000 Output 2 Input 7 2 3 1111111 Output 0 Note In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5]. Then the string was changed as follows: «01000» → «10000» → «11111». The total cost of operations is 1 + 10 = 11. In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5]. Then the string was changed as follows: «01000» → «11000» → «11111». The overall cost is 1 + 1 = 2. In the third example, string already consists only of ones, so the answer is 0. Submitted Solution: ``` n, x, y = map(int, input().split()) nOnes = input().count('1') result = y * n for i in range(nOnes + 1): result = min(result, x * i + min(y + (nOnes - i) * y, y * (n - nOnes + i))) print(result) ```
instruction
0
50,263
0
100,526
No
output
1
50,263
0
100,527
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones. Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a. You can apply the following operations any number of times: * Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»); * Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones? Input The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string a of length n, consisting of zeros and ones. Output Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations. Examples Input 5 1 10 01000 Output 11 Input 5 10 1 01000 Output 2 Input 7 2 3 1111111 Output 0 Note In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5]. Then the string was changed as follows: «01000» → «10000» → «11111». The total cost of operations is 1 + 10 = 11. In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5]. Then the string was changed as follows: «01000» → «11000» → «11111». The overall cost is 1 + 1 = 2. In the third example, string already consists only of ones, so the answer is 0. Submitted Solution: ``` def removeUtil(string, last_removed): if len(string) == 0 or len(string) == 1: return string if string[0] == string[1]: last_removed = ord(string[0]) while len(string) > 1 and string[0] == string[1]: string = string[1:] string = string[1:] return removeUtil(string, last_removed) rem_str = removeUtil(string[1:], last_removed) if len(rem_str) != 0 and rem_str[0] == string[0]: last_removed = ord(string[0]) return (rem_str[1:]) if len(rem_str) == 0 and last_removed == ord(string[0]): return rem_str return ([string[0]] + rem_str) def remove(string): last_removed = 0 return toString(removeUtil(toList(string), last_removed)) def toList(string): x = [] for i in string: x.append(i) return x def toString(x): return ''.join(x) [n, x, y] = [int(x) for x in input().split()] A1 = input() A = remove(A1) if len(A) == 1: if A[0] == "1": print("0") else: print(y) else: c = 0 if A[0] == "0": c = 1 for i in range(1, len(A)): if A[i] == "0" and A[i-1] == "1": c += 1 print(c) m = y*c for i in range(1, c): temp = x*i + y*(c-i) if temp < m: m = temp print(m) ```
instruction
0
50,264
0
100,528
No
output
1
50,264
0
100,529
Provide a correct Python 3 solution for this coding contest problem. You are given two strings s and t consisting of lowercase English letters and an integer L. We will consider generating a string of length L by concatenating one or more copies of s and t. Here, it is allowed to use the same string more than once. For example, when s = `at`, t = `code` and L = 6, the strings `atatat`, `atcode` and `codeat` can be generated. Among the strings that can be generated in this way, find the lexicographically smallest one. In the cases given as input, it is always possible to generate a string of length L. Constraints * 1 ≤ L ≤ 2 × 10^5 * 1 ≤ |s|, |t| ≤ L * s and t consist of lowercase English letters. * It is possible to generate a string of length L in the way described in Problem Statement. Input Input is given from Standard Input in the following format: N x_1 s_1 x_2 s_2 : x_N s_N Output Print the lexicographically smallest string among the ones that can be generated in the way described in Problem Statement. Examples Input 6 at code Output atatat Input 8 coding festival Output festival Input 8 same same Output samesame Input 10 coin age Output ageagecoin
instruction
0
50,349
0
100,698
"Correct Solution: ``` L = int(input()) Ss = input() Ts = input() if Ss+Ts > Ts+Ss: Ss, Ts = Ts, Ss lenS, lenT = len(Ss), len(Ts) for numS in reversed(range(L//lenS+1)): numT = (L-lenS*numS) / lenT if int(numT) == numT: ans = Ss*numS + Ts*int(numT) print(ans) break ```
output
1
50,349
0
100,699
Provide a correct Python 3 solution for this coding contest problem. You are given two strings s and t consisting of lowercase English letters and an integer L. We will consider generating a string of length L by concatenating one or more copies of s and t. Here, it is allowed to use the same string more than once. For example, when s = `at`, t = `code` and L = 6, the strings `atatat`, `atcode` and `codeat` can be generated. Among the strings that can be generated in this way, find the lexicographically smallest one. In the cases given as input, it is always possible to generate a string of length L. Constraints * 1 ≤ L ≤ 2 × 10^5 * 1 ≤ |s|, |t| ≤ L * s and t consist of lowercase English letters. * It is possible to generate a string of length L in the way described in Problem Statement. Input Input is given from Standard Input in the following format: N x_1 s_1 x_2 s_2 : x_N s_N Output Print the lexicographically smallest string among the ones that can be generated in the way described in Problem Statement. Examples Input 6 at code Output atatat Input 8 coding festival Output festival Input 8 same same Output samesame Input 10 coin age Output ageagecoin
instruction
0
50,350
0
100,700
"Correct Solution: ``` l = int(input()) a = input() b = input() if len(a) > len(b): k = b b = a a = k mina = None maxa = None """ f = [None] * (l + 1) f[0] = '' #print(f) for i in range(l): tmpa = None tmpb = None if i + 1 >= len(a) and f[i + 1 - len(a)] is not None: tmpa = a + f[i + 1 - len(a)] if i + 1 >= len(b) and f[i + 1 - len(b)] is not None: tmpb = b + f[i + 1 - len(b)] if tmpa is None and tmpb is None: continue if tmpa is None and tmpb is not None: f[i+1] = tmpb continue if tmpb is None and tmpa is not None: f[i+1] = tmpa continue if tmpa < tmpb: f[i+1] = tmpa else: f[i+1] = tmpb print(f[l]) def less(a, b): if a < b: if not b.startswith(a): return True else: c = b while c.startswith(a): c = c[len(a):] if a < c: return True else: return False """ for i in range(l+ 1) : if i * len(a) > l: break if (l - i * len(a)) % len(b) == 0: if mina is None: mina = i maxb = (l - i * len(a)) // len(b) maxa = i minb = (l - i * len(a)) // len(b) ans1 = a * maxa + b * minb ans2 = b * maxb + a * mina if ans1 < ans2: print(ans1) else: print(ans2) ```
output
1
50,350
0
100,701
Provide a correct Python 3 solution for this coding contest problem. You are given two strings s and t consisting of lowercase English letters and an integer L. We will consider generating a string of length L by concatenating one or more copies of s and t. Here, it is allowed to use the same string more than once. For example, when s = `at`, t = `code` and L = 6, the strings `atatat`, `atcode` and `codeat` can be generated. Among the strings that can be generated in this way, find the lexicographically smallest one. In the cases given as input, it is always possible to generate a string of length L. Constraints * 1 ≤ L ≤ 2 × 10^5 * 1 ≤ |s|, |t| ≤ L * s and t consist of lowercase English letters. * It is possible to generate a string of length L in the way described in Problem Statement. Input Input is given from Standard Input in the following format: N x_1 s_1 x_2 s_2 : x_N s_N Output Print the lexicographically smallest string among the ones that can be generated in the way described in Problem Statement. Examples Input 6 at code Output atatat Input 8 coding festival Output festival Input 8 same same Output samesame Input 10 coin age Output ageagecoin
instruction
0
50,351
0
100,702
"Correct Solution: ``` import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from fractions import gcd L = int(readline()) S = readline().rstrip().decode('utf-8') T = readline().rstrip().decode('utf-8') ST = S + T TS = T + S if ST > TS: S,T = T,S # Sを手前にした方が得 LS = len(S) LT = len(T) n = 0 for x in range(L+1): if (L - LS * x) % LT == 0: n = x break n1, m1 = n, (L - LS * n) // LT d = gcd(LS,LT) n2, m2 = n1, m1 dn, dm = LT//d, LS//d while m2 >= dm: m2 -= dm n2 += dn x = S * n1 + T * m1 y = S * n2 + T * m2 answer = min(x,y) print(answer) ```
output
1
50,351
0
100,703
Provide a correct Python 3 solution for this coding contest problem. You are given two strings s and t consisting of lowercase English letters and an integer L. We will consider generating a string of length L by concatenating one or more copies of s and t. Here, it is allowed to use the same string more than once. For example, when s = `at`, t = `code` and L = 6, the strings `atatat`, `atcode` and `codeat` can be generated. Among the strings that can be generated in this way, find the lexicographically smallest one. In the cases given as input, it is always possible to generate a string of length L. Constraints * 1 ≤ L ≤ 2 × 10^5 * 1 ≤ |s|, |t| ≤ L * s and t consist of lowercase English letters. * It is possible to generate a string of length L in the way described in Problem Statement. Input Input is given from Standard Input in the following format: N x_1 s_1 x_2 s_2 : x_N s_N Output Print the lexicographically smallest string among the ones that can be generated in the way described in Problem Statement. Examples Input 6 at code Output atatat Input 8 coding festival Output festival Input 8 same same Output samesame Input 10 coin age Output ageagecoin
instruction
0
50,352
0
100,704
"Correct Solution: ``` def main(): L = int(input()) S, T = (input() for _ in [0] * 2) ans = [] apnd = ans.append a = S b = T i = 0 for _ in [0] * 2: while 1: x = L - (len(b) * i) div_, mod_ = divmod(x, len(a)) if not mod_: apnd(a * div_ + b * i) break i += 1 i = 0 a, b = b, a print(min(ans)) main() ```
output
1
50,352
0
100,705
Provide a correct Python 3 solution for this coding contest problem. You are given two strings s and t consisting of lowercase English letters and an integer L. We will consider generating a string of length L by concatenating one or more copies of s and t. Here, it is allowed to use the same string more than once. For example, when s = `at`, t = `code` and L = 6, the strings `atatat`, `atcode` and `codeat` can be generated. Among the strings that can be generated in this way, find the lexicographically smallest one. In the cases given as input, it is always possible to generate a string of length L. Constraints * 1 ≤ L ≤ 2 × 10^5 * 1 ≤ |s|, |t| ≤ L * s and t consist of lowercase English letters. * It is possible to generate a string of length L in the way described in Problem Statement. Input Input is given from Standard Input in the following format: N x_1 s_1 x_2 s_2 : x_N s_N Output Print the lexicographically smallest string among the ones that can be generated in the way described in Problem Statement. Examples Input 6 at code Output atatat Input 8 coding festival Output festival Input 8 same same Output samesame Input 10 coin age Output ageagecoin
instruction
0
50,353
0
100,706
"Correct Solution: ``` def solve(l, s, t): queue = [(1, 0), (0, 1)] def gcd(a, b): r = a % b if r: d = a // b sb = queue.pop() sa = queue.pop() queue.append(sb) queue.append(tuple(x - d * y for x, y in zip(sa, sb))) return gcd(b, r) else: return b ls, lt = len(s), len(t) if ls > lt: s, t, ls, lt = t, s, lt, ls if (s * (lt // ls + 1) * 2)[:lt * 2] > t * 2: s, t, ls, lt = t, s, lt, ls g = gcd(ls, lt) l //= g ls //= g lt //= g a, b = queue[-1] a *= l b *= l k = b // ls b -= ls * k a += lt * k return s * a + t * b l = int(input()) s = input() t = input() print(solve(l, s, t)) ```
output
1
50,353
0
100,707
Provide a correct Python 3 solution for this coding contest problem. You are given two strings s and t consisting of lowercase English letters and an integer L. We will consider generating a string of length L by concatenating one or more copies of s and t. Here, it is allowed to use the same string more than once. For example, when s = `at`, t = `code` and L = 6, the strings `atatat`, `atcode` and `codeat` can be generated. Among the strings that can be generated in this way, find the lexicographically smallest one. In the cases given as input, it is always possible to generate a string of length L. Constraints * 1 ≤ L ≤ 2 × 10^5 * 1 ≤ |s|, |t| ≤ L * s and t consist of lowercase English letters. * It is possible to generate a string of length L in the way described in Problem Statement. Input Input is given from Standard Input in the following format: N x_1 s_1 x_2 s_2 : x_N s_N Output Print the lexicographically smallest string among the ones that can be generated in the way described in Problem Statement. Examples Input 6 at code Output atatat Input 8 coding festival Output festival Input 8 same same Output samesame Input 10 coin age Output ageagecoin
instruction
0
50,354
0
100,708
"Correct Solution: ``` n=int(input()) a=sorted([input()for i in range(2)]) s,t=len(a[0]),len(a[1]) c=[] for i in range(n): if (n-i*t)%s==0: c.append(a[0]*((n-i*t)//s)+a[1]*i) break for i in range(n): if (n-i*s)%t==0: c.append(a[1]*((n-i*s)//t)+a[0]*i) break print(sorted(c)[0]) ```
output
1
50,354
0
100,709
Provide a correct Python 3 solution for this coding contest problem. You are given two strings s and t consisting of lowercase English letters and an integer L. We will consider generating a string of length L by concatenating one or more copies of s and t. Here, it is allowed to use the same string more than once. For example, when s = `at`, t = `code` and L = 6, the strings `atatat`, `atcode` and `codeat` can be generated. Among the strings that can be generated in this way, find the lexicographically smallest one. In the cases given as input, it is always possible to generate a string of length L. Constraints * 1 ≤ L ≤ 2 × 10^5 * 1 ≤ |s|, |t| ≤ L * s and t consist of lowercase English letters. * It is possible to generate a string of length L in the way described in Problem Statement. Input Input is given from Standard Input in the following format: N x_1 s_1 x_2 s_2 : x_N s_N Output Print the lexicographically smallest string among the ones that can be generated in the way described in Problem Statement. Examples Input 6 at code Output atatat Input 8 coding festival Output festival Input 8 same same Output samesame Input 10 coin age Output ageagecoin
instruction
0
50,355
0
100,710
"Correct Solution: ``` L = int(input()) s = input() t = input() if not s+t <= t+s: s, t = t, s ls = len(s); lt = len(t) for i in range(L // ls, -1, -1): if (L - ls*i) % lt == 0: ans = s * i + t * ((L - ls*i) // lt) break print(ans) ```
output
1
50,355
0
100,711
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two strings s and t consisting of lowercase English letters and an integer L. We will consider generating a string of length L by concatenating one or more copies of s and t. Here, it is allowed to use the same string more than once. For example, when s = `at`, t = `code` and L = 6, the strings `atatat`, `atcode` and `codeat` can be generated. Among the strings that can be generated in this way, find the lexicographically smallest one. In the cases given as input, it is always possible to generate a string of length L. Constraints * 1 ≤ L ≤ 2 × 10^5 * 1 ≤ |s|, |t| ≤ L * s and t consist of lowercase English letters. * It is possible to generate a string of length L in the way described in Problem Statement. Input Input is given from Standard Input in the following format: N x_1 s_1 x_2 s_2 : x_N s_N Output Print the lexicographically smallest string among the ones that can be generated in the way described in Problem Statement. Examples Input 6 at code Output atatat Input 8 coding festival Output festival Input 8 same same Output samesame Input 10 coin age Output ageagecoin Submitted Solution: ``` l = int(input()) a = input() b = input() if len(a) > len(b): k = b b = a a = k mina = None maxa = None f = [None] * (l + 1) f[0] = '' #print(f) for i in range(l): tmpa = None tmpb = None if i + 1 >= len(a) and f[i + 1 - len(a)] is not None: tmpa = a + f[i + 1 - len(a)] if i + 1 >= len(b) and f[i + 1 - len(b)] is not None: tmpb = b + f[i + 1 - len(b)] if tmpa is None and tmpb is None: continue if tmpa is None and tmpb is not None: f[i+1] = tmpb continue if tmpb is None and tmpa is not None: f[i+1] = tmpa continue if tmpa < tmpb: f[i+1] = tmpa else: f[i+1] = tmpb print(f[l]) ```
instruction
0
50,357
0
100,714
No
output
1
50,357
0
100,715
Provide a correct Python 3 solution for this coding contest problem. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. Constraints * 2 \leq |S| \leq 200 * S is an even string consisting of lowercase English letters. * There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S. Input Input is given from Standard Input in the following format: S Output Print the length of the longest even string that can be obtained. Examples Input abaababaab Output 6 Input xxxx Output 2 Input abcabcabcabc Output 6 Input akasakaakasakasakaakas Output 14
instruction
0
50,360
0
100,720
"Correct Solution: ``` S=input() L=len(S)//2-1 while S[:L]!=S[L:2*L]: L-=1 print(2*L) ```
output
1
50,360
0
100,721
Provide a correct Python 3 solution for this coding contest problem. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. Constraints * 2 \leq |S| \leq 200 * S is an even string consisting of lowercase English letters. * There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S. Input Input is given from Standard Input in the following format: S Output Print the length of the longest even string that can be obtained. Examples Input abaababaab Output 6 Input xxxx Output 2 Input abcabcabcabc Output 6 Input akasakaakasakasakaakas Output 14
instruction
0
50,361
0
100,722
"Correct Solution: ``` S = input()[:-1] while S[:len(S)//2] != S[len(S)//2:]: S = S[:-1] print(len(S)) ```
output
1
50,361
0
100,723
Provide a correct Python 3 solution for this coding contest problem. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. Constraints * 2 \leq |S| \leq 200 * S is an even string consisting of lowercase English letters. * There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S. Input Input is given from Standard Input in the following format: S Output Print the length of the longest even string that can be obtained. Examples Input abaababaab Output 6 Input xxxx Output 2 Input abcabcabcabc Output 6 Input akasakaakasakasakaakas Output 14
instruction
0
50,362
0
100,724
"Correct Solution: ``` import re S = input() m = re.search(r'\A([a-z]+)\1', S[:len(S) - 1]) print(len(m.group(0))) ```
output
1
50,362
0
100,725
Provide a correct Python 3 solution for this coding contest problem. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. Constraints * 2 \leq |S| \leq 200 * S is an even string consisting of lowercase English letters. * There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S. Input Input is given from Standard Input in the following format: S Output Print the length of the longest even string that can be obtained. Examples Input abaababaab Output 6 Input xxxx Output 2 Input abcabcabcabc Output 6 Input akasakaakasakasakaakas Output 14
instruction
0
50,363
0
100,726
"Correct Solution: ``` s = input()[:-2] ls = len(s) // 2 while s[:ls] != s[ls:]: ls -= 1 s = s[:-2] print(ls*2) ```
output
1
50,363
0
100,727
Provide a correct Python 3 solution for this coding contest problem. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. Constraints * 2 \leq |S| \leq 200 * S is an even string consisting of lowercase English letters. * There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S. Input Input is given from Standard Input in the following format: S Output Print the length of the longest even string that can be obtained. Examples Input abaababaab Output 6 Input xxxx Output 2 Input abcabcabcabc Output 6 Input akasakaakasakasakaakas Output 14
instruction
0
50,364
0
100,728
"Correct Solution: ``` s = list(input()) s = s[:-1] while s[:len(s)//2] != s[len(s)//2 :]: s = s[:-1] # print(s) print(len(s)) ```
output
1
50,364
0
100,729
Provide a correct Python 3 solution for this coding contest problem. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. Constraints * 2 \leq |S| \leq 200 * S is an even string consisting of lowercase English letters. * There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S. Input Input is given from Standard Input in the following format: S Output Print the length of the longest even string that can be obtained. Examples Input abaababaab Output 6 Input xxxx Output 2 Input abcabcabcabc Output 6 Input akasakaakasakasakaakas Output 14
instruction
0
50,365
0
100,730
"Correct Solution: ``` S = input() S = S[:-2] while S[:len(S)//2] != S[len(S)//2:]: S = S[:-2] print(len(S)) ```
output
1
50,365
0
100,731
Provide a correct Python 3 solution for this coding contest problem. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. Constraints * 2 \leq |S| \leq 200 * S is an even string consisting of lowercase English letters. * There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S. Input Input is given from Standard Input in the following format: S Output Print the length of the longest even string that can be obtained. Examples Input abaababaab Output 6 Input xxxx Output 2 Input abcabcabcabc Output 6 Input akasakaakasakasakaakas Output 14
instruction
0
50,366
0
100,732
"Correct Solution: ``` s = input() for k in range(len(s)//2-1, 0, -1): if s[:k] == s[k:2*k]: break print(k*2) ```
output
1
50,366
0
100,733
Provide a correct Python 3 solution for this coding contest problem. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. Constraints * 2 \leq |S| \leq 200 * S is an even string consisting of lowercase English letters. * There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S. Input Input is given from Standard Input in the following format: S Output Print the length of the longest even string that can be obtained. Examples Input abaababaab Output 6 Input xxxx Output 2 Input abcabcabcabc Output 6 Input akasakaakasakasakaakas Output 14
instruction
0
50,367
0
100,734
"Correct Solution: ``` s=input()[:-2] while s[:len(s)//2] != s[len(s)//2:]: s=s[:len(s)-2] print(len(s)) ```
output
1
50,367
0
100,735
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. Constraints * 2 \leq |S| \leq 200 * S is an even string consisting of lowercase English letters. * There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S. Input Input is given from Standard Input in the following format: S Output Print the length of the longest even string that can be obtained. Examples Input abaababaab Output 6 Input xxxx Output 2 Input abcabcabcabc Output 6 Input akasakaakasakasakaakas Output 14 Submitted Solution: ``` S=input() L=len(S) for i in range(L//2-1,-1,-1): if S[0:i-1]==S[i:2*i-1]: break print(i*2) ```
instruction
0
50,368
0
100,736
Yes
output
1
50,368
0
100,737
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. Constraints * 2 \leq |S| \leq 200 * S is an even string consisting of lowercase English letters. * There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S. Input Input is given from Standard Input in the following format: S Output Print the length of the longest even string that can be obtained. Examples Input abaababaab Output 6 Input xxxx Output 2 Input abcabcabcabc Output 6 Input akasakaakasakasakaakas Output 14 Submitted Solution: ``` S = input() n = len(S) - 2 while S: if S[0:n//2] == S[n//2:n]:break n = n-2 print(n) ```
instruction
0
50,369
0
100,738
Yes
output
1
50,369
0
100,739
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. Constraints * 2 \leq |S| \leq 200 * S is an even string consisting of lowercase English letters. * There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S. Input Input is given from Standard Input in the following format: S Output Print the length of the longest even string that can be obtained. Examples Input abaababaab Output 6 Input xxxx Output 2 Input abcabcabcabc Output 6 Input akasakaakasakasakaakas Output 14 Submitted Solution: ``` n = input() n = n[:-1] while n[:len(n)//2] != n[len(n)//2:]: n = n[:-1] print(len(n)) ```
instruction
0
50,370
0
100,740
Yes
output
1
50,370
0
100,741
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. Constraints * 2 \leq |S| \leq 200 * S is an even string consisting of lowercase English letters. * There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S. Input Input is given from Standard Input in the following format: S Output Print the length of the longest even string that can be obtained. Examples Input abaababaab Output 6 Input xxxx Output 2 Input abcabcabcabc Output 6 Input akasakaakasakasakaakas Output 14 Submitted Solution: ``` s = input() while 1: s = s[:-2] i = len(s)//2 if s[:i] == s[i:]: break print(len(s)) ```
instruction
0
50,371
0
100,742
Yes
output
1
50,371
0
100,743
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. Constraints * 2 \leq |S| \leq 200 * S is an even string consisting of lowercase English letters. * There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S. Input Input is given from Standard Input in the following format: S Output Print the length of the longest even string that can be obtained. Examples Input abaababaab Output 6 Input xxxx Output 2 Input abcabcabcabc Output 6 Input akasakaakasakasakaakas Output 14 Submitted Solution: ``` s = input() n = len(s) def iseven(str, n): for i in range(0, n//2): if str[i] != str[i+n//2]: return False else: return True for i in range(2, n, 2): if iseven(s, n-i): print(n-i) ```
instruction
0
50,372
0
100,744
No
output
1
50,372
0
100,745
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. Constraints * 2 \leq |S| \leq 200 * S is an even string consisting of lowercase English letters. * There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S. Input Input is given from Standard Input in the following format: S Output Print the length of the longest even string that can be obtained. Examples Input abaababaab Output 6 Input xxxx Output 2 Input abcabcabcabc Output 6 Input akasakaakasakasakaakas Output 14 Submitted Solution: ``` import collections def even_str(cnt): return len([key for key in cnt if cnt[key] % 2 != 0]) == 0 s = list(input()) c = collections.Counter(s) while len(s) != 0: last_char = s.pop(-1) c[last_char] -= 1 if(even_str(c)): print(len(s)) exit() ```
instruction
0
50,373
0
100,746
No
output
1
50,373
0
100,747
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. Constraints * 2 \leq |S| \leq 200 * S is an even string consisting of lowercase English letters. * There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S. Input Input is given from Standard Input in the following format: S Output Print the length of the longest even string that can be obtained. Examples Input abaababaab Output 6 Input xxxx Output 2 Input abcabcabcabc Output 6 Input akasakaakasakasakaakas Output 14 Submitted Solution: ``` S = input while len(S)!=0: S.pop() if len(S)%2==0 and S[0:len(S)/2]==S[len(S)/2:]: print(len(S)) exit() ```
instruction
0
50,374
0
100,748
No
output
1
50,374
0
100,749
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input. Constraints * 2 \leq |S| \leq 200 * S is an even string consisting of lowercase English letters. * There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S. Input Input is given from Standard Input in the following format: S Output Print the length of the longest even string that can be obtained. Examples Input abaababaab Output 6 Input xxxx Output 2 Input abcabcabcabc Output 6 Input akasakaakasakasakaakas Output 14 Submitted Solution: ``` s = input() for i in range(len(s)//2): s = s[:-2] l = len(s) if s[:l] == s[l:]: print( l * 2) break ```
instruction
0
50,375
0
100,750
No
output
1
50,375
0
100,751
Provide a correct Python 3 solution for this coding contest problem. Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For example, if you perform an operation for the second letter on `aaz`, `aaz` becomes `abz`. If you then perform an operation for the third letter on `abz`, `abz` becomes `aba`. Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s. Find the such string. Constraints * 1≤|s|≤10^5 * All letters in s are lowercase English letters. * 1≤K≤10^9 Input The input is given from Standard Input in the following format: s K Output Print the lexicographically smallest string after performing exactly K operations on s. Examples Input xyz 4 Output aya Input a 25 Output z Input codefestival 100 Output aaaafeaaivap
instruction
0
50,392
0
100,784
"Correct Solution: ``` s = list(input()) K = int(input()) for i in range(len(s)): if s[i] == "a": pass elif 123 - ord(s[i]) <= K: K -= (123 - ord(s[i])) s[i] = 'a' K = K % 26 while K > 0: K -= 1 if s[-1] == "z": s[-1] = "a" else: s[-1] = chr(ord(s[-1]) + 1) print("".join(s)) ```
output
1
50,392
0
100,785
Provide a correct Python 3 solution for this coding contest problem. Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For example, if you perform an operation for the second letter on `aaz`, `aaz` becomes `abz`. If you then perform an operation for the third letter on `abz`, `abz` becomes `aba`. Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s. Find the such string. Constraints * 1≤|s|≤10^5 * All letters in s are lowercase English letters. * 1≤K≤10^9 Input The input is given from Standard Input in the following format: s K Output Print the lexicographically smallest string after performing exactly K operations on s. Examples Input xyz 4 Output aya Input a 25 Output z Input codefestival 100 Output aaaafeaaivap
instruction
0
50,393
0
100,786
"Correct Solution: ``` s=input() K=int(input()) S=[c for c in s] def diff(c): return ord('z')-ord(c) for i in range(len(s)): d=diff(S[i]) if d<min(25,K): K-=d+1 S[i]='a' k=K%26 S[-1]=chr(ord(S[-1])+k) if k<=diff(S[-1]) else chr(ord(S[-1])+k-26) print(''.join(S)) ```
output
1
50,393
0
100,787
Provide a correct Python 3 solution for this coding contest problem. Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For example, if you perform an operation for the second letter on `aaz`, `aaz` becomes `abz`. If you then perform an operation for the third letter on `abz`, `abz` becomes `aba`. Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s. Find the such string. Constraints * 1≤|s|≤10^5 * All letters in s are lowercase English letters. * 1≤K≤10^9 Input The input is given from Standard Input in the following format: s K Output Print the lexicographically smallest string after performing exactly K operations on s. Examples Input xyz 4 Output aya Input a 25 Output z Input codefestival 100 Output aaaafeaaivap
instruction
0
50,394
0
100,788
"Correct Solution: ``` s=input() k=int(input()) a=[] for t in s[:-1]: c=123-ord(t) if k<c or t=='a': a.append(t) else: k-=c a.append('a') a.append(chr((ord(s[-1])-97+k)%26+97)) print(''.join(a)) ```
output
1
50,394
0
100,789
Provide a correct Python 3 solution for this coding contest problem. Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For example, if you perform an operation for the second letter on `aaz`, `aaz` becomes `abz`. If you then perform an operation for the third letter on `abz`, `abz` becomes `aba`. Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s. Find the such string. Constraints * 1≤|s|≤10^5 * All letters in s are lowercase English letters. * 1≤K≤10^9 Input The input is given from Standard Input in the following format: s K Output Print the lexicographically smallest string after performing exactly K operations on s. Examples Input xyz 4 Output aya Input a 25 Output z Input codefestival 100 Output aaaafeaaivap
instruction
0
50,395
0
100,790
"Correct Solution: ``` s = input() K = int(input()) s = list(s) # print(diff) for i in range(len(s)): if s[i] != 'a': dist = ord('z') - ord(s[i]) + 1 if dist <= K: K -= dist s[i] = 'a' # print(s) temp = K % 26 s[-1] = chr(ord(s[-1]) + temp) # print(s) print(''.join(s)) ```
output
1
50,395
0
100,791
Provide a correct Python 3 solution for this coding contest problem. Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For example, if you perform an operation for the second letter on `aaz`, `aaz` becomes `abz`. If you then perform an operation for the third letter on `abz`, `abz` becomes `aba`. Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s. Find the such string. Constraints * 1≤|s|≤10^5 * All letters in s are lowercase English letters. * 1≤K≤10^9 Input The input is given from Standard Input in the following format: s K Output Print the lexicographically smallest string after performing exactly K operations on s. Examples Input xyz 4 Output aya Input a 25 Output z Input codefestival 100 Output aaaafeaaivap
instruction
0
50,396
0
100,792
"Correct Solution: ``` l = list(input()) k = int(input()) for i in range(len(l)): if l[i] == "a": continue if 123 - ord(l[i]) <= k: k -= 123 - ord(l[i]) l[i] = "a" k %= 26 l[-1] = chr((ord(l[-1])-97+k)%26+97) print("".join(l)) ```
output
1
50,396
0
100,793
Provide a correct Python 3 solution for this coding contest problem. Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For example, if you perform an operation for the second letter on `aaz`, `aaz` becomes `abz`. If you then perform an operation for the third letter on `abz`, `abz` becomes `aba`. Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s. Find the such string. Constraints * 1≤|s|≤10^5 * All letters in s are lowercase English letters. * 1≤K≤10^9 Input The input is given from Standard Input in the following format: s K Output Print the lexicographically smallest string after performing exactly K operations on s. Examples Input xyz 4 Output aya Input a 25 Output z Input codefestival 100 Output aaaafeaaivap
instruction
0
50,397
0
100,794
"Correct Solution: ``` s = input().strip() k = int(input()) ans = '' for _s in s[:-1]: if _s == 'a': ans += 'a' elif 26 - ord(_s) + ord('a') <= k: ans += 'a' k -= 26 - ord(_s) + ord('a') else: ans += _s ans += chr(ord('a') + (ord(s[-1]) - ord('a') + k) % 26) print(ans) ```
output
1
50,397
0
100,795
Provide a correct Python 3 solution for this coding contest problem. Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For example, if you perform an operation for the second letter on `aaz`, `aaz` becomes `abz`. If you then perform an operation for the third letter on `abz`, `abz` becomes `aba`. Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s. Find the such string. Constraints * 1≤|s|≤10^5 * All letters in s are lowercase English letters. * 1≤K≤10^9 Input The input is given from Standard Input in the following format: s K Output Print the lexicographically smallest string after performing exactly K operations on s. Examples Input xyz 4 Output aya Input a 25 Output z Input codefestival 100 Output aaaafeaaivap
instruction
0
50,398
0
100,796
"Correct Solution: ``` s=input() l=len(s) k=int(input()) z='' for i in range(l): t=123-ord(s[i]) if s[i]=='a': z+='a' elif t<=k: z+='a' k-=t else: z+=s[i] v=ord(z[l-1])-97+k z=z[:l-1]+chr(v%26+97) print(z) ```
output
1
50,398
0
100,797
Provide a correct Python 3 solution for this coding contest problem. Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For example, if you perform an operation for the second letter on `aaz`, `aaz` becomes `abz`. If you then perform an operation for the third letter on `abz`, `abz` becomes `aba`. Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s. Find the such string. Constraints * 1≤|s|≤10^5 * All letters in s are lowercase English letters. * 1≤K≤10^9 Input The input is given from Standard Input in the following format: s K Output Print the lexicographically smallest string after performing exactly K operations on s. Examples Input xyz 4 Output aya Input a 25 Output z Input codefestival 100 Output aaaafeaaivap
instruction
0
50,399
0
100,798
"Correct Solution: ``` s = list(input()) k = int(input()) for i in range(len(s)): if ord("z")-ord(s[i])+1<=k: k -= (ord("z")-ord(s[i])+1)%26 s[i] = "a" if k: s[-1] = chr((ord(s[-1])+k-ord("a"))%26+ord("a")) print("".join(s)) ```
output
1
50,399
0
100,799
Provide tags and a correct Python 3 solution for this coding contest problem. 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.
instruction
0
50,508
0
101,016
Tags: greedy, strings Correct Solution: ``` import os, sys, bisect from collections import defaultdict, Counter, deque; from functools import lru_cache #use @lru_cache(None) if os.path.exists('in.txt'): sys.stdin=open('in.txt','r') if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w') # input = lambda: sys.stdin.readline().strip() imap = lambda: map(int,input().split()); ilist = lambda: list(imap()) #------------------------------------------------------------------ #sys.setrecursionlimit(10**6) mod = int(1e9+7) n,k = imap() s = input().strip() t = input().strip() f = 0 for i in range(n): if s[i]!=t[i]: f = 1 s = s[i:] t = t[i:] break if not f: print(n) exit() res = n-len(s) n = len(s) for i in range(n): cur = 1 for j in range(i+1): if t[j]=="b": cur+=1<<(i-j) if s[j]=="b": cur-=1<<(i-j) if cur<k: res+=cur else: res+=(n-i)*k break print(res) ```
output
1
50,508
0
101,017
Provide tags and a correct Python 3 solution for this coding contest problem. 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.
instruction
0
50,509
0
101,018
Tags: greedy, strings Correct Solution: ``` n, k = map(int, input().split()) a = input() b = input() res = 0 ans = 0 for i in range(0, n): res = min(res * 2 + (b[i] == 'b') - (a[i] == 'b'), k) ans += min(res + 1, k) print(ans) ```
output
1
50,509
0
101,019
Provide tags and a correct Python 3 solution for this coding contest problem. 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.
instruction
0
50,510
0
101,020
Tags: greedy, strings Correct Solution: ``` import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------------------ from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc def RL(): return map(int, sys.stdin.readline().rstrip().split()) def RLL(): return list(map(int, sys.stdin.readline().rstrip().split())) def N(): return int(input()) def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0 def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0 def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2) mod = 998244353 INF = float('inf') from math import factorial from collections import Counter, defaultdict, deque from heapq import heapify, heappop, heappush # ------------------------------ def c(ca, cb): return ord(cb)-ord(ca) def main(): n, k = RL() s = input() t = input() res = 0 tag = n for i in range(n): if s[i]==t[i]: res+=1 else: tag = i; break num = 2 for j in range(tag, n): if s[j]=='b': num-=1 if t[j]=='a': num-=1 if num>=k: res+=k*(n-j); break res+=num num*=2 print(res) if __name__ == "__main__": main() ```
output
1
50,510
0
101,021
Provide tags and a correct Python 3 solution for this coding contest problem. 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.
instruction
0
50,511
0
101,022
Tags: greedy, strings Correct Solution: ``` n,k=map(int,input().split()) a=input().strip() b=input().strip() add=1 count=0 for i in range(n): if a[i]==b[i]: add=add*2-1 elif a[i]=="a" and b[i]=="b": add=add*2 else: add=add*2-2 if add>k: count+=(n-i)*k break count=count+min(k,add) print(count) ```
output
1
50,511
0
101,023
Provide tags and a correct Python 3 solution for this coding contest problem. 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.
instruction
0
50,512
0
101,024
Tags: greedy, strings Correct Solution: ``` n,k=map(int,input().split()) s=input() t=input() res,tp=0,1 for i in range(n): tp*=2 if s[i]=='b': tp-=1 if t[i]=='a': tp-=1 res+=min(tp,k) tp=min(tp,1e9) print(res) ```
output
1
50,512
0
101,025
Provide tags and a correct Python 3 solution for this coding contest problem. 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.
instruction
0
50,513
0
101,026
Tags: greedy, strings Correct 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(1e18+7,cnt) ans+=min(cnt,k) print(ans) ```
output
1
50,513
0
101,027
Provide tags and a correct Python 3 solution for this coding contest problem. 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.
instruction
0
50,514
0
101,028
Tags: greedy, strings Correct Solution: ``` n,k=map(int,input().split()) a=input().strip() b=input().strip() add=1 count=0 for i in range(n): add*=2 if a[i]=='b': add-=1 if b[i]=='a': add-=1 if add>k: count+=(n-i)*k break count+=add print(count) ```
output
1
50,514
0
101,029
Provide tags and a correct Python 3 solution for this coding contest problem. 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.
instruction
0
50,515
0
101,030
Tags: greedy, strings Correct Solution: ``` def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(mi()) # B. The Fair Nut and Strings n, k = mi() s = input().strip() t = input().strip() ans = 0 jj = 0 for i in range(n): if s[i] == t[i]: ans += 1 jj = i + 1 else: break cur = 2 for j in range(jj, n): if s[j] == 'b': cur -= 1 if t[j] == 'a': cur -= 1 if cur >= k: ans += k * (n - j) break ans += cur cur *= 2 print(ans) ```
output
1
50,515
0
101,031