#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     x = 0;     bool w = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) w = 0;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     x = w ? x : -x;   }   const long long N = 1e5 + 10, Mod = 1e9 + 7;   long long n, m, a[N], lg[N], b[N], f[N], c[N], sum[N], d[N], ans[N];   struct en {     long long l, r, id;     bool operator<(const en &x) const { return r < x.r; }   } q[N];   inline long long Get(long long x) { return f[x] ? f[x] = Get(f[x]) : x; }   inline long long ji(long long x, long long y) {     return (b[x] - b[y + 1] * lg[y - x + 1] % Mod + Mod) % Mod;   }   inline void add(long long x, long long y) {     f[x] = y;     c[y] = c[x];     if ((x - c[x] > 30 && sum[y] > 9) || (sum[x] + (sum[y] << x - c[x])) > Mod)       sum[y] = Mod;     else       sum[y] = sum[x] + (sum[y] << x - c[x]);   }   signed main() {     read(n), read(m);     lg[0] = 1;     for (long long i = 1; i <= n; i++)       read(a[i]), sum[i] = a[i], lg[i] = (lg[i - 1] << 1) % Mod, c[i] = i - 1;     for (long long i = 1; i <= m; i++) read(q[i].l), read(q[i].r), q[i].id = i;     for (long long i = n; i >= 1; i--)       b[i] = ((b[i + 1] << 1) + a[i] + Mod) % Mod;     sort(q + 1, q + m + 1);     long long k = 1;     for (long long i = 1; i <= n; i++) {       while (sum[i] >= 0 && c[i]) add(c[i], i);       d[i] = (d[c[i]] + (ji(c[i] + 1, i) << 1) % Mod + Mod) % Mod;       while (q[k].r == i) {         long long x = Get(q[k].l);         ans[q[k].id] = (d[i] - d[x] + ji(q[k].l, x) + Mod) % Mod;         k++;       }     }     for (long long i = 1; i <= m; i++) printf( %lld n , ans[i]);     return 0;   }   