func_code_string: #include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const int maxn = 1e6 + 10;   int n, k, cnt[maxn], a[maxn], L[maxn], R[maxn];   stack<pair<int, int> > stk;   int main() {     scanf( %d , &n);     ;     scanf( %d , &k);     ;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     ;     stk.push({INF, 0});     for (int i = 1; i <= n; i++) {       while (stk.top().first < a[i]) stk.pop();       L[i] = stk.top().second + 1;       stk.push({a[i], i});     }     while (stk.size()) stk.pop();     stk.push({INF, n + 1});     for (int i = n; i >= 1; i--) {       while (stk.top().first <= a[i]) stk.pop();       R[i] = stk.top().second - 1;       stk.push({a[i], i});     }     for (int i = 1; i <= n; i++) {       cnt[i] = (cnt[i - 1] + (i - 1) / (k - 1)) % mod;     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       int t = (cnt[R[i] - L[i] + 1] - cnt[i - L[i]] - cnt[R[i] - i]) % mod;       ans += 1LL * t * a[i] % mod;     }     printf( %I64d n , (ans % mod + mod) % mod);     return 0;   }   