#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();
}
