#include <bits/stdc++.h>
using namespace std;
std::string dbgDelim(int &i) { return (i++ == 0 ? "" : ", "); }
template <class T>
std::ostream &operator<<(std::ostream &os, std::vector<T> v);
template <class T>
std::ostream &operator<<(std::ostream &os, std::set<T> v);
template <class T>
std::ostream &operator<<(std::ostream &os, std::queue<T> q);
template <class T>
std::ostream &operator<<(std::ostream &os, std::priority_queue<T> q);
template <class T, class K>
std::ostream &operator<<(std::ostream &os, std::pair<T, K> p);
template <class T, class K>
std::ostream &operator<<(std::ostream &os, std::map<T, K> mp);
template <class T, class K>
std::ostream &operator<<(std::ostream &os, std::unordered_map<T, K> mp);
template <int INDEX, class TUPLE>
void dbgDeploy(std::ostream &os, TUPLE _) {}
template <int INDEX, class TUPLE, class H, class... Ts>
void dbgDeploy(std::ostream &os, TUPLE t) {
  os << (INDEX == 0 ? "" : ", ") << get<INDEX>(t);
  dbgDeploy<INDEX + 1, TUPLE, Ts...>(os, t);
}
template <class T, class K>
void dbgDeploy(std::ostream &os, std::pair<T, K> p, std::string delim) {
  os << "(" << p.first << delim << p.second << ")";
}
template <class... Ts>
std::ostream &operator<<(std::ostream &os, std::tuple<Ts...> t) {
  os << "(";
  dbgDeploy<0, std::tuple<Ts...>, Ts...>(os, t);
  os << ")";
  return os;
}
template <class T, class K>
std::ostream &operator<<(std::ostream &os, std::pair<T, K> p) {
  dbgDeploy(os, p, ", ");
  return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, std::vector<T> v) {
  {
    int i = 0;
    os << "{";
    {
      for (T t : v) {
        os << dbgDelim(i) << t;
      };
    }
    os << "}";
    return os;
  };
}
template <class T>
std::ostream &operator<<(std::ostream &os, std::set<T> s) {
  {
    int i = 0;
    os << "{";
    {
      for (T t : s) {
        os << dbgDelim(i) << t;
      };
    }
    os << "}";
    return os;
  };
}
template <class T>
std::ostream &operator<<(std::ostream &os, std::queue<T> q) {
  {
    int i = 0;
    os << "{";
    {
      for (; q.size(); q.pop()) {
        os << dbgDelim(i) << q.front();
      };
    }
    os << "}";
    return os;
  };
}
template <class T>
std::ostream &operator<<(std::ostream &os, std::priority_queue<T> q) {
  {
    int i = 0;
    os << "{";
    {
      for (; q.size(); q.pop()) {
        os << dbgDelim(i) << (T)q.top();
      };
    }
    os << "}";
    return os;
  };
}
template <class T, class K>
std::ostream &operator<<(std::ostream &os, std::map<T, K> mp) {
  {
    int i = 0;
    os << "{";
    {
      for (auto p : mp) {
        os << dbgDelim(i);
        dbgDeploy(os, p, "->");
      };
    }
    os << "}";
    return os;
  };
}
template <class T, class K>
std::ostream &operator<<(std::ostream &os, std::unordered_map<T, K> mp) {
  {
    int i = 0;
    os << "{";
    {
      for (auto p : mp) {
        os << dbgDelim(i);
        dbgDeploy(os, p, "->");
      };
    }
    os << "}";
    return os;
  };
}
class State {
 public:
  State(int64_t l, int64_t k, int64_t num, State *inner)
      : l(l),
        k(k),
        cache(make_pair(0, -1)),
        q(queue<int64_t>()),
        total_score(0),
        inner(inner) {}
  int64_t score(int64_t num) {
    if (num == 0) return 0;
    if (cache.first) return cache.second;
    while (l <= ((int64_t)((q).size())) + num) {
      total_score += q.front();
      q.pop();
    }
    int64_t next_num = num + this->num;
    int64_t next_k = k;
    while (0 < next_num && next_k < inner->k) {
      next_k += 1;
      next_num /= l;
    }
    int64_t ans = total_score;
    if (next_k == inner->k) ans += inner->score(next_num);
    cache = make_pair(1, ans);
    return ans;
  }
  void inc(int64_t n) {
    cache.first = 0;
    q.push(n);
  }
  pair<int64_t, int64_t> cache;
  int64_t l;
  int64_t k;
  queue<int64_t> q;
  int64_t total_score;
  int64_t num;
  State *inner;
};
int main() {
  State *state = new State(-1, (((int64_t)1) << ((int64_t)(50))), 1, NULL);
  int64_t n, l;
  cin >> n >> l;
  int64_t ans = 0;
  for (int64_t step = 0; (step) < ((int64_t)(n)); ++(step)) {
    int64_t k;
    cin >> k;
    while (state->k < k) {
      int64_t cur_k = state->k;
      int64_t cur_num = state->num;
      state = state->inner;
      int64_t t = 1;
      for (int64_t i = cur_k; t <= cur_num && i < state->k; ++i) {
        t *= l;
      }
      if (t <= cur_num) {
        vector<int64_t> v;
        while (0 < cur_num) {
          if (cur_num < 2 * t) {
            v.push_back(cur_num);
            cur_num = 0;
          } else {
            v.push_back(t);
            cur_num -= t;
          }
        }
        reverse(v.begin(), v.end());
        for (auto d : v) state->inc(d);
      }
    }
    if (state->k == k) {
      ans += state->score(1);
      state->inc(1);
    } else {
      state = new State(l, k, 1, state);
      state->inc(1);
    }
  }
  cout << ans + n << endl;
}
