#include <bits/stdc++.h>
using namespace std;
using INT = long long;
int a[1000100], mx[1000100][22];
int dp[1000100];
int calc(int u, int v) {
  if (u > v) swap(u, v);
  int len = v - u + 1;
  int id = 31 - __builtin_clz(len);
  int ans = max(mx[u][id], mx[v - (1 << id) + 1][id]);
  return ans;
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) mx[i][0] = a[i];
  for (int i = 1; i <= 20; i++) {
    for (int j = 1; j <= n; j++) {
      mx[j][i] = max(mx[j][i - 1], mx[min(n, j + (1 << i - 1))][i - 1]);
    }
  }
  int ans = 0;
  for (int i = n - k + 1; i >= 1; i--) {
    int x = calc(i, i + k - 1);
    int st = 1, ed = (n - i) / (k - 1) + 1;
    if (ed == 1) {
      dp[i] = x;
      continue;
    }
    while (st + 1 < ed) {
      int md = (st + ed) >> 1;
      int r = i + (k - 1) * md;
      if (calc(i, i + k - 1) >= calc(i + k - 1, r))
        st = md;
      else
        ed = md;
    }
    dp[i] = (INT)x * st % 1000000007;
    int id = i + (k - 1) * st;
    dp[i] = (dp[i] + dp[id]) % 1000000007;
  }
  for (int i = 1; i <= n; i++) ans = (ans + dp[i]) % 1000000007;
  cout << ans << endl;
  return 0;
}
