malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-12;   const int INF = 999999999;   const int kMod = 1000000007;   const int kMaxN = 100010;   char a[kMaxN], b[kMaxN];   int p10[kMaxN], p2[kMaxN], seq[kMaxN];   int F[kMaxN], S[kMaxN];   int P10(int n) {     int &res = p10[n];     if (res != -1) return res;     return res = (n == 0) ? 1 : ((long long)P10(n - 1) * 10) % kMod;   }   int P2(int n) {     int &res = p2[n];     if (res != -1) return res;     return res = (n == 0) ? 1 : ((long long)P2(n - 1) * 2) % kMod;   }   int ComSeq(int n) {     int &res = seq[n];     if (res != -1) return res;     if (n == 0) return res = 0;     return res = ((long long)ComSeq(n - 1) * 10 + 1) % kMod;   }   int ComS(int n) {     int &res = S[n];     if (res != -1) return res;     if (n == 0) return res = 0;     res = ((long long)ComS(n - 1) * 20) % kMod;     res = (res + (long long)P2(n - 1) * 11) % kMod;     return res;   }   int ComG(int n) {     int res = ((long long)ComS(n) * 2) % kMod;     res = (res - (long long)ComSeq(n) * 11) % kMod;     return res;   }   int ComF(int n) {     int &res = F[n];     if (res != -1) return res;     res = 0;     if (n == 0) return res;     int p = ((long long)P10(n - 1) * 4) % kMod;     int w1 = (p + (long long)ComSeq(n - 1) * 7) % kMod;     res = (res + (((long long)p * p) % kMod) * (P2(n - 1) - 1)) % kMod;     res = (res + p * (long long)ComG(n - 1)) % kMod;     res = (res + ComF(n - 1)) % kMod;     p = ((long long)P10(n - 1) * 7) % kMod;     int w2 = (p + (long long)ComSeq(n - 1) * 4) % kMod;     res = (res + (((long long)p * p) % kMod) * (P2(n - 1) - 1)) % kMod;     res = (res + p * (long long)ComG(n - 1)) % kMod;     res = (res + ComF(n - 1)) % kMod;     res = (res + (long long)w1 * w2) % kMod;     return res;   }   int Solve(const char a[]) {     int n = strlen(a);     int res = 0;     int prefix = 0;     for (int i = n - 1; i >= 0; --i) {       int d = a[n - 1 - i] -  0 ;       int next_prefix = (prefix + (long long)P10(i) * d) % kMod;       if (d == 7) {         int p = (prefix + (long long)P10(i) * 4) % kMod;         if (i > 0) {           res = (res + (((long long)p * p) % kMod) * (P2(i) - 1)) % kMod;           res = (res + (long long)p * ComG(i)) % kMod;           res = (res + ComF(i)) % kMod;         }         int w1 = (p + (long long)ComSeq(i) * 7) % kMod;         int w2 = (next_prefix + (long long)ComSeq(i) * 4) % kMod;         res = (res + (long long)w1 * w2) % kMod;       }       prefix = next_prefix;     }     return res;   }   int main() {     scanf( %s , a);     scanf( %s , b);     memset(p10, -1, sizeof(p10));     memset(p2, -1, sizeof(p2));     memset(seq, -1, sizeof(seq));     memset(F, -1, sizeof(F));     memset(S, -1, sizeof(S));     int res = Solve(b);     res = (res - Solve(a)) % kMod;     if (res < 0) res += kMod;     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, i, j, r = 1;     cin >> n;     int a[n][n];     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (i % 2 == 0) {           a[i][j] = r;           r++;         } else {           a[i][n - j - 1] = r;           r++;         }       }     }     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         cout << a[j][i] <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void Int(T &n) {     n = 0;     int f = 1;     int ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch -  0 ;     n = n * f;   }   template <typename T>   T gcd(T a, T b) {     return !b ? a : gcd(b, a % b);   }   template <typename T>   inline void umin(T &a, T b) {     a = a < b ? a : b;   }   template <typename T>   inline void umax(T &a, T b) {     a = a > b ? a : b;   }   template <typename T, typename W>   inline void Int(T &x, W &y) {     Int(x), Int(y);   }   template <typename T, typename W, typename Q>   inline void Int(T &x, W &y, Q &z) {     Int(x, y), Int(z);   }   const int N = 1e5 + 7;   const int inf = 1e9 + 7;   int dp[N];   int lev[N];   vector<int> g[N];   vector<pair<int, int>> edges;   int dfs(int u, int p = -1) {     dp[u] = 0;     for (int v : g[u]) {       if (lev[v] == 0) {         lev[v] = lev[u] + 1;         edges.push_back({u, v});         dp[u] += dfs(v, u);       } else if (lev[u] > lev[v] && v != p) {         ++dp[u];         --dp[v];         edges.push_back({u, v});       }     }     if (p != -1 && dp[u] == 0) {       printf( 0 n );       exit(0);     }     return dp[u];   }   int solve() {     int n, m;     Int(n, m);     for (int i = 1; i <= m; ++i) {       int u, v;       Int(u, v);       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= n; ++i) {       if (!lev[i]) {         lev[i] = 1;         dfs(i);       }     }     for (auto [u, v] : edges) {       printf( %d %d n , u, v);     }     return 0;   }   int main() {     int tests = 1, CaseNo = 0;     while (tests--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[10000], i, t, n, j, x;   int main() {     cin >> t;     while (t--) {       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> x;         if (x <= 2048) a[x]++;       }       j = 1;       while (j < 2048) {         a[j * 2] += a[j] / 2;         a[j] = 0;         j *= 2;       }       if (a[2048] > 0) {         cout <<  YES  << endl;       } else         cout <<  NO  << endl;       a[2048] = 0;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n;     cin >> n;     int r, c;     int diff = 1000000;     for (int a = 1; a * a <= n; a++)       for (int b = a; a * b <= n; b++)         if (a * b == n && b - a < diff) r = a, c = b;     cout << r <<     << c;   }
#include <bits/stdc++.h>   const long long oo = 1e16;   using namespace std;   const int N = 1000005;   long long n, dp[N];   long long num(long long n) {     if (n == 0) return 0;     if (dp[n] != -1) return dp[n];     string s = to_string(n);     long long res = oo;     for (int i = 0; i < s.size(); i++)       if (s[i] !=  0 ) res = min(res, 1 + num(n - (s[i] -  0 )));     return dp[n] = res;   }   int main() {     cin >> n;     memset(dp, -1, sizeof(dp));     cout << num(n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m;     cin >> n >> m;     long long start = 0, end = 6 * (n + m);     while (start <= end) {       long long mid = (start + end) / 2;       long long val1 = (mid / 2) - (mid / 6);       long long val2 = (mid / 3) - (mid / 6);       if ((mid / 6) >= (max(n - val1, 0LL) + max(m - val2, 0LL))) {         end = mid - 1;       } else {         start = mid + 1;       }     }     cout << start << endl;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       int flag = 1;       int st;       char c = s[0];       for (int i = 1; i < n; i++) {         if (s[i] == c)           continue;         else {           st = i;           flag = 0;           break;         }       }       if (flag == 1) {         cout << (n + 2) / 3 << endl;         continue;       }       int ans = 0;       int m = 1;       c = s[st];       int val = (st + 1) % n;       for (int i = val; i != st; i = ((i + 1) % n)) {         if (s[i] == c) {           m++;         } else {           if (m >= 3) ans += (m) / 3;           c = s[i];           m = 1;         }       }       if (m >= 3) ans += (m / 3);       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace Solve {   const int MAXN = 3005;   inline int mymin(int a, int b) { return a < b ? a : b; }   inline int mymax(int a, int b) { return a > b ? a : b; }   int Log[MAXN], maxid[MAXN][20];   void getLog() {     Log[1] = 0;     for (int i = 2; i <= 3000; i++) {       if (i & 1)         Log[i] = Log[i - 1];       else         Log[i] = Log[i >> 1] + 1;     }     return;   }   void getST(int *A, int n) {     for (int i = 1; i <= n; i++) maxid[i][0] = i;     for (int k = 1; k <= 12; k++) {       for (int i = 1; i + (1 << k) - 1 <= n; i++) {         int f = i + (1 << (k - 1));         if (A[maxid[i][k - 1]] > A[maxid[f][k - 1]])           maxid[i][k] = maxid[i][k - 1];         else           maxid[i][k] = maxid[f][k - 1];       }     }     return;   }   struct Data {     int id, val;     Data(int a = 0, int b = 0) : id(a), val(b) {}     bool operator<(const Data &B) const { return val > B.val; }   } A[MAXN];   int N, D[MAXN], awd[MAXN];   int Qmaxid(int l, int r) {     if (l > r) return 0;     int k = Log[r - l + 1];     int f = r - (1 << k) + 1;     if (D[maxid[l][k]] > D[maxid[f][k]]) return maxid[l][k];     return maxid[f][k];   }   void work() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) scanf( %d , &A[i].val), A[i].id = i;     sort(A + 1, A + N + 1);     A[0].val = 0;     for (int i = 1; i <= N; i++) D[i] = A[i - 1].val - A[i].val;     D[N + 1] = A[N].val;     getLog();     getST(D, N + 1);     int mxi = -1, mxj = -1, mxk = -1, ansi = -1, ansj = -1, ansk = -1;     for (int i = 1; i < N; i++) {       if (A[i].val - A[i + 1].val < mxi) continue;       for (int j = i + 1; j < N; j++) {         if (i > 2 * (j - i)) continue;         if (j - i > 2 * i) break;         if (A[i].val - A[i + 1].val == mxi && A[j].val - A[j + 1].val < mxj)           continue;         int milen = mymin(i, j - i);         int mxlen = mymax(i, j - i);         int low = j + ((mxlen + 1) >> 1) + 1, upp = j + (milen << 1) + 1;         if (low > N + 1) continue;         if (upp > N + 1) upp = N + 1;         int mxid = Qmaxid(low, upp);         if (A[i].val - A[i + 1].val == mxi && A[j].val - A[j + 1].val == mxj &&             D[mxid] < mxk)           continue;         mxi = A[i].val - A[i + 1].val;         mxj = A[j].val - A[j + 1].val;         mxk = D[mxid];         ansi = i, ansj = j, ansk = mxid - 1;       }     }     for (int i = 1; i <= ansi; i++) awd[A[i].id] = 1;     for (int i = ansi + 1; i <= ansj; i++) awd[A[i].id] = 2;     for (int i = ansj + 1; i <= ansk; i++) awd[A[i].id] = 3;     for (int i = ansk + 1; i <= N; i++) awd[A[i].id] = -1;     for (int i = 1; i <= N; i++) printf( %d  , awd[i]);     printf(  n );     return;   }   }  // namespace Solve   int main() {     Solve::work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005, K = 105, P = 998244353;   using ll = long long;   ll dp[N][K], sum[N], cnt[N][K];   inline bool cmp(int a, int b) { return a == -1 || b == -1 || a == b; }   int n, kk, len, a[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> kk >> len;     if (len == 1) {       puts( 0 );       return 0;     }     for (int i = 1; i <= n; i++) {       cin >> a[i];       for (int j = 1; j <= kk; j++) cnt[i][j] = cnt[i - 1][j] + cmp(a[i], j);     }     sum[0] = 1;     if (a[1] == -1) {       for (int i = 1; i <= kk; i++) dp[1][i] = 1;       sum[1] = kk;     } else       sum[1] = 1, dp[1][a[1]] = 1;     for (int i = 2; i <= n; i++)       for (int j = 1; j <= kk; j++)         if (cmp(a[i], j)) {           dp[i][j] = sum[i - 1];           if (i >= len && cnt[i][j] - cnt[i - len][j] == len) {             dp[i][j] = ((dp[i][j] - sum[i - len] + dp[i - len][j]) % P + P) % P;           }           sum[i] = (sum[i] + dp[i][j]) % P;         }     cout << sum[n] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 1000 + 5;   const int mod = 1000 * 1000 * 1000 + 7;   int a[65], b[65];   int main() {     ios_base::sync_with_stdio(false);     long long l, r;     cin >> l >> r;     for (int i = 0; l > 0; l /= 2, i++) a[i] = l % 2;     for (int i = 0; r > 0; r /= 2, i++) b[i] = r % 2;     int i;     for (i = 60; i >= 0 && a[i] == b[i]; i--)       ;     if (i == -1)       cout << 0 << endl;     else       cout << (1ll << (i + 1)) - 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct seg {     vector<int> id;     map<pair<int, int>, int> st;     int getid(int l, int r) {       int L = lower_bound(id.begin(), id.end(), l) - id.begin();       int R = upper_bound(id.begin(), id.end(), r) - id.begin() - 1;       if (L > R) return -1;       return st[make_pair(L, R)];     }   } tr[20000];   vector<pair<int, int> > res;   int cur;   int merge(int x, int y) {     if (x == -1 || y == -1)       return max(x, y);     else {       res.emplace_back(x, y);       cur++;       return cur;     }   }   int blk, tot, Tid = 0;   int n, q, a[5000], Id[5000], l[5000], r[5000];   int solve(int l, int r, vector<int> id) {     Tid++;     int k;     tr[k = Tid].id = id;     if (l == r) {       tr[Tid].st[pair<int, int>(0, 0)] = id[0];       return Tid;     }     int mid = (l + r) >> 1;     vector<int> lid, rid;     for (auto x : id)       if (a[x] <= mid)         lid.push_back(x);       else         rid.push_back(x);     int ls = solve(l, mid, lid), rs = solve(mid + 1, r, rid);     for (int i = 0; i < id.size(); i++)       for (int j = i; j < id.size(); j++)         tr[k].st[pair<int, int>(i, j)] =             merge(tr[ls].getid(id[i], id[j]), tr[rs].getid(id[i], id[j]));     return k;   }   int main() {     scanf( %d%d , &n, &q);     blk = sqrt(q);     cur = n;     for (int i = 1; i <= (tot = n / blk); i++)       l[i] = r[i - 1] + 1, r[i] = i * blk;     if (tot * blk != n) l[++tot] = r[tot - 1] + 1, r[tot] = n;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= tot; i++) {       vector<int> id;       for (int j = 1; j <= n; j++)         if (l[i] <= a[j] && a[j] <= r[i]) id.push_back(j);       Id[i] = solve(l[i], r[i], id);     }     vector<int> ans;     for (int l, r; q--;) {       scanf( %d%d , &l, &r);       int rest = -1;       for (int i = 1; i <= tot; i++) rest = merge(rest, tr[Id[i]].getid(l, r));       ans.push_back(rest);     }     printf( %d n , cur);     for (auto x : res) printf( %d %d n , x.first, x.second);     for (int x : ans) printf( %d  , x);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n], b[n];       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) cin >> b[i];       sort(a, a + n);       sort(b, b + n);       for (int i = 0; i < n; i++) cout << a[i] <<    ;       cout << endl;       for (int i = 0; i < n; i++) cout << b[i] <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> tst[100005];   int rep[100005];   int idx[100005];   int arr[100005];   pair<int, int> sw[1000000];   int ns;   int num, id;   int islucky(int x) {     for (; x > 0; x /= 10)       if (x % 10 != 4 and x % 10 != 7) return 0;     return 1;   }   int main() {     int i, j;     int a, b, c, d;     int n;     ns = 0;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &arr[i]);       tst[i] = pair<int, int>(arr[i], i);     }     sort(tst, tst + n);     for (i = 0; i < n; i++) {       rep[i] = tst[i].first;       idx[i] = tst[i].second;       arr[tst[i].second] = i;     }     num = -1;     for (i = 0; i < n; i++) {       if (islucky(rep[i])) {         num = i;         id = idx[i];         break;       }     }     if (num == -1) {       for (i = 0; i < n - 1; i++)         if (arr[i] > arr[i + 1]) {           printf( -1 n );           return 0;         }     }     for (i = 0; i < n; i++) {       if (i == num or i == arr[i]) continue;       a = i;       b = id;       c = idx[i];       d = arr[i];       if (a != b) sw[ns++] = pair<int, int>(a, b);       if (a != c) sw[ns++] = pair<int, int>(a, c);       idx[num] = id = c;       idx[i] = a;       idx[arr[i]] = b;       swap(arr[a], arr[b]);       swap(arr[a], arr[c]);     }     printf( %d n , ns);     for (i = 0; i < ns; i++) printf( %d %d n , sw[i].first + 1, sw[i].second + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, k;     cin >> n >> k;     vector<pair<int, int> > v;     string a;     cin >> a;     int balance_max = 0;     int balance_min = 0;     v.push_back(pair<int, int>(0, 0));     for (int i = 0; i < n - 1; i++) {       if (a[i] ==  W ) {         balance_min++;         if (balance_max < k - 1) balance_max++;       } else if (a[i] ==  L ) {         balance_max--;         if (balance_min > 1 - k) balance_min--;       } else if (a[i] ==  ? ) {         if (balance_max < k - 1) balance_max++;         if (balance_min > 1 - k) balance_min--;       }       v.push_back(pair<int, int>(balance_min, balance_max));       if (balance_max < balance_min) {         cout <<  NO  << endl;         return 0;       }     }     if (a[n - 1] ==  W ) {       balance_min++;       balance_max++;     } else if (a[n - 1] ==  L ) {       balance_min--;       balance_max--;     } else if (a[n - 1] ==  ? ) {       balance_min--;       balance_max++;     }     v.push_back(pair<int, int>(balance_min, balance_max));     int pos = k;     string solve =   ;     if (balance_max == k) {       pos = k;     } else if (balance_min == -k) {       pos = -k;     } else {       cout <<  NO  << endl;       return 0;     }     for (int i = n - 1; i >= 0; i--) {       if (a[i] ==  L ) {         pos++;         solve +=  L ;       } else if (a[i] ==  W ) {         pos--;         solve +=  W ;       } else if (a[i] ==  D ) {         solve +=  D ;       } else if (a[i] ==  ? ) {         if (v[i].second < pos) {           pos--;           solve +=  W ;         } else if (v[i].first > pos) {           pos++;           solve +=  L ;         } else           solve +=  D ;       }     }     reverse(solve.begin(), solve.end());     cout << solve << endl;   }
#include <bits/stdc++.h>   #pragma GCC optimize(3,  Ofast ,  inline )   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   const long long maxn = (long long)1e6 + 5;   const long long mod = 998244353;   const long long inf = 0x3f3f3f3f;   long long T = 1;   struct edge {     long long u, v, colu, colv;     bool operator<(const edge &b) const {       if (colu != b.colu) return colu < b.colu;       return colv < b.colv;     };   } v[maxn];   long long tot = 0;   struct node {     long long u, v, fa, siz;   };   stack<node> s;   long long pre[maxn];   long long find(long long x) {     while (x != pre[x]) x = pre[x];     return pre[x];   }   long long siz[maxn];   void unite(long long u, long long v) {     u = find(u), v = find(v);     if (siz[u] > siz[v]) swap(u, v);     s.push({u, v, pre[u], siz[u]});     if (u != v) {       pre[u] = v;       siz[v] += siz[u];       siz[u] = 0;     }   }   void restore() {     node now = s.top();     s.pop();     if (now.u != now.v) {       pre[now.u] = now.fa;       siz[now.u] = now.siz;       siz[now.v] -= now.siz;     }   }   long long col[maxn];   bool no[maxn];   void solve() {     long long n, m, k;     cin >> n >> m >> k;     long long cnt = k;     for (long long i = 1; i <= n; ++i) cin >> col[i];     for (long long i = 1; i <= 2 * n; ++i) pre[i] = i, siz[i] = 1;     for (long long i = 1; i <= m; ++i) {       long long x, y;       cin >> x >> y;       if (col[x] != col[y]) {         v[++tot] = edge({x, y, col[x], col[y]});         if (col[x] > col[y]) swap(v[tot].colu, v[tot].colv);         continue;       }       if (no[col[x]]) continue;       if (find(x) == find(y)) {         --cnt;         no[col[x]] = true;         continue;       }       unite(x, y + n);       unite(y, x + n);     }     long long ans = (cnt - 1) * cnt / 2;     bool flag = false;     sort(v + 1, v + tot + 1);     long long last = s.size();     for (long long i = 1; i <= tot; ++i) {       edge now = v[i];       if (no[now.colu] || no[now.colv]) continue;       if (now.colu != v[i - 1].colu || now.colv != v[i - 1].colv) {         while (s.size() != last) restore();         flag = false;       }       if (flag) continue;       if (find(now.u) == find(now.v)) {         --ans;         flag = true;         continue;       }       unite(now.u, now.v + n);       unite(now.v, now.u + n);     }     cout << ans;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     while (T--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000000;   const long long longinf = 1000000000000000000;   const double PI = 3.141592653589793;   const long long mod = 1000000007;   long long d[100][2];   void solve() {     int n;     cin >> n;     vector<long long> v(n);     for (int i = 0; i < n; ++i) {       cin >> v[i];     }     vector<long long> sm(n + 1, 0);     for (int i = n - 1; i >= 0; --i) {       sm[i] = sm[i + 1] + v[i];     }     d[n][0] = 0;     d[n][1] = 0;     for (int i = n - 1; i >= 0; --i) {       for (int h = 0; h <= 1; ++h) {         d[i][h] = max(d[i + 1][h], v[i] + sm[i + 1] - d[i + 1][h ^ 1]);       }     }     cout << sm[0] - d[0][0] <<     << d[0][0] << endl;   }   int main() {     cout.precision(20);     cin.tie(0);     iostream::sync_with_stdio(false);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long Mul(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;       b >>= 1;     }     return res;   }   int A[200005];   long long F[200005], NF[200005], sum[200005], Two[200005];   long long C(int n, int m) {     return F[n] * NF[m] % 1000000007 * NF[n - m] % 1000000007;   }   int main() {     int n;     long long T;     scanf( %d%lld , &n, &T);     for (int i = 1; i <= n; i++) scanf( %d , &A[i]), sum[i] = sum[i - 1] + A[i];     F[0] = 1;     NF[0] = 1;     for (int i = 1; i <= max(n, 2); i++) F[i] = F[i - 1] * i % 1000000007;     for (int i = 1; i <= max(n, 2); i++) NF[i] = Mul(F[i], 1000000007 - 2);     Two[0] = 1;     for (int i = 1; i <= n; i++) Two[i] = Two[i - 1] * NF[2] % 1000000007;     long long ans = 0, res = 1;     int lst = 0;     for (int i = 1; i <= n; i++) {       res = (2ll * res % 1000000007 - C(i - 1, lst)) % 1000000007;       if (i + sum[i] <= T) {         ans++;         ans %= 1000000007;         continue;       }       if (T - sum[i] < 0) break;       long long R = T - sum[i];       for (int j = lst + 1; j <= R; j++) res = (res + C(i, j)) % 1000000007;       for (int j = lst; j >= R + 1; j--) res = (res - C(i, j)) % 1000000007;       lst = R;       ans = (ans + 1ll * res * Two[i] % 1000000007) % 1000000007;     }     printf( %lld n , (ans + 1000000007) % 1000000007);     return 0;   }