#include <bits/stdc++.h>
using namespace std;
long long md = 1e9 + 7;
long long a[300010];
long long fact[300010];
long long step(long long x, long long y) {
  if (y == 0) return 1ll;
  if (y == 1) return x;
  if (y % 2 == 0) {
    long long kik = step(x, y / 2);
    return (kik * kik) % md;
  }
  return (step(x, y - 1) * x) % md;
}
long long C(long long n, long long l, long long r) {
  l = max(0LL, l);
  r = max(0LL, r);
  long long ans = 0;
  for (int k = l; k <= r; k++) {
    ans = (ans +
           fact[n] * step(fact[k], md - 2) % md * step(fact[n - k], md - 2)) %
          md;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  long long n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  fact[0] = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = (fact[i - 1] * i) % md;
  }
  long long curt = 0;
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    curt += a[i];
    if (curt > m) break;
    if (i == n) {
      ans = (ans +
             step(step(2LL, i), md - 2) * C(i, 0, min(i, m - curt)) % md * i) %
            md;
    } else if (i == m) {
      ans = (ans + step(step(2LL, i), md - 2) * i) % md;
    } else {
      if (curt + a[i + 1] + i + 1 <= m) continue;
      ans = (ans +
             step(step(2LL, i + 1), md - 2) *
                 C(i, m - curt - a[i + 1], min(i, m - curt)) % md * i +
             step(step(2LL, i + 1), md - 2) *
                 C(i, m + 1 - curt - a[i + 1], min(i, m - curt)) % md * i) %
            md;
    }
  }
  cout << ans;
}
