#include <bits/stdc++.h>
using namespace std;
const int MAXn = 1e6 + 10, MAXlg = 20 + 4, MOD = 1e9 + 7;
int dp1[MAXn][MAXlg], dp2[MAXn][MAXlg], n, k, ar[MAXn], ar2[MAXn], ar3[MAXn];
long long ans;
void make_dp1() {
  for (int i = 1; i < n; i++) dp1[i][0] = ar[i - 1];
  for (int i = 1; i < MAXlg; i++)
    for (int j = 0; j < n; j++)
      if (j - (1 << i) >= 0)
        dp1[j][i] = max(dp1[j][i - 1], dp1[j - (1 << (i - 1))][i - 1]);
}
void make_dp2() {
  for (int i = 0; i < n - 1; i++) dp2[i][0] = ar[i + 1];
  for (int i = 1; i < MAXlg; i++)
    for (int j = 0; j < n; j++)
      if (j + (1 << i) < n)
        dp2[j][i] = max(dp2[j][i - 1], dp2[j + (1 << (i - 1))][i - 1]);
}
int query1(int a, int num) {
  int ansq = 0;
  for (int i = MAXlg - 1; i >= 0; i--) {
    if (a - (1 << i) >= 0 && dp1[a][i] <= num) {
      ansq += (1 << i);
      a -= (1 << i);
    }
  }
  return ansq;
}
int query2(int a, int num) {
  int ansq = 0;
  for (int i = MAXlg - 1; i >= 0; i--) {
    if (a + (1 << i) < n && dp2[a][i] < num) {
      ansq += (1 << i);
      a += (1 << i);
    }
  }
  return ansq;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> ar[i];
  make_dp1();
  make_dp2();
  if (k == 2) {
    for (int i = 2; i < MAXn; i++)
      ar3[i] = ((long long)ar3[i - 1] + i - 1) % MOD;
  } else {
    ar3[k] = 1;
    ar2[k] = 1;
    for (int i = k + 1; i < MAXn; i++) {
      ar2[i] = ar2[i - 1];
      if (i % (k - 1) == 1) ar2[i]++;
      ar2[i] %= MOD;
      ar3[i] = ((long long)ar3[i - 1] + ar2[i]) % MOD;
      ar3[i] %= MOD;
    }
  }
  for (int i = 0; i < n; i++) {
    long long l = query1(i, ar[i]), r = query2(i, ar[i]),
              hp = ((long long)ar3[l + r + 1] - ar3[l] - ar3[r] + MOD) % MOD,
              hp2 = ar[i], ans2 = (hp * hp2) % MOD;
    ans = ((long long)ans + ans2) % MOD;
  }
  cout << ans;
}
