//
// Created by adavy on 7/23/2025.
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#include "biscuits.h"
void insert(map<ll,ll>& mp, ll i, ll x){
    if (mp.count(i)) {
        mp[i] += x;
    } else {
        mp[i] = x;
    }
}
long long count_tastiness(long long x, std::vector<long long> a) {
    int B = 60;
    while(a.size() < B) a.push_back(0);
    vector<ll> divs(B);
    ll total = 0;
    for (int i = 0; i < B; ++i) {
        total += (1LL << i) * a[i];
    }
    ll rem = total;
    for (int i = 0; i < B; ++i) {
        rem -= (1LL << i) * a[i];
        divs[i] = rem / x;
    }
    ll ans = (1LL << B);
    map<ll,ll> blocks;
    blocks[(1LL << B) - 1] = 1;
    for (int i = B - 1; i >= 0; --i) {
        map<ll,ll> blocks2;
        for (auto [k, v] : blocks) {
            ll t = k;
            if (k > divs[i]) {
                ans -= v * (k - divs[i]);
                t = divs[i];
            }
            insert(blocks2, t % (1LL << i), v);
            if (t >= (1LL << i)) {
                insert(blocks2, (1LL << i) - 1, v);
            }
        }
        blocks = move(blocks2);
    }
    return ans;
}
/*
int main() {
    int q;
    assert(scanf("%d", &q) == 1);
    vector<int> k(q);
    vector<long long> x(q);
    vector<vector<long long>> a(q);
    vector<long long> results(q);
    for (int t = 0; t < q; t++) {
        assert(scanf("%d%lld", &k[t], &x[t]) == 2);
        a[t] = vector<long long>(k[t]);
        for (int i = 0; i < k[t]; i++) {
            assert(scanf("%lld", &a[t][i]) == 1);
        }
    }
    fclose(stdin);
    for (int t = 0; t < q; t++) {
        results[t] = count_tastiness(x[t], a[t]);
    }
    for (int t = 0; t < q; t++) {
        printf("%lld\n", results[t]);
    }
    fclose(stdout);
    return 0;
}
*/
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |