malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e3 + 100;   int k;   long long a[20][maxn];   int nk[20];   map<long long, pair<int, int> > mp;   long long sum = 0;   bool _is[1 << 17];   long long tol[20];   bool _a[20][maxn];   vector<pair<int, int> > que;   vector<vector<pair<int, int> > > dp[1 << 17];   pair<int, int> ans[20];   void dfs(int fir, int i, int j, int sta, int &flag) {     if (a[i][j] == fir) {       if (_a[i][j] && !_is[sta]) {         _is[sta] = 1;         flag = 1;         dp[sta].push_back(que);         return;       }     }     if (_a[i][j]) return;     long long tmp = sum - (tol[i] - a[i][j]);     if (mp.find(tmp) == mp.end()) {       return;     }     int tfir = mp[tmp].first;     int tsec = mp[tmp].second;     if (sta >> tfir & 1) {       return;     }     _a[i][j] = 1;     que.push_back({tmp, i});     dfs(fir, tfir, tsec, sta | 1 << tfir, flag);     que.pop_back();     if (!flag) _a[i][j] = 0;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> k;     for (int i = 0; i < k; ++i) {       cin >> nk[i];       for (int j = 0; j < nk[i]; ++j) {         cin >> a[i][j];         mp[a[i][j]] = {i, j};         sum += a[i][j];         tol[i] += a[i][j];       }     }     if (sum % k) {       cout <<  No  << endl;     } else {       sum /= k;       for (int i = 0; i < k; ++i) {         for (int j = 0; j < nk[i]; ++j) {           if (_a[i][j]) continue;           int tmp = 0;           dfs(a[i][j], i, j, 0, tmp);         }       }       for (int i = 1; i < 1 << k; ++i) {         if (!_is[i]) {           for (int j = i; j; j = j - 1 & i) {             if (_is[j] && _is[i ^ j]) {               for (auto l : dp[j]) {                 dp[i].push_back(l);               }               for (auto l : dp[i ^ j]) {                 dp[i].push_back(l);               }               _is[i] = 1;               break;             }           }         }       }       if (_is[(1 << k) - 1]) {         cout <<  Yes  << endl;         for (auto i : dp[(1 << k) - 1]) {           for (auto j : i) {             ans[mp[j.first].first] = j;           }         }         for (int i = 0; i < k; ++i) {           cout << ans[i].first <<     << ans[i].second + 1 << endl;         }       } else {         cout <<  No  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   mt19937 rnf(2106);   const int N = 200005, M = 1000000007, K = 1000006;   int ast(int x, int n) {     int ans = 1;     while (n) {       if (n % 2 == 1) ans = (ans * 1LL * x) % M;       x = (x * 1LL * x) % M;       n /= 2;     }     return ans;   }   int u[K];   int f[K], rf[K], r[K];   void pre() {     for (int i = 2; i < K; ++i) {       if (u[i]) continue;       for (int j = i; j < K; j += i) {         if (!u[j]) u[j] = i;       }     }     f[0] = 1;     for (int i = 1; i < K; ++i) f[i] = (f[i - 1] * 1LL * i) % M;     rf[K - 1] = ast(f[K - 1], M - 2);     for (int i = K - 2; i >= 0; --i) rf[i] = (rf[i + 1] * 1LL * (i + 1)) % M;     for (int i = 1; i < K; ++i) r[i] = (rf[i] * 1LL * f[i - 1]) % M;   }   int n;   int a[N];   vector<pair<int, int> > v[N];   int t[N * 4];   void bil(int tl, int tr, int pos) {     if (tl == tr) {       t[pos] = a[tl];       return;     }     int m = (tl + tr) / 2;     bil(tl, m, pos * 2);     bil(m + 1, tr, pos * 2 + 1);     t[pos] = (t[pos * 2] * 1LL * t[pos * 2 + 1]) % M;   }   void ubd(int tl, int tr, int x, int y, int pos) {     if (tl == tr) {       t[pos] = (t[pos] * 1LL * y) % M;       return;     }     int m = (tl + tr) / 2;     if (x <= m)       ubd(tl, m, x, y, pos * 2);     else       ubd(m + 1, tr, x, y, pos * 2 + 1);     t[pos] = (t[pos * 2] * 1LL * t[pos * 2 + 1]) % M;   }   int qry(int tl, int tr, int l, int r, int pos) {     if (l > r) return 1;     if (tl == l && tr == r) return t[pos];     int m = (tl + tr) / 2;     return (qry(tl, m, l, min(m, r), pos * 2) * 1LL *             qry(m + 1, tr, max(m + 1, l), r, pos * 2 + 1)) %            M;   }   int h[K];   int ans[N];   void solv() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     int qq;     scanf( %d , &qq);     for (int i = 0; i < qq; ++i) {       int l, r;       scanf( %d%d , &l, &r);       v[r].push_back(make_pair(l, i));     }     bil(1, n, 1);     for (int i = 1; i <= n; ++i) {       int x = a[i];       while (x > 1) {         if (h[u[x]]) ubd(1, n, h[u[x]], (u[x] * 1LL * r[u[x] - 1]) % M, 1);         h[u[x]] = i;         ubd(1, n, h[u[x]], (1 - r[u[x]] + M) % M, 1);         x /= u[x];       }       for (int j = 0; j < v[i].size(); ++j) {         ans[v[i][j].second] = qry(1, n, v[i][j].first, i, 1);       }     }     for (int i = 0; i < qq; ++i) printf( %d n , ans[i]);   }   int main() {     pre();     solv();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 505;   const int mod = 1e9 + 7;   long long int dp[1005][1005] = {0};   int main() {     long long int n, m, k;     cin >> n >> m >> k;     if (2 * k > n - 1 || 2 * k > m - 1)       cout << 0 << endl;     else {       dp[0][0] = 1;       for (int i = 1; i <= 1000; i++) {         dp[i][0] = 1;         dp[i][i] = 1;         for (int j = 1; j <= i; j++) {           dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % mod;         }       }       cout << ((dp[n - 1][2 * k] % mod) * (dp[m - 1][2 * k] % mod)) % mod << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     int weight[n + 1];     int stacked[m + 1];     for (int i = 1; i <= n; i++) {       cin >> weight[i];     }     for (int i = 1; i <= m; i++) {       cin >> stacked[i];     }     bool vis[n + 1];     memset(vis, false, sizeof(vis));     int ans = 0;     for (int i = 2; i <= m; i++) {       memset(vis, false, sizeof(vis));       for (int j = i - 1; j >= 1; j--) {         if (stacked[j] == stacked[i]) break;         if (!vis[stacked[j]]) {           ans += weight[stacked[j]];           vis[stacked[j]] = true;         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   inline long long sub(long long &a, long long b) {     a -= b;     if (a < 0) {       a += MOD;     }   }   inline long long mult(long long a, long long b) { return (a * 1ll * b) % MOD; }   inline long long b_pow(long long a, long long p) {     long long cur = a, ans = 1;     while (p > 0) {       if (p & 1) {         ans = mult(ans, cur);       }       p /= 2;       cur = mult(cur, cur);     }     return ans;   }   const long long lim = 1e6;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long T;     cin >> T;     while (T--) {       long long n, p;       cin >> n >> p;       if (p == 1) {         for (long long i = 0; i < n; i++) {           long long x;           cin >> x;         }         cout << (n & 1) <<   n ;         continue;       }       map<long long, long long> cnt;       for (long long i = 0; i < n; i++) {         long long x;         cin >> x;         cnt[x]++;       }       auto it = --cnt.end();       long long ans = 0, need = 0;       for (;;) {         if (it->second >= need) {           it->second -= need;           need = 0;           ans = 0;         } else {           sub(ans, mult(it->second, b_pow(p, it->first)));           need -= it->second;           it->second = 0;         }         if (it->second & 1) {           need = 1;           ans = b_pow(p, it->first);         }         if (it == cnt.begin()) {           break;         } else {           long long was = it->first;           it--;           if (need > 0) {             while (need < 1e6 && was != it->first) {               need *= p;               was--;             }           }         }       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   const double Pi = acos(-1.0);   using namespace std;   const int maxN = 100005;   const long long mod = 1000000009;   int n, m;   int par[maxN];   int findpar(int x) {     if (par[x] != x) par[x] = findpar(par[x]);     return par[x];   }   int main(int argc, char** argv) {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) par[i] = i;     long long ans = 1;     int a, b;     while (m--) {       scanf( %d %d , &a, &b);       int pa = findpar(a), pb = findpar(b);       if (pa == pb)         ans = (ans * 2) % mod;       else         par[pb] = pa;       printf( %lld n , ans - 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void BFS(vector<vector<long long> > &graph, long long n,            vector<long long> &order) {     vector<long long> vis(n + 1);     set<long long> PQ;     PQ.insert(1);     while (!PQ.empty()) {       long long x = *PQ.begin();       PQ.erase(PQ.begin());       order.push_back(x);       vis[x] = 1;       for (long long i = 0; i < graph[x].size(); i++) {         if (vis[graph[x][i]] == 0) PQ.insert(graph[x][i]);       }     }   }   int main() {     long long n, m, i, j, k, l, w, u, v, t_sum = 0;     cin >> n >> m;     vector<vector<long long> > graph(n + 1);     for (i = 1; i <= m; i++) {       cin >> u >> v;       graph[u].push_back(v);       graph[v].push_back(u);     }     vector<long long> order;     BFS(graph, n, order);     for (i = 0; i < order.size(); i++) cout << order[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const int N = 10005;   int f[N][2005];   int main() {     int _;     scanf( %d , &_);     for (int j = 1; j <= 1000; j++) {       f[0][j] = INF;     }     while (_--) {       int n;       scanf( %d , &n);       for (int i = 1; i <= n; i++) {         int x;         scanf( %d , &x);         for (int j = 0; j <= 2000; j++) {           f[i][j] = INF;         }         for (int j = 0; j <= 2000; j++) {           f[i][max(0, j - x)] = min(f[i][max(0, j - x)], f[i - 1][j] + x);           if (j + x <= 2000)             f[i][j + x] = min(f[i][j + x], max(0, f[i - 1][j] - x));         }       }       int ans = INF;       for (int j = 0; j <= 1000; j++) {         ans = min(ans, f[n][j] + j);       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int getint() {     int res = 0, fh = 1;     char ch = getchar();     while ((ch >  9  || ch <  0 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) fh = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) res = res * 10 + ch -  0 , ch = getchar();     return fh * res;   }   string s;   int like[20];   int main() {     int F = getint(), I = getint(), T = getint();     for (int i = 1; i <= F; i++) {       getline(cin, s);       for (int j = 0; j < I; j++) like[j + 1] += (s[j] ==  Y );     }     int ans = 0;     for (int i = 1; i <= I; i++)       if (like[i] >= T) ans++;     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const long long N = 5e6 + 3;   long long dp[N];   int main(void) {     ios_base::sync_with_stdio(0);     cin.tie(0);     string str;     unsigned long long temp = 1, p = 0, q = 0;     cin >> str;     long long ans = 0;     long long pppp = str.size();     for (int i = 0; i < str.size(); i++) {       p = (p * 131 + str[i]) % mod;       q = (temp * (str[i]) + q) % mod;       ;       temp *= 131;       temp %= mod;       if (p == q) {         if (i == 0)           dp[i]++, ans += dp[i];         else {           dp[i] = dp[(i - 1) / 2] + 1;           ans += dp[i];         }       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MN = 100005, inf = 1000000005, MOD = 1000000007;   const long long INF = 1000000000000000005LL;   int t[100];   int suma(int i) {     int y = min(t[i], t[i + 2]), a = t[i + 1];     int res = (y + a) * (y + a) - a * a;     int d = max(t[i], t[i + 2]) - y;     res += (d * (a + y));     return res;   }   int main() {     for (int i = 1; i <= 6; ++i) scanf( %d , &t[i]);     int ans = suma(1) + suma(4);     printf( %d , ans);   }
#include<bits/stdc++.h>   using namespace std;   #define ll long long int   #define endl   n    void solve()   {       int n,start=0;       cin>>n;       int end=n;       int arr[n],pos[n+1];       for(int i=0 ; i<n;i++)       {       cin>>arr[i];       pos[arr[i]]=i;       }       for(int i=n;i>0;i--)       {           start = pos[i];           if(end>start)           {               for(int j=start ; j<end ; j++)               {                   cout<<arr[j]<<   ;               }           end = start;           }       }       cout<<endl;   }      int main()   {   int t;   cin>>t;   while(t--)   {   solve();   }   return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename... T>   void read(T&... args) {     ((cin >> args), ...);   }   template <typename... T>   void write(T&&... args) {     ((cout << args <<    ), ...);   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, ans(0);     read(n);     vector<long long> arr(n + 1, 0);     for (long long i = 1; i < n + 1; ++i) {       read(arr[i]);       arr[i] += arr[i - 1];     }     long long start(0), end(0);     set<long long> s = {0};     while (start < n) {       while (end < n && !s.count(arr[end + 1])) {         ++end;         s.insert(arr[end]);       }       ans += end - start;       s.erase(arr[start]);       ++start;     }     cout << ans <<   n ;     arr.clear();     s.clear();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mxN = 1e6;   int n, m, p, a[mxN];   long long s1[1 << 21];   vector<long long> s2[1 << 21];   void bld(int i = 1, int l = 0, int r = n - 1) {     if (l == r) {       s1[i] = a[l];       s2[i] = {p - a[l], 1ll << 60};       return;     }     int m = (l + r) / 2;     bld(2 * i, l, m);     bld(2 * i + 1, m + 1, r);     s1[i] = s1[2 * i] + s1[2 * i + 1];     long long cs = s1[2 * i];     for (int i1 = 0, i2 = 0;          i1 < s2[2 * i].size() - 1 || i2 < s2[2 * i + 1].size() - 1;) {       if (s2[2 * i][i1] + cs < s2[2 * i + 1][i2]) {         if (s2[i].size() && s2[i].back() > s2[2 * i][i1] - p)           s2[i].push_back(s2[i].back() + p);         else           s2[i].push_back(s2[2 * i][i1]);         cs -= p;         ++i1;       } else         s2[i].push_back(s2[2 * i + 1][i2++] - cs);     }     s2[i].push_back(1ll << 60);   }   long long qry(int l1, int r1, long long x, int i = 1, int l2 = 0,                 int r2 = n - 1) {     if (l1 <= l2 && r2 <= r1)       return x + s1[i] -              (long long)(upper_bound(s2[i].begin(), s2[i].end(), x) -                          s2[i].begin()) *                  p;     int m2 = (l2 + r2) / 2;     if (r1 <= m2) return qry(l1, r1, x, 2 * i, l2, m2);     if (m2 < l1) return qry(l1, r1, x, 2 * i + 1, m2 + 1, r2);     return qry(l1, r1, qry(l1, r1, x, 2 * i, l2, m2), 2 * i + 1, m2 + 1, r2);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> p;     for (int i = 0; i < n; ++i) cin >> a[i];     bld();     for (int l, r; m--;) {       cin >> l >> r, --l, --r;       cout << qry(l, r, 0) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 405;   double f[maxn], g[maxn], ans;   int n, m, dis[maxn][maxn], q[maxn];   int main() {     scanf( %d%d , &n, &m);     memset(dis, 127 / 3, sizeof(dis));     for (int i = 1; i <= n; i++) {       dis[i][i] = 0;     }     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       dis[u][v] = dis[v][u] = 1;     }     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);         }       }     }     for (int i = 1; i <= n; i++) {       double temp = 0;       for (int j = 0; j < n; j++) {         int u = 0;         memset(f, 0, sizeof(f));         for (int k = 1; k <= n; k++) {           if (dis[i][k] == j) {             u++;             int x = 0;             for (int kk = 1; kk <= n; kk++) {               if (dis[k][kk] == 1) {                 x++;               }             }             for (int kk = 1; kk <= n; kk++) {               if (dis[k][kk] == 1) {                 f[kk] += 1.0 / x;               }             }           }         }         int v = 0;         for (int k = 1; k <= n; k++) {           if (abs(dis[i][k] - j) <= 1) {             q[++v] = k;           }         }         double res = 0;         for (int k = 1; k <= n; k++) {           for (int kk = 1; kk <= v; kk++) {             if (f[q[kk]] > g[dis[k][q[kk]]]) {               g[dis[k][q[kk]]] = f[q[kk]];             }           }           double w = 0;           for (int kk = 1; kk <= v; kk++) {             w += g[dis[k][q[kk]]];             g[dis[k][q[kk]]] = 0;           }           res = max(res, w);         }         if (u) {           res = max(res, 1.0);         }         temp += res / n;       }       ans = max(ans, temp);     }     printf( %.12lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> g[(long long)3e5], a((long long)3e5);   long long i, n, x, y, r;   void b(long long p, long long q, long long m) {     a[p]++, r += m;     for (auto j : g[p])       if (j != q) b(j, p, m ^ 1), a[p] += a[j];   }   int main() {     for (cin >> n, i = 1; i < n; i++)       cin >> x >> y, g[x].push_back(y), g[y].push_back(x);     b(1, 0, 0), r *= (n - r);     for (i = 1; i <= n; i++) r += a[i] * (n - a[i]);     cout << r / 2;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int tests;     cin >> tests;     while (tests--) {       int n, s, t;       cin >> n >> s >> t;       cout << min(max(s, t) + 1 - (s + t - n), n + (n - s - t) + 1) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[200010];   int n, m, head[200010], o = 0, x[2], id[200010], sz[200010], cnt = 0,                           tree[800010], tag[800010];   bool isnt_rt[200010];   vector<vector<int> > w;   struct edge {     int to, link;   } e[200010];   struct seg {     int x, l, r, id;     bool operator<(const seg &b) const { return x < b.x; }   } sg[200010];   void add_edge(int u, int v) {     e[++o].to = v, e[o].link = head[u], head[u] = o, isnt_rt[v] = true;   }   void dfs(int u, int k) {     id[u] = ++x[k], sz[u] = 1;     for (int i = head[u]; i; i = e[i].link) {       dfs(e[i].to, k);       sz[u] += sz[e[i].to];     }   }   void pushup(int l, int r, int t) {     if (tag[t] > 0) return tree[t] = (r - l + 1), void();     if (l == r) return tree[t] = 0, void();     tree[t] = tree[t << 1] + tree[t << 1 | 1];   }   void add(int ll, int rr, int l, int r, int t, int c) {     if (ll <= l && r <= rr) {       tag[t] += c;       pushup(l, r, t);       return;     }     int mid = (l + r) >> 1;     if (ll <= mid) add(ll, rr, l, mid, t << 1, c);     if (mid < rr) add(ll, rr, mid + 1, r, t << 1 | 1, c);     pushup(l, r, t);   }   int main() {     scanf( %d%d , &n, &m), w.resize(n + 1);     for (int i = 1; i <= n; i++) {       w[i].resize(m + 1);       scanf( %s , s + 1);       for (int j = 1; j <= m; j++) {         if (s[j] ==  L ) w[i][j] = 1;         if (s[j] ==  U ) w[i][j] = 2;         if (s[j] ==  L  && j + 2 <= m)           add_edge(((i)-1) * m + (j + 2), ((i)-1) * m + (j));         if (s[j] ==  R  && j - 2 >= 1)           add_edge(((i)-1) * m + (j - 2), ((i)-1) * m + (j));         if (s[j] ==  U  && i + 2 <= n)           add_edge(((i + 2) - 1) * m + (j), ((i)-1) * m + (j));         if (s[j] ==  D  && i - 2 >= 1)           add_edge(((i - 2) - 1) * m + (j), ((i)-1) * m + (j));       }     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (isnt_rt[((i)-1) * m + (j)]) continue;         dfs(((i)-1) * m + (j), (i + j) & 1);       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         int u, v;         if (w[i][j] == 1) {           u = ((i)-1) * m + (j), v = ((i)-1) * m + (j + 1);           if ((i + j) & 1) swap(u, v);         } else if (w[i][j] == 2) {           u = ((i)-1) * m + (j), v = ((i + 1) - 1) * m + (j);           if ((i + j) & 1) swap(u, v);         } else           continue;         sg[++cnt] = (seg){id[u], id[v], id[v] + sz[v] - 1, 1};         sg[++cnt] = (seg){id[u] + sz[u], id[v], id[v] + sz[v] - 1, -1};       }     sort(sg + 1, sg + cnt + 1);     long long ans = 0;     for (int i = 1, j = 1; i <= x[0]; i++) {       while (sg[j].x <= i && j <= cnt) {         add(sg[j].l, sg[j].r, 1, x[1], 1, sg[j].id);         j++;       }       ans += tree[1];     }     printf( %lld n , ans);   }
/*   ``````````````````$$$$$   `````````````$$$$$$´´´´$$$$$$   ``````````$$$´´´´´´´´´´´´´´´´$$$   ````````$`$$´´´´´´´´´´´´´´´´´´´´$$   ```````$´$$$´´´´´´´´´´´´´´´´´´´´´$$$$   `````$´´$$$$´´´´´´´´´´´´´´´´´´´´´´´´´´$   ````$´´$$$$$´´´´´´´´´´$$$$$$$´´´´´´´´´$$   ```$´´´$$$$$$$´´´$$$$$$$$$$$$$$$$$´´´´´$$   ``$´´´´$$$$$$$$$$$$$$$$$$$$$$$$$$$$$´´´´$$   `$´´´´´´$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$´´$   `$´´´´´´$$$$$$$$$$$´´´´$$$$$$$$$$$$$$$$$$$   $´´´´´´´´$$$$$$$$´´´´´´´´$$$$$$$´´´´´´´´$$   $´´´´´´´´´$$$$$$´´´´´´´´´´$$$$´´´´´´´´´´´$   `$´´´´´´´´´$$$$$´´´´´´´´´´$$$´´´´´´´´´´´$   `$´´´´´´´´´´$$$$$´´´´´´´´$$$$´´´´´´´´´´´$   `$´´´´´´´´´´´$$$$$$´´´´$$$$$´´´´´´´´´´´$$   ``$´´´´´´´´´´´$$$$$$$$$$$$$$´´´´´´´´´´´$   ``$$´´´´´´´´´´´´$$$$$$$$$$$$´´´´´´´´´´$$   ```$$´´´´´´´´´´´´$$$$$$$$$$´´´´´´´´´´$$   ````$´´´´´´´´´´´´$$$$$$$$$´´´´´´´´´´´$   `````$´´´´´´´´´´´$$$$$$$$´´´´´´´´´´´$   ``````$$´´´´´´´´´$$$$$$´´´´´´´´´´´$$   ````````$$´´´´´´$$$$$´´´´´´´´´´´$$   ``````````$$$´$$$$´´´´´´´´´´´$$$   `````````````$$$$$´´´´´´$$$$$   ``````````````````$$$$$$   */   #include  bits/stdc++.h        #define ll long long int   #define pb push_back   #define F first   #define S second   #define vi vector<ll>   #define vs vector<string>   #define input(v,n) for(ll VAL=0;VAL<n;VAL++){ll VALUE;cin>>VALUE;v.pb(VALUE);}   #define mi map<ll,ll>   #define FOR(i,a,b) for(ll i=a;i<b;i++)   #define mi map<ll,ll>   #define print(v) for(ll printing=0;printing<v.size();printing++){cout<<v[printing]<<   ;}   #define TestCase ll testcase;cin>>testcase;while(testcase--)   #define bin(n) bitset<32>(n).to_string();   #define maxv(v) *max_element(v.begin(),v.end())   #define minv(v) *min_element(v.begin(),v.end())   #define decimal(s) stoll(s,nullptr,2)   #define rmLead(str) str.erase(0, min(str.find_first_not_of( 0 ), str.size()-1));   using namespace std;      void solve(){       ll n,c;cin>>n>>c;       vi a(n),b(n-1);       for(auto &i:a)  cin>>i;       for(auto &i:b)  cin>>i;       b.pb(0);       ll prev_val = 0,prev_day=0;       ll ans = 1e18;       for(ll i=0;i<n;i++){           ll x = (c-prev_val+a[i]-1)/a[i];           ans = min(prev_day+max(x,(ll)0),ans);           x = max((ll)0,(b[i]-prev_val+a[i]-1)/a[i]);              prev_day+=x+1;           prev_val+=x*a[i]-b[i];         }       // ll x = (c-prev_val+a[n-1]-1)/a[n-1];       // ans = min(ans,prev_day+max(x,(ll)0));       //print(dp);       cout<<ans<<  n ;      }       int main(){   ios_base::sync_with_stdio(false);    cin.tie(NULL);   cout.tie(NULL);   TestCase   solve();   }