#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const int N = 1000010;
const int oo = 1e9;
const int MOD = 1000000007;
int n, k;
long long a[N], sum = 0;
vector<long long> v[N];
deque<pair<long long, long long> > pr;
deque<long long> st;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  int idx = 1;
  for (int i = 1; i + k - 1 <= n; ++i) {
    while (idx < i + k) {
      while (st.size() && a[idx] > a[st.back()]) st.pop_back();
      st.push_back(idx);
      idx++;
    }
    while (st.size() && st.front() < i) st.pop_front();
    v[i % (k - 1)].push_back(a[st.front()]);
  }
  long long res = 0;
  for (int i = 0; i < k - 1; ++i) {
    sum = 0;
    pr.clear();
    for (int j = v[i].size() - 1; j >= 0; --j) {
      long long cur = 1;
      while (pr.size() && pr.front().first < v[i][j]) {
        cur += pr.front().second;
        sum -= pr.front().first * pr.front().second;
        pr.pop_front();
      }
      sum += cur * v[i][j];
      pr.push_front(make_pair(v[i][j], cur));
      res = (res + sum) % MOD;
    }
  }
  cout << res << endl;
  return 0;
}
