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<algorithm>
#include<cstdio>
#define N 200002
using namespace std;
int a[N],b[N],c[N],d[N],e[N],f[N],i,j,k,m,n,o[N],p[N],q,w;long long x;bool g[N];
inline bool cmp(int u,int v){return c[u]<c[v];}
inline void solve(int u,int v)
{
    for(;c[a[u]]==c[u];g[u=a[u]]=true);
    for(;c[b[v]]==c[v];g[v=b[v]]=true);
    for(j=v,q=0;u<=j;j=a[j])o[++q]=e[j];
    for(j=u,q=0;j<=v;j=b[j])p[++q]=f[j];
    for(j=q,o[q+1]=p[q+1]=0;j;j--)o[j]+=o[j+1],p[j]+=p[j+1];
    for(j=0;j<=q-m;j++)x+=(long long)(o[q-j]-o[q-j+1])*p[m+j];
    for(w=c[u];w!=c[a[u]]&&w!=c[b[v]]&&m<=q;q=j,w++)for(j=k=0;(k+=m)<=q;)o[++j]=o[k],p[j]=p[k];
    if(w!=c[a[u]]&&w!=c[b[v]])b[a[u]]=n+1,a[b[v]]=0;
    else
    {
        for(j=o[q+1]=p[q+1]=0;j<=q-m;j++)x-=(long long)(o[q-j]-o[q-j+1])*p[m+j];
        for(j=1,o[q+1]=p[q+1]=0;j<=q;j++)o[j]-=o[j+1],p[j]-=p[j+1];
        for(j=u,k=0;k<q;j=b[j])c[j]=w,e[j]=o[q-k],f[j]=p[++k];
        a[b[v]]=a[j],b[a[j]]=b[v];
    }
}
int main()
{
    scanf("%d%d",&n,&m),x=n;
    for(i=1;i<=n;i++)scanf("%d",c+i),d[i]=i,e[i]=f[i]=1,a[i]=i-1,b[i]=i+1;
    for(sort(d+1,d+n+1,cmp),i=1;i<=n;i++)if(!g[d[i]])solve(d[i],d[i]);
    return 0&printf("%lld\n",x);
}