func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class S, class T>   ostream& operator<<(ostream& o, const pair<S, T>& p) {     return o <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& o, const vector<T>& vc) {     o <<  { ;     for (const T& v : vc) o << v <<  , ;     o <<  } ;     return o;   }   using ll = long long;   template <class T>   using V = vector<T>;   template <class T>   using VV = vector<vector<T>>;   constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }   template <unsigned int mod_>   struct ModInt {     using uint = unsigned int;     using ll = long long;     using ull = unsigned long long;     constexpr static uint mod = mod_;     uint v;     ModInt() : v(0) {}     ModInt(ll _v) : v(normS(_v % mod + mod)) {}     explicit operator bool() const { return v != 0; }     static uint normS(const uint& x) { return (x < mod) ? x : x - mod; }     static ModInt make(const uint& x) {       ModInt m;       m.v = x;       return m;     }     ModInt operator+(const ModInt& b) const { return make(normS(v + b.v)); }     ModInt operator-(const ModInt& b) const { return make(normS(v + mod - b.v)); }     ModInt operator-() const { return make(normS(mod - v)); }     ModInt operator*(const ModInt& b) const { return make((ull)v * b.v % mod); }     ModInt operator/(const ModInt& b) const { return *this * b.inv(); }     ModInt& operator+=(const ModInt& b) { return *this = *this + b; }     ModInt& operator-=(const ModInt& b) { return *this = *this - b; }     ModInt& operator*=(const ModInt& b) { return *this = *this * b; }     ModInt& operator/=(const ModInt& b) { return *this = *this / b; }     ModInt& operator++(int) { return *this = *this + 1; }     ModInt& operator--(int) { return *this = *this - 1; }     ll extgcd(ll a, ll b, ll& x, ll& y) const {       ll p[] = {a, 1, 0}, q[] = {b, 0, 1};       while (*q) {         ll t = *p / *q;         for (int i = 0; i < (int)(3); i++) swap(p[i] -= t * q[i], q[i]);       }       if (p[0] < 0)         for (int i = 0; i < (int)(3); i++) p[i] = -p[i];       x = p[1], y = p[2];       return p[0];     }     ModInt inv() const {       ll x, y;       extgcd(v, mod, x, y);       return make(normS(x + mod));     }     ModInt pow(ll p) const {       if (p < 0) return inv().pow(-p);       ModInt a = 1;       ModInt x = *this;       while (p) {         if (p & 1) a *= x;         x *= x;         p >>= 1;       }       return a;     }     bool operator==(const ModInt& b) const { return v == b.v; }     bool operator!=(const ModInt& b) const { return v != b.v; }     friend istream& operator>>(istream& o, ModInt& x) {       ll tmp;       o >> tmp;       x = ModInt(tmp);       return o;     }     friend ostream& operator<<(ostream& o, const ModInt& x) { return o << x.v; }   };   using mint = ModInt<1000000007>;   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     cout << fixed << setprecision(20);     int N, Q;     cin >> N >> Q;     V<ll> A(N);     for (int i = 0; i < (int)(N); i++) cin >> A[i];     V<mint> p2(N + 1);     p2[0] = 1;     for (int i = 1; i <= (int)(N); i++) p2[i] = p2[i - 1] * 2;     struct link {       int to;       mint sum;       ll sum2;     };     V<link> ls(N);     const ll inf = 1e9;     for (int i = 0; i < (int)(N); i++) {       link cur{i, A[i], A[i]};       while (cur.to > 0 && cur.sum2 > 0) {         link x = ls[cur.to - 1];         link nxt;         nxt.to = x.to;         nxt.sum = cur.sum * p2[cur.to - x.to] + x.sum;         nxt.sum2 = (cur.sum2 << min(cur.to - x.to, 30)) + x.sum2;         nxt.sum2 = min(nxt.sum2, inf);         cur = nxt;       }       ls[i] = cur;     }     const int H = 20;     V<array<pair<int, mint>, H>> par(N + 1);     for (int h = 0; h < (int)(H); h++) par[0][h] = {-1, 0};     for (int i = 0; i < (int)(N); i++) {       par[i + 1][0] = {ls[i].to, ls[i].sum};       for (int h = 1; h <= (int)(H - 1); h++) {         int j;         mint js;         tie(j, js) = par[i + 1][h - 1];         if (j == -1) {           par[i + 1][h] = {-1, 0};         } else {           int k;           mint ks;           tie(k, ks) = par[j][h - 1];           if (k == -1)             par[i + 1][h] = {-1, 0};           else             par[i + 1][h] = {k, js + ks};         }       }     }     V<mint> sum(N + 1);     for (int i = N - 1; i >= 0; i--) sum[i] = sum[i + 1] * 2 + A[i];     for (int _ = 0; _ < (int)(Q); _++) {       int l, r;       cin >> l >> r;       l--;       mint ans = 0;       for (int h = H - 1; h >= 0; h--) {         if (l + 1 <= par[r][h].first) {           ans += par[r][h].second;           r = par[r][h].first;         }       }       ans *= 2;       ans += sum[l] - sum[r] * p2[r - l];       cout << ans << endl;     }   }   