#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200100;
int N, L;
int arr[MAXN];
bool on[MAXN];
int lo[MAXN], hi[MAXN];
pair<int, int> ord[MAXN];
pair<int, vector<int> > lmap[MAXN], hmap[MAXN];
int ftot[MAXN];
pair<int, vector<int> > dv(int nv) {
  pair<int, vector<int> > res;
  res.first = nv;
  res.second.push_back(0);
  return res;
}
pair<int, vector<int> > gv(pair<int, vector<int> > cv, int nv) {
  long long cdiv = 1;
  for (int i = cv.first; i < nv; i++) {
    cdiv *= L;
    if (cdiv > 1e9) {
      cdiv = 1e9;
      break;
    }
  }
  pair<int, vector<int> > res;
  res.first = nv;
  for (int i = 0; i < cv.second.size(); i++) {
    int fv = cv.second[i];
    if (fv == 0 || fv >= cdiv) {
      res.second.push_back(fv / cdiv);
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> N >> L;
  for (int i = 0; i < N; i++) {
    cin >> arr[i];
    ord[i] = make_pair(arr[i], i);
    on[i] = false;
  }
  sort(ord, ord + N);
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    int cloc = ord[i].second;
    on[cloc] = true;
    int nlo = cloc;
    if (cloc > 0 && on[cloc - 1]) nlo = lo[cloc - 1];
    int nhi = cloc;
    if (cloc < N - 1 && on[cloc + 1]) nhi = hi[cloc + 1];
    hi[nlo] = nhi;
    lo[nhi] = nlo;
    pair<int, vector<int> > lf, lb, rf, rb;
    lf = dv(arr[cloc]);
    lb = dv(arr[cloc]);
    rf = dv(arr[cloc]);
    rb = dv(arr[cloc]);
    if (nlo < cloc) {
      lf = gv(lmap[nlo], arr[cloc]);
      lb = gv(hmap[cloc - 1], arr[cloc]);
    }
    if (nhi > cloc) {
      rf = gv(lmap[cloc + 1], arr[cloc]);
      rb = gv(hmap[nhi], arr[cloc]);
    }
    for (int x : lb.second) {
      int ncnt = rf.second.end() -
                 lower_bound(rf.second.begin(), rf.second.end(), L - 1 - x);
      ans += ncnt;
    }
    int nadd = 1 + lf.second.back();
    for (int x : rf.second) lf.second.push_back(x + nadd);
    nadd = 1 + rb.second.back();
    for (int x : lb.second) rb.second.push_back(x + nadd);
    lmap[nlo] = lf;
    hmap[nhi] = rb;
  }
  cout << N + ans << "\n";
}
