malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   long long powmod(long long a, long long b) {     long long res = 1;     for (; b; b >>= 1) {       if (b & 1) (res *= a) %= mod;       (a *= a) %= mod;     }     return res;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     long long ans = 0, now = 1, x = powmod(100, mod - 2);     for (int i = 0; i < n; ++i) {       (ans += now) %= mod;       (now *= a[i]) %= mod;       (now *= x) %= mod;     }     (ans *= powmod(now, mod - 2)) %= mod;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int T = 1;     while (T--) {       string s1, s2;       cin >> s1 >> s2;       long long int ans = 0;       long long int i, j, k;       i = j = k = 0;       long long int n = s2.size();       long long int m = s1.size();       long long int count = 0;       map<long long int, long long int> fs, ls;       while (i < n && j < m) {         if (s2[i] == s1[j]) {           fs[i] = j;           i++;           j++;           count = 0;         } else {           count++;           j++;         }         ans = max(ans, count);       }       ans = max(ans, m - (j));       i = n - 1;       j = m - 1;       while (i >= 0 && j >= 0) {         if (s2[i] == s1[j]) {           i--;           j--;           ls[i] = j;           count = 0;         } else {           count++;           j--;         }         ans = max(ans, count);       }       for (auto x : fs) {         ans = max(ans, ls[x.first] - x.second);       }       ans = max(ans, j + 1);       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void setup() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.precision(15);   }   int dx[] = {1, -1, 0, 0, 0, 0};   int dy[] = {0, 0, 1, -1, 0, 0};   int dz[] = {0, 0, 0, 0, 1, -1};   int k, n, m;   int ANS = 0;   string x[10][10];   int vis[10][10][10];   void dfs(int sz, int sx, int sy) {     int i;     ANS++;     vis[sx][sy][sz] = 1;     int nx, ny, nz;     for (i = 0; i < 6; i++) {       nx = sx + dx[i];       ny = sy + dy[i];       nz = sz + dz[i];       if (nx >= 0 && nx < n && ny >= 0 && ny < m && nz >= 0 && nz < k)         if (!vis[nx][ny][nz] && x[nz][nx][ny] ==  . ) dfs(nz, nx, ny);     }   }   int main() {     int i, j, tx, ty;     cin >> k >> n >> m;     string blank;     for (i = 0; i < k; i++) {       for (j = 0; j < n; j++) cin >> x[i][j];     }     cin >> tx >> ty;     tx--, ty--;     if (x[0][tx][ty] ==  . ) dfs(0, tx, ty);     cout << ANS <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, k;     cin >> n >> m >> k;     vector<long long> v;     v.push_back(0);     for (int i = 0; i < m; i++) {       long long a;       cin >> a;       v.push_back(a);     }     int i = 1, j = 1, ans = 0;     while (i <= m) {       while ((v[j] - i + k) / k == (v[i] - i + k) / k) j++;       i = j;       ans++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long modulo = 1e9 + 7;   template <class X>   void printarr(X arr[], int n) {     for (int i = 0; i < n; ++i) cout << arr[i] <<    ;     cout << endl;   }   long long fpow(long long a, long long n) {     long long ans = 1;     while (n) {       if (n & 1) ans = (ans * a) % modulo;       a = (a * a) % modulo;       n = n >> 1;     }     return ans;   }   const int M = 2e3 + 10;   vector<int> graph[M];   int visited[M] = {0};   int dfs(int source, int original) {     visited[source] = original;     int max_height = -1;     for (int a : graph[source]) {       if (visited[a] == original) continue;       max_height = max(dfs(a, original), max_height);     }     return 1 + max_height;   }   void solve(int source, int distance) {     visited[source] = distance;     for (int a : graph[source]) {       if (visited[a] == -1) solve(a, distance + 1);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     int parent[n + 1], min_distance[n + 1];     for (int i = 0; i <= n; ++i) {       parent[i] = i;       min_distance[i] = INT_MAX;     }     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v;       graph[u].push_back(v);       graph[v].push_back(u);     }     if (n == 1) {       cout << 0 << endl;       return 0;     }     for (int i = 1; i <= n; ++i) {       int distance = dfs(i, i);       if (distance < min_distance[i]) {         for (int j = 1; j <= n; ++j) {           if (visited[j] == i) {             min_distance[j] = distance;             parent[j] = i;           }         }       }     }     vector<pair<int, int> > connected_components;     for (int i = 1; i <= n; ++i) {       if (parent[i] == i) connected_components.push_back({min_distance[i], i});     }     sort(connected_components.begin(), connected_components.end(),          greater<pair<int, int> >());     int cnt = connected_components.size();     for (int i = 1; i < cnt; ++i) {       int u = connected_components[0].second, v = connected_components[i].second;       graph[u].push_back(v);       graph[v].push_back(u);     }     for (int i = 1; i <= n; ++i) visited[i] = -1;     solve(connected_components[0].second, 0);     int distance = 0, leaf;     for (int i = 1; i <= n; ++i) {       if (visited[i] > distance) {         leaf = i;         distance = visited[i];       }     }     for (int i = 1; i <= n; ++i) visited[i] = 0;     cout << dfs(leaf, leaf) << endl;     for (int i = 1; i < cnt; ++i)       cout << connected_components[0].second <<                << connected_components[i].second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string S;   vector<int> V;   int rev(int x) {     long long sum = 0;     for (int i = 0; i < 8; i++) {       int temp = x % 2;       sum = sum * 2 + temp;       x /= 2;     }     return sum;   }   int main() {     ios::sync_with_stdio(false);     getline(cin, S);     int prev = 0;     for (int i = 0; i < (int)S.size(); i++) {       int t = (int)S[i];       t = rev(t);       if (prev >= t)         V.push_back(prev - t);       else         V.push_back(prev + 256 - t);       prev = t;     }     for (int i = 0; i < (int)V.size(); i++) {       cout << V[i] << endl;     }     return 0;   }
#include<bits/stdc++.h>      using namespace std;      int main(){     ios::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while(t>0){       t--;       int n;       cin >> n;       vector<int> a(n);       map<int,int> mp;       for(int i=0;i<n;i++){         cin >> a[i];         if(i%2){mp[a[i]]++;}         else{mp[a[i]]--;}       }       sort(a.begin(),a.end());       for(int i=0;i<n;i++){         if(i%2){mp[a[i]]--;}         else{mp[a[i]]++;}       }       bool fl=true;       for(auto &nx : mp){         if(nx.second!=0){fl=false;}       }       if(fl){cout <<  YES n ;}else{cout <<  NO n ;}     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[1005][11][11];   int d[1005][1005], vis[1005], fa[1005], t[1005][2];   int n, m, c;   vector<int> V[1005];   struct Edge {     int a, b, w;   } p[500005];   int cmp(Edge x, Edge y) { return x.w < y.w; }   int cal(int a, int b) {     int ans = 0, i, j;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++)         if (s[a][i][j] != s[b][i][j]) ans++;     return ans;   }   int find(int x) {     if (x != fa[x]) return fa[x] = find(fa[x]);     return x;   }   void dfs(int u, int pu) {     int x, i;     vis[u] = 1;     t[c][0] = u, t[c++][1] = pu;     for (i = 0; i < V[u].size(); i++) {       x = V[u][i];       if (vis[x]) continue;       dfs(x, u);     }   }   int main() {     int k, w, i, j;     scanf( %d%d%d%d , &n, &m, &k, &w);     for (i = 1; i <= k; i++) {       for (j = 0; j < n; j++) scanf( %s , s[i][j]);     }     c = 0;     for (i = 1; i <= k; i++)       for (j = i + 1; j <= k; j++) {         int dis = cal(i, j);         if (dis * w <= n * m) {           p[c].a = i;           p[c].b = j;           p[c++].w = dis * w;         }       }     sort(p, p + c, cmp);     for (i = 1; i <= k; i++) fa[i] = i;     int ans = 0;     for (i = 0; i < c; i++) {       int fx = find(p[i].a);       int fy = find(p[i].b);       if (fx == fy) continue;       fa[fx] = fy;       ans += p[i].w;       V[p[i].a].push_back(p[i].b);       V[p[i].b].push_back(p[i].a);     }     c = 0;     for (i = 1; i <= k; i++)       if (!vis[i]) {         ans += n * m;         dfs(i, 0);       }     printf( %d n , ans);     for (i = 0; i < c; i++) printf( %d %d n , t[i][0], t[i][1]);   }
#include <bits/stdc++.h>   using namespace std;   #define m_p make_pair   #define all(x) (x).begin(),(x).end()   #define sz(x) ((int)(x).size())   #define fi first   #define se second   typedef long long ll;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   mt19937 rnf(2106);   const int N = 1000006;      int q;   int a[N], c[N];      const int m = 20;   int p[N][m];   bool z[N];      int go(int x)   {       for (int i = m - 1; i >= 0; --i)       {           if (!z[p[x][i]])               x = p[x][i];       }       return x;   }      void solv()   {       cin >> q >> a[0] >> c[0];          for (int i = 1; i <= q; ++i)       {           int ty;           cin >> ty;           if (ty == 1)           {               cin >> p[i][0] >> a[i] >> c[i];               for (int j = 1; j < m; ++j)               {                   p[i][j] = p[p[i][j - 1]][j - 1];               }           }           else           {               int x, w;               cin >> x >> w;                  int ww = 0;               ll g = 0;               while (1)               {                   if (w == 0)                       break;                   if (z[x])                       break;                   int u = go(x);                   if (a[u] > w)                   {                       a[u] -= w;                       ww += w;                       g += w * 1LL * c[u];                       w = 0;                   }                   else                   {                       w -= a[u];                       ww += a[u];                       g += a[u] * 1LL * c[u];                       a[u] = 0;                       z[u] = true;                   }               }                  cout << ww <<     << g << endl;           }       }   }      int main()   {       #ifdef SOMETHING       freopen( input.txt ,  r , stdin);       //freopen( output.txt ,  w , stdout);       #endif // SOMETHING       ios_base::sync_with_stdio(false), cin.tie(0);          int tt = 1;       //cin >> tt;       while (tt--)       {           solv();       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long int z = 1000000007;   long long int h[1000009], a[1000009];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     vector<pair<string, string> > p;     std::set<int> myset;     std::set<int>::iterator it;     long long int n, m, i, x = 0, y, v, j, d, c, k = 0, max = 0, sum = 0,                            flag = 0;     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> x;       myset.insert(x);     }     x = 1;     while (sum <= m) {       it = myset.begin();       if (*it != x) {         sum += x;         if (sum <= m) {           a[k] = x;           k++;         }       } else {         myset.erase(it);       }       x++;     }     cout << k << endl;     for (i = 0; i < k; i++) cout << a[i] <<    ;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   ;   long long max(long long a, long long b) {     if (a > b)       return a;     else       return b;   }   long long min(long long a, long long b) {     if (a > b)       return b;     else       return a;   }   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long normalize(long long x, long long mod) {     x %= mod;     if (x < 0) x += mod;     return x;   }   long long dx[4] = {0, 0, 1, -1};   long long dy[4] = {1, -1, 0, 0};   const long long mod = 1000 * 1000 * 1000 + 7;   const long long inf = 1e18 + 5;   long long powm(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res;   }   const long long N = 2e5 + 5;   long long n, m, k, x, l, r;   long long a[N];   vector<long long> v;   void solve() {     cin >> l >> r;     for (long long i = 0; i <= 63; i++) {       if ((l & (1LL << i)) == 0) {         if ((l | (1LL << i)) > r) {           break;         }         l |= (1LL << i);       }     }     cout << l <<   n ;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(10);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[110000], b[110000], dp[110000][5];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, i, j, k;     vector<long long> v;     cin >> n;     for (i = 1; i < n; i++) {       cin >> a[i];     }     for (i = 1; i < n; i++) {       cin >> b[i];     }     for (i = 2; i <= n; i++) {       for (j = 0; j < 4; j++) {         dp[i][j] = -1;         for (k = 0; k <= 3; k++) {           if (dp[i - 1][k] != -1) {             if (((j & k) == b[i - 1]) && ((j | k) == a[i - 1])) dp[i][j] = k;           }         }       }     }     long long fl = 0;     for (i = 0; i < 4; i++) {       if (dp[n][i] != -1) {         cout <<  YES n ;         for (j = n; j > 0; j--) {           v.push_back(i);           i = dp[j][i];         }         fl = 1;         break;       }     }     if (fl == 0)       cout <<  NO ;     else {       for (i = 0; i < v.size(); i++) cout << v[v.size() - i - 1] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int findd(string s1, string s2) {     long long h1 = 0, h2 = 0, x = 1;     int i, n = (int)s1.size(), m = (int)s2.size();     if (n < m) return -1;     for (i = 0; i < m; i++) h2 = h2 * 33 + s2[i] -  a  + 1;     for (i = 0; i < n; i++) {       if (i < m) {         h1 = h1 * 33 + s1[i] -  a  + 1;         x = x * 33;         if (i == m - 1)           if (h1 == h2) return 1;       } else {         h1 = h1 * 33 - (s1[i - m] -  a  + 1) * x + s1[i] -  a  + 1;         if (h1 == h2) return 1;       }     }     return -1;   }   string join(string s1, string s2) {     string st;     long long x, h1, h2;     int j, maxj = 0;     if (findd(s1, s2) != -1)       st = s1;     else {       h1 = h2 = 0;       x = 1;       for (j = 0; j < min(s1.size(), s2.size());) {         h1 = h1 * 33 + s2[j] -  a  + 1;         h2 = h2 + (s1[s1.size() - 1 - j] -  a  + 1) * x;         x = x * 33;         if (h1 == h2) {           j++;           maxj = max(j, maxj);         } else {           j++;         }       }       if (maxj == 0)         st = s1 + s2;       else {         st = s1;         for (j = maxj; j < s2.size(); j++) st += s2[j];       }     }     return st;   }   int main(int argc, const char* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int m;     string S[3], s1, s2, s3;     cin >> S[0] >> S[1] >> S[2];     m = (int)S[0].size() + (int)S[1].size() + (int)S[2].size();     vector<int> V = {0, 1, 2};     do {       s1 = S[V[0]];       s2 = S[V[1]];       s3 = S[V[2]];       s1 = join(s1, s2);       s1 = join(s1, s3);       m = min(m, (int)s1.size());     } while (next_permutation(V.begin(), V.end()));     cout << m;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<pair<string, string>, string> solve(int n) {     if (n == 1) {       return {{ a ,   },  a };     }     if (n == 2) {       return {{ a ,  a },  a };     }     int k = n - 1 >> 1;     auto res = solve(k);     string c =   ;     c += res.second[res.second.size() - 1] + 1;     if (k * 2 + 1 == n) {       return {{res.first.first + c, res.first.second + c + c}, res.second + c};     } else {       return {{res.first.first + c, c + res.first.second + c + c},               res.second + c};     }   }   int main() {     int n;     cin >> n;     auto it = solve(n);     cout << it.first.first + it.first.second <<     << it.second << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       string ans;       string v;       string p;       for (int i = 0; i < n - 2; i++) {         cin >> v;         if (v[0] == p[1] && i != 0) {           ans += v[0];         } else if ((v[0] != p[1]) && i != 0) {           ans += p[1];           ans += v[0];         } else {           ans += v[0];         }         p = v;       }       ans += v[1];       if (ans.size() != n) {         ans +=  a ;       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int n, m;   bool check(int mid) {     ll cnt = m * 1ll * mid, C = 1, ret = 1;     for (int i = 1; i <= min(m, mid) && cnt; i++) {       C = C * (mid - i + 1) / i;       if (cnt >= C * i)         cnt -= C * i, ret += C;       else {         ret += cnt / i;         break;       }       if (ret >= n) return 1;     }     return ret >= n;   }   int main() {     ios::sync_with_stdio(false);     int T;     cin >> T;     while (T--) {       cin >> n >> m;       int l = 0, r = n, ans = -1;       while (l <= r) {         int mid = (l + r) >> 1;         if (check(mid))           ans = mid, r = mid - 1;         else           l = mid + 1;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void pisz(int n) { printf( %d n , n); }   const int MAX_N = 200010;   int n;   char a[MAX_N];   char b[MAX_N];   double s1[26][MAX_N];   double s2[26][MAX_N];   void precompute() {     s1[b[1] -  A ][1] = 1UL;     for (int(i) = (2); (i) <= (n); ++i) {       for (int(j) = 0; (j) < (26); ++(j)) {         s1[j][i] = s1[j][i - 1];         if (j == b[i] -  A ) {           s1[j][i] = (double)(s1[j][i] + i);         }       }     }     s2[b[n] -  A ][n - 1] = 1UL;     for (int(i) = (n - 2); (i) >= (1); --i) {       for (int(j) = 0; (j) < (26); ++(j)) {         s2[j][i] = s2[j][i + 1];         if (j == b[i + 1] -  A ) {           s2[j][i] = (double)(s2[j][i] + (double)(n - (i + 1UL) + 1UL));         }       }     }   }   int main() {     char c;     scanf( %d , &n);     scanf( %s , a + 1);     scanf( %s , b + 1);     precompute();     double num_of_substrings = 0UL;     for (int(l) = (1); (l) <= (n); ++l) {       num_of_substrings += (double)((double)((double)(n - l) + 1UL) *                                     (double)((double)(n - l) + 1UL));     }     double count = 0UL;     for (int(i) = (1); (i) <= (n); ++i) {       c = a[i];       count = (double)(count + (double)((double)(n - i + 1UL) * s1[c -  A ][i]));       count = (double)(count + (double)(i * s2[c -  A ][i]));     }     double res = (count * 1.0) / (num_of_substrings);     printf( %.9f n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<long long int> a;     long long int n;     cin >> n;     long long int sum = 0, m, ans = 0, count = 0;     ;     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       sum = sum + x;       a.push_back(x);     }     m = sum / n;     for (long long int i = 0; i < a.size() - 1; i++) {       count = m - a[i];       ans = ans + fabs(count);       a[i] = m;       a[i + 1] = a[i + 1] - count;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ile(long long int a) {     int ans = 0;     while (a) {       if (a % 2 == 1) ans++;       a /= 2;     }     return ans;   }   int main() {     int n;     cin >> n;     long long int* a;     a = new long long int[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int* b;     b = new int[n];     for (int i = 0; i < n; i++) {       b[i] = ile(a[i]);     }     int* pre;     pre = new int[n];     pre[0] = b[0] % 2;     for (int i = 1; i < n; i++) {       pre[i] = (pre[i - 1] + b[i]) % 2;     }     int ile0 = 0;     int ile1 = 0;     for (int i = 0; i < n; i++) {       if (pre[i] == 0)         ile0++;       else         ile1++;     }     long long int ans = 0;     ans += ile0;     for (int i = 1; i < n; i++) {       if (pre[i - 1] == 0)         ile0--;       else         ile1--;       if (pre[i - 1] == 0)         ans += ile0;       else         ans += ile1;     }     for (int i = 0; i < n; i++) {       int j = i;       int naj = 0;       int sum = 0;       while (j < n && sum <= 128) {         naj = max(naj, b[j]);         sum += b[j];         if (naj > (sum - naj)) {           if (i == 0) {             if (pre[j] == 0) ans--;           } else {             if (pre[j] - pre[i - 1] == 0) ans--;           }         }         j++;       }     }     cout << ans;     return 0;   }
#include<iostream>   #include<string>   #include<algorithm>   #include<cstdio>   #include<cstring>   #include<cmath>   #include<map>   #include<queue>   #include<sstream>   #include<stack>   #include<set>   #include<bitset>   #include<vector>   #define ll long long   #define ull unsigned long long   #define up_b upper_bound   #define low_b lower_bound   #define m_p make_pair   #define mem(a) memset(a,0,sizeof(a))   #define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)   #define INF 0x3f3f3f3f   #define endl   n    #define rep(i,a,b) for(int i=a;i<=b;i++)   #define per(i,a,b) for(int i=a;i>=b;i--)   using namespace std;   const ll mod=1e9+7;   inline int lowbit(int x){return x&(-x);}   ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}   void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);   inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}   inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch> 9 ||ch< 0 ) {if(ch== - ) f=-1; ch = getchar();}while(ch>= 0 &&ch<= 9 ) x = (x<<3) + (x<<1) + ch -  0 ,  ch = getchar();return x*f; }   //inline ll Inverse(ll x) { return qpow(x,mod-2);}   //inline ll C(ll n,ll m) { return fact[n]*inv[m]%mod*inv[n-m]%mod;}   double round(double r){return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);}//四舍五入   const int maxn=1e5+5;   //const int dx[]={-1,0,1,0};   //const int dy[]={0,1,0,-1};   //ll fact[105];   //ll inv[105];   ll w[maxn];   ll pow2[35];   map<ll,ll>mp;      void init()   {    pow2[0]=1;    rep(i,1,30) pow2[i]=pow2[i-1]*2;   }      int main()   {    //IOS;    //fact[0]=inv[0]=1;    //rep(i,1,100) fact[i]=(ll)i*fact[i-1]%mod,inv[i]=Inverse(fact[i]);    init();    int _;_=read();while(_--)    {     ll n=read(),W=read(),h=0;     rep(i,1,n)     {      ll temp=read(),p=0;      while(temp!=1)      {       temp/=2;       p++;      }      mp[p]++;      } //w[i]=read(),mp[w[i]]++;     //sort(w+1,w+1+n);     //h=1;tmp=W-w[n];mp[w[n]]--;     int x=0;     for(h=1;x<n;h++)     {      ll now=W;      for(int j=30;j>=0;j--)      {       while(mp[j]>0&&now>=pow2[j])       {        mp[j]--;        now-=pow2[j];        x++;        //cout<<now<<endl;       }      }     }     printf( %lld n ,h-1);     mp.clear();    }   }