func_code_string: #include <bits/stdc++.h>   using std::cin;   using std::cout;   const long long N = 1e6 + 17, mo = 1e9 + 7;   long long f[N][2], n, h[N];   inline long long min(long long x, long long y) { return x > y ? y : x; }   inline long long quickmod(long long x) { return x >= mo ? x - mo : x; }   signed main() {     std::ios::sync_with_stdio(0);     cin >> n;     for (long long i = 1; i <= n; ++i) {       cin >> h[i];       --h[i];     }     f[1][0] = h[1];     f[1][1] = min(h[1], h[2]);     long long ans = f[1][0];     for (long long i = 2; i <= n; ++i) {       f[i][0] = quickmod(h[i] + min(h[i], h[i - 1]) * f[i - 1][1] % mo);       f[i][1] = quickmod(min(h[i], h[i + 1]) +                          min(min(h[i], h[i - 1]), h[i + 1]) * f[i - 1][1] % mo);       ans = quickmod(ans + f[i][0]);     }     cout << ans <<   n ;     return 0;   }   