Under construction

Still being built. Things may change

Why Work?

Time limit1.122sMemory limit1122 MB

Summary
Given N coins whose prices follow a binary-counter-like update rule, find the maximum profit from trading one unit per coin per day over T days.
Level

Medium7 of 10

Topics
Math, Greedy, Simulation
Solved
No attempts yet

문제

준성 is unwilling to work and only wants a quick score, so he starts analyzing the prices of NN cryptocurrencies! Here is what he found. PiP_i is the price of the ii-th cryptocurrency.

  1. PiP_i is either 1 or 2.
  2. P1P_1 changes every day. That is, if P1P_1 is 1, it becomes 2, and if it is 2, it becomes 1.
  3. Pi+1P_{i+1} changes every day if P1,P2,…,PiP_1, P_2, \dots, P_i were all 2 yesterday. Otherwise, it does not change. (1≤i≤N−1)(1 \leq i \leq N-1)
  4. Apart from the conditions above, PiP_i never changes, and each cryptocurrency has an unlimited supply.

Because a huge investor could enter the market and make the analysis useless,준성 trades only one unit of each cryptocurrency per day, either buying or selling.

Junseong is diligent, so he starts trading as soon as prices are updated. Trading takes negligibly little time. None of his intended trades fail. If he wants to buy, he can always buy, and if he wants to sell, he can sell immediately.

Assume the analysis is correct at all times and his capital is always large enough to buy. Find the maximum profit he can earn by trading over TT days.

입력

The first line contains integers NN and TT, separated by a space. (1≤N≤111222; 1≤T≤1012)(1 \leq N \leq 111222;\ 1 \leq T \leq 10^{12})

The second line contains the values of PiP_i on the day Junseong starts trading, given in order with no spaces.

출력

Print the answer to the problem on the first line.

힌트

Cryptocurrencies that Junseong still holds when trading ends are not counted in the profit.

Examples2

  1. Example 1

    Input
    4 5
    1122
    
    Expected output
    4
    
  2. Example 2

    Input
    4 5
    2211
    
    Expected output
    5