#include "biscuits.h"
#include <bits/stdc++.h>
#define ll long long
#define se second
#define fi first
#define pb push_back
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
typedef pair<ll,ll> pii;
typedef pair<pii,pii> ipii;
const int MAXN = 200;
const int MAXA = 5e4+10;
const int SQRT = 300;
const ll INF = 2e18;
const int MOD = 1e9+7;
const int LOG = 20;
void chmn(auto &a, auto b){ a = min(a, b); }
void chmx(auto &a, auto b){ a = max(a, b); }
ll x, a[MAXN];
unordered_map<int,ll> dp[MAXN];
vector<pii> vec;
ll f(int idx, int add){
if(idx > 60) return 1;
if(dp[idx][add] != 0) return dp[idx][add];
vec.pb({idx,add});
ll way = 0;
if(a[idx]+add >= x){ // bisa x
ll sis = a[idx]+add-x;
way += f(idx+1, sis/2);
}
// bit 0 aja
way += f(idx+1, (a[idx]+add)/2 );
// cout << idx << ' ' << add << ' '<< way << " way\n";
return dp[idx][add] = way;
}
long long count_tastiness(long long X, std::vector<long long> A) {
x = X;
for(int i=0; i<=60; i++) a[i] = (i>=A.size() ? 0 : A[i]);
ll add = 0;
for(int i=0; i<=60; i++){
a[i] += add;
if(a[i] > x){
add = (a[i]-x)/2;
a[i] -= 2*add;
} else add = 0;
// cout << a[i] << ' '<< i << " i\n";
}
ll ANS = f(0,0);
for(auto [i,j] : vec) dp[i][j] = 0;
vec.clear();
return ANS;
}