For a sequence S of positive integers and positive integers k and l, S is said to belong to level (k,l) when one of the following conditions is satisfied:

* The length of S is 1, and its only element is k.
* There exist sequences T_1,T_2,...,T_m (m \geq l) belonging to level (k-1,l) such that the concatenation of T_1,T_2,...,T_m in this order coincides with S.



Note that the second condition has no effect when k=1, that is, a sequence belongs to level (1,l) only if the first condition is satisfied.

Given are a sequence of positive integers A_1,A_2,...,A_N and a positive integer L. Find the number of subsequences A_i,A_{i+1},...,A_j (1 \leq i \leq j \leq N) that satisfy the following condition:

* There exists a positive integer K such that the sequence A_i,A_{i+1},...,A_j belongs to level (K,L).

Constraints

* 1 \leq N \leq 2 \times 10^5
* 2 \leq L \leq N
* 1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:


N L
A_1 A_2 ... A_N


Output

Print the number of subsequences A_i,A_{i+1},...,A_j (1 \leq i \leq j \leq N) that satisfy the condition.

Examples

Input

9 3
2 1 1 1 1 1 1 2 3


Output

22


Input

9 2
2 1 1 1 1 1 1 2 3


Output

41


Input

15 3
4 3 2 1 1 1 2 3 2 2 1 1 1 2 2


Output

31
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):0;}
    const int INF=0x3f3f3f3f;
    const int MOD=998244353;
    inline int mm(const int x){return x>=MOD?x-MOD:x;}
    inline ll qpower(ll x,ll e)
    {
        ll ans=1;
        while(e)
        {
            if(e&1) ans=ans*x%MOD;
            x=x*x%MOD;e>>=1;
        }
        return ans;
    }
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    vc<pr> nw;int L;
    ll calcnw()
    {
        ll ans=0,sum=0;
        for(int t=L-1;t<sz(nw);t++) sum+=nw[t-L+1].FR,ans+=sum*nw[t].SE;
        return ans;
    }
    vc< pair<pr,pr> > all,all2;//(fl,fr,li,ri)表示覆盖区间、作为端点的系数；里面所有数当前都是val
    vc<pr> num;
    void main()
    {
        int n=qread();L=qread();
        for(int i=1;i<=n;i++) num.PB(MP(qread(),i));sort(all(num));
        ll ans=n;int val=0,numpos=0;
        while(1)
        {
            if(!sz(all))
            {
                if(numpos==n) break;
                val=num[numpos].FR;
            } else val++;
            while(numpos<n and num[numpos].FR==val)//newguy
                all.PB(MP( MP(num[numpos].SE,num[numpos].SE),MP(1,1) )),numpos++;
            sort(all(all));all2.clear();
            for(int i=0,j;i<sz(all);i=j+1)
            {
                j=i;while(j+1<sz(all) and all[j].FR.SE+1==all[j+1].FR.FR) j++;//极长连续段
                int cnt=(j-i+1)/L;if(!cnt) continue;
                nw.clear();for(int k=i;k<=j;k++) nw.PB(all[k].SE);ans+=calcnw();
                vc<pr> pos,pp;pp.resize(cnt);
                for(int k=i;k<=j;k++)
                {
                    int tl=k-i+1,tr=j-k+1;
                    if(tl>=L) pp[tl/L-1].SE+=all[k].SE.SE;
                    if(tr>=L) pp[cnt-tr/L].FR+=all[k].SE.FR;
                }
                nw=pp;ans-=calcnw();
                for(int t=0;t<cnt;t++) pos.PB(MP(all[i].FR.FR+t,all[i].FR.FR+t));pos[cnt-1].SE=all[j].FR.SE;
                for(int t=0;t<cnt;t++) all2.PB(MP(pos[t],pp[t]));
            }
            all=all2;
        }
        write(ans);
    }
};
int main()
{
    srand(time(0));
    mine::main();
}
