#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 55;
const int mod = 1e9 + 7;
inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
inline int mul(int x, int y) { return (long long)x * y % mod; }
inline int fe(int x, int k) {
  int res = 1;
  while (k) {
    if (k & 1) res = mul(res, x);
    x = mul(x, x);
    k >>= 1;
  }
  return res;
}
inline int dv(int x, int k) { return mul(x, fe(k, mod - 2)); }
int n, k;
int a[N];
int L[N], R[N], pre[N];
int f(int l, int r, int R) {
  swap(l, r);
  l = R - l;
  r = R - r;
  return add(pre[r], mod - pre[l - 1]);
}
int main() {
  scanf("%d %d", &n, &k);
  k--;
  for (int i = 1; i <= n + 22; i++) {
    pre[i] = add(pre[i - 1], i / k);
  }
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  vector<int> v;
  for (int i = 1; i <= n; i++) {
    while (v.size() and a[v.back()] <= a[i]) v.pop_back();
    L[i] = v.empty() ? 1 : v.back() + 1;
    v.push_back(i);
  }
  v.clear();
  for (int i = n; i >= 1; i--) {
    while (v.size() and a[v.back()] < a[i]) v.pop_back();
    R[i] = v.empty() ? n : v.back() - 1;
    v.push_back(i);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int l = L[i];
    int r = min(R[i] - k, i);
    if (l <= r) {
      int res = f(l, r, R[i]);
      if (r == i) r--;
      if (l <= r) res = add(res, mod - f(l, r, i - 1));
      ans = add(ans, mul(res, a[i]));
    }
  }
  printf("%d\n", ans);
  return 0;
}

### Prompt

Please create a solution in Cpp to the following problem:

Given an array a of n integers and an integer k (2 ≤ k ≤ n), where each element of the array is denoted by a_i (0 ≤ i < n). Perform the operation z given below on a and print the value of z(a,k) modulo 10^{9}+7.
    
    
      
    function z(array a, integer k):  
        if length(a) < k:  
            return 0  
        else:  
            b = empty array  
            ans = 0  
            for i = 0 .. (length(a) - k):  
                temp = a[i]  
                for j = i .. (i + k - 1):  
                    temp = max(temp, a[j])  
                append temp to the end of b  
                ans = ans + temp  
            return ans + z(b, k)  
    

Input

The first line of input contains two integers n and k (2 ≤ k ≤ n ≤ 10^6) — the length of the initial array a and the parameter k.

The second line of input contains n integers a_0, a_1, …, a_{n - 1} (1 ≤ a_{i} ≤ 10^9) — the elements of the array a.

Output

Output the only integer, the value of z(a,k) modulo 10^9+7.

Examples

Input

3 2
9 1 10


Output

29


Input

5 3
5 8 7 1 9


Output

34

Note

In the first example: 

  * for a=(9,1,10), ans=19 and b=(9,10), 
  * for a=(9,10), ans=10 and b=(10), 
  * for a=(10), ans=0. 



So the returned value is 19+10+0=29.

In the second example: 

  * for a=(5,8,7,1,9), ans=25 and b=(8,8,9), 
  * for a=(8,8,9), ans=9 and b=(9), 
  * for a=(9), ans=0. 



So the returned value is 25+9+0=34.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 55;
const int mod = 1e9 + 7;
inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
inline int mul(int x, int y) { return (long long)x * y % mod; }
inline int fe(int x, int k) {
  int res = 1;
  while (k) {
    if (k & 1) res = mul(res, x);
    x = mul(x, x);
    k >>= 1;
  }
  return res;
}
inline int dv(int x, int k) { return mul(x, fe(k, mod - 2)); }
int n, k;
int a[N];
int L[N], R[N], pre[N];
int f(int l, int r, int R) {
  swap(l, r);
  l = R - l;
  r = R - r;
  return add(pre[r], mod - pre[l - 1]);
}
int main() {
  scanf("%d %d", &n, &k);
  k--;
  for (int i = 1; i <= n + 22; i++) {
    pre[i] = add(pre[i - 1], i / k);
  }
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  vector<int> v;
  for (int i = 1; i <= n; i++) {
    while (v.size() and a[v.back()] <= a[i]) v.pop_back();
    L[i] = v.empty() ? 1 : v.back() + 1;
    v.push_back(i);
  }
  v.clear();
  for (int i = n; i >= 1; i--) {
    while (v.size() and a[v.back()] < a[i]) v.pop_back();
    R[i] = v.empty() ? n : v.back() - 1;
    v.push_back(i);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int l = L[i];
    int r = min(R[i] - k, i);
    if (l <= r) {
      int res = f(l, r, R[i]);
      if (r == i) r--;
      if (l <= r) res = add(res, mod - f(l, r, i - 1));
      ans = add(ans, mul(res, a[i]));
    }
  }
  printf("%d\n", ans);
  return 0;
}

```