PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000206. Tổng các xâu con độ dài hai (Sum of Substrings)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tổng các xâu con độ dài hai (Sum of Substrings)

Sum of Substrings

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a binary string s=s1s2…sns=s_1s_2\ldots s_n. Each adjacent pair si,si+1s_i,s_{i+1} represents a two-digit decimal number did_i; a leading zero is allowed. Define

f(s)=∑i=1n−1di.f(s)=\sum_{i=1}^{n-1} d_i.

For example, 1011 gives 10, 01, 11 and hence f(s)=22f(s)=22.

One operation swaps two adjacent characters. At most kk operations may be performed; you do not have to use them all. Find the smallest possible value of f(s)f(s).

Input

  • The first line contains integers nn and kk: the string length and the maximum allowed number of swaps.
  • The second line contains a binary string ss of exactly nn characters.

Output

Print one integer: the minimum possible value of f(s)f(s) after no more than kk adjacent swaps.

Subtasks

  • Subtask 1 (20 points): 2≤n≤122\le n\le12; 0≤k≤1090\le k\le10^9; s∈{0,1}ns\in\{0,1\}^n.
  • Subtask 2 (30 points): 2≤n≤20002\le n\le2000; 0≤k≤1090\le k\le10^9; s∈{0,1}ns\in\{0,1\}^n.
  • Subtask 3 (50 points): 2≤n≤1052\le n\le10^5; 0≤k≤1090\le k\le10^9; s∈{0,1}ns\in\{0,1\}^n.

Examples

Input

5 2
00110

Output

12

Explanation

For 00110, adjacent pairs give 0+1+11+10=220+1+11+10=22. Swapping the last 1 and 0 produces 00101 after one allowed swap. Its pairs are 00, 01, 10, 01, whose sum is 0+1+10+1=120+1+10+1=12. No arrangement reachable with at most two swaps yields a smaller sum, so the output is 12.