malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int T, n;   char Ls[400000 + 5], ps[400000 + 5];   long long ans;   long long read() {     long long x = 0, F = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) F = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * F;   }   struct AC_automaton {     int tr[400000 + 5][26], cnt;     int C_end[400000 + 5], fail[400000 + 5], Ans[400000 + 5], lst[400000 + 5];     void Clear() {       cnt = 0;       fail[0] = 0;       memset(tr[0], 0, sizeof(tr[0]));       memset(Ans, 0, sizeof(Ans));     }     void Insert(char *s, int id) {       int p = 0, len = strlen(s);       for (int i = 0; i < len; i++) {         int num = s[i] -  a ;         if (!tr[p][num]) {           tr[p][num] = ++cnt;           C_end[cnt] = 0;           memset(tr[cnt], 0, sizeof(tr[cnt]));           fail[cnt] = 0;         }         p = tr[p][num];       }       C_end[p]++;     }     void Build() {       queue<int> Q;       for (int i = 0; i < 26; i++)         if (tr[0][i]) Q.push(tr[0][i]);       while (!Q.empty()) {         int k = Q.front();         Q.pop();         for (int i = 0; i < 26; i++)           if (tr[k][i]) {             int nxt = tr[k][i];             fail[nxt] = tr[fail[k]][i];             Q.push(nxt);             lst[nxt] = C_end[fail[nxt]] ? fail[nxt] : lst[fail[nxt]];           } else             tr[k][i] = tr[fail[k]][i];       }     }     void Query(char *s) {       int p = 0;       int len = strlen(s);       for (int i = 0; i < len; i++) {         if (s[i] <  a  || s[i] >  z ) {           p = 0;           continue;         }         p = tr[p][s[i] -  a ];         for (int j = p; j; j = lst[j]) Ans[i] += C_end[j];       }     }   } ac, ac2;   int main() {     ac.Clear();     ac2.Clear();     scanf( %s , Ls);     n = read();     int L;     for (int i = 1; i <= n; i++) {       scanf( %s , ps);       ac.Insert(ps, i);       L = strlen(ps);       reverse(ps, ps + L);       ac2.Insert(ps, i);     }     int len = strlen(Ls);     ac.Build(), ac2.Build();     ac.Query(Ls);     reverse(Ls, Ls + len);     ac2.Query(Ls);     for (int i = 0; i < len - 1; i++)       ans += 1LL * ac.Ans[i] * ac2.Ans[len - i - 2];     printf( %lld , ans);   }
#include <bits/stdc++.h>   const int maxn = 5205;   using namespace std;   int n, a[maxn][maxn], m;   int cnt, sum[maxn][maxn], x[maxn];   bool check(int x) {     int now;     for (int i = x; i <= n; i += x) {       for (int j = x; j <= n; j += x) {         now = sum[i][j] - sum[i - x][j] - sum[i][j - x] + sum[i - x][j - x];         if (now == 0 || now == x * x)           continue;         else           return 0;       }     }     return 1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n / 4; j++) {         scanf( %1x , &m);         cnt = 0;         while (m) {           a[i][j * 4 - cnt++] = (m % 2);           m >>= 1;         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];       }     }     cnt = 0;     for (int i = 1; i <= n; i++) {       if (n % i == 0) {         x[++cnt] = i;       }     }     for (int k = cnt; k >= 1; k--) {       if (check(x[k])) {         printf( %d n , x[k]);         break;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 1000 * 1000 + 100;   int nex[maxN];   int st[maxN];   int en[maxN];   vector<int> c[maxN];   int ind;   void dfs(int s) {     st[s] = ind++;     for (auto x : c[s]) dfs(x);     en[s] = ind;   }   int main() {     int n, m;     string s;     cin >> n >> m;     cin >> s;     int curr = 0;     c[curr].push_back(1);     for (int i = 1; i < ((int)(s).size()); i++) {       while (curr && s[i] != s[curr]) curr = nex[curr];       if (s[curr] == s[i]) curr++;       nex[i + 1] = curr;       c[curr].push_back(i + 1);     }     dfs(0);     int len = 0;     if (m != 0) {       int last;       cin >> last;       last--;       len = ((int)(s).size());       int p = ((int)(s).size());       for (int i = 1; i < m; i++) {         int num;         cin >> num;         num--;         len += ((int)(s).size());         len -= max(0, last + p - num);         if (last + p - num > 0) {           int lfix = last + p - num;           if (!(st[lfix] <= st[p] && st[p] < en[lfix])) {             cout << 0 << endl;             return 0;           }         }         last = num;       }     } else       len = 0;     long long ans = 1;     int mod = 1e9 + 7;     len = n - len;     for (int i = 0; i < len; i++) ans = ans * 26LL % mod;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const vector<int> mods = {998244353, 1000000007, 1000000009};   const long long inf = 3e18;   const double pi = acos(-1.0);   const double eps = 0.0000001;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <class... K>   using umap = unordered_map<K...>;   template <class... K>   using uset = unordered_set<K...>;   int n, m, k;   int u, v, w;   const int N = 200100;   const int P = 400000;   umap<int, vector<pair<int, int> > > g;   long long pw[N][3];   long long fc[10][10][3];   vector<long long> goal;   long long comb[15];   long long res;   void build() {     for (int j = (0); j < (3); ++j) pw[0][j] = 1;     for (int i = (1); i < (n + 10); ++i)       for (int j = (0); j < (3); ++j) {         pw[i][j] = (pw[i - 1][j] * 13) % mods[j];       }     goal.resize(3);     for (int i = (0); i < (n); ++i)       for (int j = (0); j < (3); ++j) {         goal[j] = (goal[j] + pw[i][j]) % mods[j];       }   }   void inc() {     long long car = 1;     for (int i = (1); i < (10); ++i) {       long long nxc = (comb[i] + car) / i;       comb[i] = (comb[i] + car) % i;       car = nxc;     }   }   bool alz() {     for (int i = (1); i < (k + 1); ++i) {       if (comb[i]) return 0;     }     return 1;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout.precision(13);     cin >> n >> m >> k;     build();     for (int i = (0); i < (m); ++i) {       cin >> u >> v >> w;       u--;       v--;       g[u].push_back({w, v});     }     for (int i = (0); i < (n); ++i) sort(begin(g[i]), end(g[i]));     for (int i = (0); i < (n); ++i) {       long long sg = ((int)(g[i]).size());       for (int j = (0); j < (sg); ++j)         for (int k = (0); k < (3); ++k) {           fc[sg][j][k] = (fc[sg][j][k] + pw[g[i][j].second][k]) % mods[k];         }     }     res = 0;     for (int i = (0); i < (P); ++i) {       vector<long long> cur(3);       for (int i = (0); i < (k); ++i)         for (int j = (0); j < (3); ++j) {           cur[j] = (cur[j] + fc[i + 1][comb[i + 1]][j]) % mods[j];         }       if (cur == goal) res++;       inc();       if (alz()) break;     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, K;   string s;   bool dp[1010][1010];   bool dfs(int i, int j) {     if (i == N && abs(j) == K) return true;     if (i != N && abs(j) == K) return false;     if (i == N && abs(j) != K) return false;     if (dp[i][j] == 1) return false;     dp[i][j] = 1;     if (s[i] ==  W ) return dfs(i + 1, j + 1);     if (s[i] ==  L ) return dfs(i + 1, j - 1);     if (s[i] ==  D ) return dfs(i + 1, j);     if (dfs(i + 1, j + 1) == true) {       s[i] =  W ;       return 1;     }     if (dfs(i + 1, j) == true) {       s[i] =  D ;       return 1;     }     if (dfs(i + 1, j - 1) == true) {       s[i] =  L ;       return 1;     }     return 0;   }   int main() {     ios::sync_with_stdio(false);     cin >> N >> K;     cin >> s;     if (dfs(0, 0) == true)       cout << s << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> adj;   vector<int> a, b, t;   vector<int> dep, sz;   void dfs(int v, int p) {     dep[v] = dep[p] + 1;     for (auto c : adj[v]) {       if (c != p) {         dfs(c, v);         sz[v] += sz[c];       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int T;     cin >> T;     while (T--) {       int k;       cin >> k;       a.resize(2 * k - 1);       b.resize(2 * k - 1);       t.resize(2 * k - 1);       adj.assign(2 * k + 1, vector<int>());       for (int i = 0; i < 2 * k - 1; ++i) {         cin >> a[i] >> b[i] >> t[i];         adj[a[i]].push_back(b[i]);         adj[b[i]].push_back(a[i]);       }       dep.assign(2 * k + 1, 0);       sz.assign(2 * k + 1, 1);       dfs(1, 0);       long long solMx = 0, solMn = 0;       for (int i = 0; i < 2 * k - 1; ++i) {         if (dep[a[i]] > dep[b[i]]) {           swap(a[i], b[i]);         }         solMx += (long long)min(sz[b[i]], 2 * k - sz[b[i]]) * t[i];         solMn += sz[b[i]] % 2 * t[i];       }       cout << solMn <<     << solMx <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MAXN = 5e5 + 10;   bool bio[MAXN];   int n;   int a[MAXN], b[MAXN], aa[MAXN], bb[MAXN];   int deg[1 << 20];   map<pair<int, int>, vector<int>> id;   vector<pair<int, int>> e[1 << 20];   stack<int> path;   bool euler(int x, bool print) {     for (int i = 0; i < n; ++i) {       bio[i] = false;       a[i] = aa[i] & ((1 << x) - 1);       b[i] = bb[i] & ((1 << x) - 1);       deg[a[i]] = deg[b[i]] = 0;       e[a[i]].clear();       e[b[i]].clear();     }     for (int i = 0; i < n; ++i) {       deg[a[i]]++;       deg[b[i]]++;       e[a[i]].emplace_back(b[i], i);       if (a[i] != b[i]) e[b[i]].emplace_back(a[i], i);     }     for (int i = 0; i < n; ++i)       if (deg[a[i]] % 2 || deg[b[i]] % 2) return false;     vector<int> ret;     int node = a[0];     path.push(node);     while (!path.empty()) {       int nxt = -1;       while (!e[node].empty() && bio[e[node].rbegin()->second])         e[node].pop_back();       if (!e[node].empty()) {         path.push(node);         nxt = e[node].rbegin()->first;         bio[e[node].rbegin()->second] = true;         e[node].pop_back();         node = nxt;       } else {         ret.push_back(node);         node = path.top();         path.pop();       }     }     if (!print) return ret.size() == n + 1;     if (ret.size() == n + 1) {       printf( %d n , x);       for (int i = 0; i < n; ++i) {         int aa = a[i] & ((1 << x) - 1);         int bb = b[i] & ((1 << x) - 1);         id[{aa, bb}].push_back(i);       }       for (int i = ret.size() - 2; i >= 0; --i) {         int a = ret[i + 1], b = ret[i];         if (id.find({a, b}) != id.end() && id[{a, b}].size() != 0) {           int x = *id[{a, b}].rbegin();           id[{a, b}].pop_back();           printf( %d %d  , 2 * x + 1, 2 * x + 2);         } else {           int x = *id[{b, a}].rbegin();           id[{b, a}].pop_back();           printf( %d %d  , 2 * x + 2, 2 * x + 1);         }       }       printf(  n );       exit(0);     }   }   int main(void) {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &aa[i], &bb[i]);     }     int lo = 0, hi = 20;     while (lo < hi) {       int mid = (lo + hi) / 2 + 1;       if (euler(mid, false))         lo = mid;       else         hi = mid - 1;     }     euler(lo, true);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int N = 500005;   const int MOD = 1e9 + 7;   int i, n, m, k, rs, x, y;   long long val[N];   map<int, int> p;   map<long long, vector<pair<int, int>>> M;   int Pow(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = ((long long)ans * a) % MOD, --b;       a = ((long long)a * a) % MOD;       b /= 2;     }     return ans;   }   int pfind(int x) {     if (!p.count(x)) return p[x] = x;     if (p[x] == x) return p[x] = x;     return p[x] = pfind(p[x]);   }   void punite(int x, int y) {     if (rand() & 1)       p[pfind(x)] = pfind(y);     else       p[pfind(y)] = pfind(x);   }   int main() {     scanf( %d %d %d , &n, &m, &k);     rs = Pow(2, n + k);     for (i = 1; i <= n; ++i) scanf( %lld , val + i);     while (m--) {       scanf( %d %d , &x, &y);       M[val[x] ^ val[y]].push_back(make_pair(x, y));     }     for (auto it : M) {       vector<pair<int, int>> v = it.second;       x = n;       p.clear();       for (auto it : v)         if (pfind(it.first) != pfind(it.second)) {           punite(it.first, it.second);           --x;         }       rs -= Pow(2, n);       rs += Pow(2, x);       if (rs < 0)         rs += MOD;       else         rs %= MOD;     }     printf( %d n , rs);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int n, a[maxn], b[maxn], v[maxn];   unordered_map<int, int> mp;   void dfs(int x, int l, int r) {     if (v[x] <= r && v[x] >= l) mp[v[x]] = 1;     if (a[x] != -1) {       if (l < v[x]) dfs(a[x], l, min(v[x] - 1, r));     }     if (b[x] != -1) {       if (r > v[x]) dfs(b[x], max(l, v[x] + 1), r);     }   }   bool f[maxn];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> v[i] >> a[i] >> b[i];       if (a[i] != -1) f[a[i]] = 1;       if (b[i] != -1) f[b[i]] = 1;     }     int root = 1;     for (int i = 1; i <= n; i++)       if (!f[i]) root = i;     dfs(root, 0, 1000000000);     int ret = 0;     for (int i = 1; i <= n; i++)       if (mp.find(v[i]) != mp.end()) ret++;     cout << n - ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 205;   const int mod = 1e9 + 7;   int n, m, t, q;   vector<int> G[N];   map<int, int> M;   set<int> S;   int a[N], in[N], iinn[N], vis[N];   long long sum;   void topsort(int id) {     int cnt = 0;     while (1) {       for (int i = (1); i <= (n); i++) {         if (iinn[i] == 0 && vis[i] == 0 && a[i] == id) {           cnt++;           vis[i] = 1;           sum++;           int len = G[i].size();           for (int j = (0); j <= (len - 1); j++) {             iinn[G[i][j]]--;           }           i = 0;         }       }       if (cnt == n) break;       id = (id % 3) + 1;       sum++;     }   }   int main() {     scanf( %d , &n);     for (int i = (1); i <= (n); i++) scanf( %d , &a[i]);     for (int i = (1); i <= (n); i++) {       int len, num;       scanf( %d , &len);       for (int j = (1); j <= (len); j++) {         scanf( %d , &num);         G[num].push_back(i);         in[i]++;         iinn[i]++;       }     }     long long ans = 1ll << 62;     sum = 0;     topsort(1);     ans = min(ans, sum);     sum = 0;     memset(vis, 0, sizeof(vis));     for (int i = (1); i <= (n); i++) iinn[i] = in[i];     topsort(2);     ans = min(ans, sum);     sum = 0;     memset(vis, 0, sizeof(vis));     for (int i = (1); i <= (n); i++) iinn[i] = in[i];     topsort(3);     ans = min(ans, sum);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int len;     string s;     cin >> len;     cin >> s;     vector<char> vect;     while (len != 0) {       if (len % 2 == 1) {         vect.push_back(s[0]);       } else {         vect.insert(vect.begin(), s[0]);       }       s.erase(0, 1);       len = s.length();     }     for (int i = 0; i < vect.size(); i++) {       cout << vect[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, d;     vector<pair<int, int>> v;     vector<int> ans;     set<pair<int, int>> st;     scanf( %d %d %d , &n, &m, &d);     ans.resize(n);     for (int i = 0; i < n; ++i) {       int t;       scanf( %d , &t);       v.push_back(make_pair(t, i));     }     sort(v.begin(), v.end());     st.insert(make_pair(v[0].first + d + 1, 1));     ans[v[0].second] = 1;     for (int i = 1; i < v.size(); ++i) {       int minute = v[i].first;       int id = v[i].second;       auto it = st.begin();       int cur_min_available_minute = it->first;       int day = it->second;       if (cur_min_available_minute <= m && minute >= cur_min_available_minute) {         st.erase(it);         st.insert(make_pair(minute + d + 1, day));         ans[id] = day;       } else {         st.insert(make_pair(minute + d + 1, st.size() + 1));         ans[id] = st.size();       }     }     printf( %d n , (int)st.size());     for (int i = 0; i < n; ++i) {       printf( %d  , ans[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double d, h, v, e;     cin >> d >> h >> v >> e;     double V = e * 3.14159265358979 * (d / 2) * (d / 2);     if (v <= V) {       cout <<  NO ;     } else {       double S = 3.14159265358979 * (d / 2) * (d / 2) * h;       cout <<  YES  << endl << fixed << setprecision(12) << S / (v - V);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     iostream::sync_with_stdio(false);     int n;     cin >> n;     vector<int> nums(n);     map<int, int> counts;     for (int i = 0; i < n; i++) {       cin >> nums[i];       counts[nums[i]]++;     }     map<int, int> last;     int k = 0, previous;     for (auto it = counts.begin(); it != counts.end(); it++) {       if (k++ > 0) {         if (previous < it->second) {           cout << -1 << endl;           return 0;         }       }       if (k != it->first) {         cout << -1 << endl;         return 0;       }       previous = it->second;       last[it->first] = 1;     }     int total = 0;     vector<int> ans(n);     for (int i = 0; i < n; i++) {       ans[i] = last[nums[i]]++;       total = max(ans[i], total);     }     cout << total << endl;     for (int i = 0; i < n; i++) {       if (i) cout <<    ;       cout << ans[i];     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     long long n, ans = 0, cnt = 0;     cin >> n;     vector<long long> a(n), pref(n + 1);     for (auto& i : a) cin >> i;     pref[0] = a[0];     for (int i = 1; i < n; ++i) pref[i] += pref[i - 1] + a[i];     if (pref[n - 1] % 3 || n < 3) return cout << 0, 0;     long long s = pref[n - 1] / 3;     for (int i = 0; i < n - 1; ++i) {       if (pref[i] == 2 * s) ans += cnt;       if (pref[i] == s) ++cnt;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long int a[100001];   long long int d[100001];   long long int n;   long long int max(long long int x, long long int y) {     if (x > y) return x;     return y;   }   int main() {     cin >> n;     long long int i;     long long int x;     for (i = 0; i < n; ++i) {       cin >> x;       a[x]++;     }     d[0] = 0;     d[1] = a[1];     for (i = 2; i <= 100001; ++i) {       d[i] = max(d[i - 1], d[i - 2] + a[i] * i);     }     cout << d[100001] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, i, j, m, x, c, count, nr, OK, suma, k, level, val, y[100], z;   void inmultire_y(long long nr) {     int i = 0;     int j = 0;     int Max = 0;     for (; i < 100; i++) y[i] = 0;     long long x2 = nr;     int n = 0;     while (x2) {       n++;       x2 /= 10;     }     x2 = nr;     for (i = 1; i <= n; i++) {       long long x1 = nr;       for (j = 1; j <= n; j++) {         y[i + j - 1] += (x2 % 10) * (x1 % 10);         Max = max(Max, i + j - 1);         if (y[i + j - 1] >= 10) {           Max = max(Max, i + j);           y[i + j] += y[i + j - 1] / 10;           y[i + j - 1] = y[i + j - 1] % 10;         }         x1 /= 10;       }       x2 /= 10;     }     y[0] = Max;   }   long long impartire_y(long long X) {     long long i;     unsigned long R = 0;     for (i = y[0]; i; i--) {       y[i] = (R = 10 * R + y[i]) / X;       R %= X;     }     while (!y[y[0]] && y[0] > 1) y[0]--;     long long r = 0;     for (i = 100; i > 0; i--) {       if (y[i]) {         for (long long j = i; j > 0; j--) {           r = r * 10 + y[j];         }         break;       }     }     return r;   }   int main() {     cin >> n;     val = 2;     for (level = 2; level <= n + 1; level++) {       x = level * (level - 1);       while (1) {         inmultire_y(x);         z = impartire_y(level - 1);         z = z - val / (level - 1);         break;       }       val = x;       cout << z <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double a, d, x, y, r;     int i, n;     scanf( %lf%lf%d , &a, &d, &n);     for (i = 1; i <= n; i++) {       r = fmod(i * d, 4 * a);       if (r <= a)         x = r, y = 0;       else if (r <= 2 * a)         x = a, y = r - a;       else if (r <= 3 * a)         x = a - (r - 2 * a), y = a;       else         x = 0, y = a - (r - 3 * a);       printf( %.10f %.10f n , x, y);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     bool cap = false, low = false, num = false;     for (int i = 0; i < s.size(); ++i) {       if (s[i] >=  a  && s[i] <=  z )         low = true;       else if (s[i] >=  A  && s[i] <=  Z )         cap = true;       else if (s[i] >=  0  && s[i] <=  9 )         num = true;     }     if (s.size() >= 5 && cap && low && num)       cout <<  Correct  << endl;     else       cout <<  Too weak  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 10;   long long int vis[N];   vector<vector<int> > v;   int dfs(int t) {     vis[t] = 1;     for (int i = 0; i < v[t].size(); i++) {       if (vis[v[t][t]] == 0) {         dfs(v[t][i]);       }     }     return 0;   }   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int lcm(int a, int b) { return a * (b / gcd(a, b)); }   int main() {     long long int n, m;     cin >> n >> m;     while (1) {       if (n == 0 or m == 0) break;       if (n >= 2 * m)         n = n % (2 * m);       else if (m >= 2 * n)         m = m % (2 * n);       else         break;     }     cout << n <<     << m << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ((void)0);     ((void)0);     ((void)0);     int T, N, M1, M2, s, e;     long long X;     for (cin >> T; T--;) {       M1 = M2 = 0x7fffffff;       s = 0;       e = 1e9;       for (cin >> N >> X; N--;) {         int d, h;         cin >> d >> h;         M1 = min(M1, -d);         M2 = min(M2, h - d);       }       if (X + M1 <= 0) {         cout <<  1 n ;         continue;       }       while (s <= e) {         int m = (s + e) >> 1;         if (X + 1LL * m * M2 + M1 <= 0)           e = m - 1;         else           s = m + 1;       }       if (s > 1e9)         cout <<  -1 n ;       else         cout << s + 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int sum(int n) {     int c = 0;     while (n > 0) {       c += n % 10;       n /= 10;     }     return c;   }   void showarr(int arr[], int n) {     for (int i = 0; i < n; i++) {       cout << arr[i] <<    ;     }     cout <<   n ;   }   int arr[8001], f[8001];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int i, j, t;     cin >> t;     while (t--) {       int s, k, n, q, m = 0;       cin >> n;       for (int i = 0; i < n; ++i) {         cin >> arr[i];         f[i + 1] = 0;       }       int ans = 0, cnt = 0;       for (i = 0; i < n; i++) {         cnt = arr[i];         for (j = i + 1; j < n; j++) {           cnt += arr[j];           if (cnt > n) break;           f[cnt] = 1;         }       }       for (i = 0; i < n; i++) {         if (f[arr[i]]) ans++;       }       cout << ans <<   n ;     }   }