malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     string ans, s;     int n, t, p;     char ch;     scanf( %d , &n);     ans.clear();     for (int i = 1; i <= n; i++) {       t = i;       s.clear();       while (t > 0) {         p = t % 10;         ch = p +  0 ;         s = ch + s;         t = t / 10;       }       ans = ans + s;     }     cout << ans[n - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x, zhan[100500], tree[100500], o, ans[100500], now = 1;   struct edge {     int x, t, id, r;     bool operator<(const edge &xx) const {       if (x != xx.x) return x < xx.x;       return id < xx.id;     }   } aa[100500];   void add(int x, int y) {     for (int i = x; i <= n; i += (i & (-i))) tree[i] += y;   }   int get(int x) {     int ans = 0;     for (int i = x; i >= 1; i -= (i & (-i))) ans += tree[i];     return ans;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &aa[i].r, &aa[i].t, &aa[i].x);       aa[i].id = i;       zhan[++o] = aa[i].t;     }     sort(zhan + 1, zhan + o + 1);     o = unique(zhan + 1, zhan + o + 1) - zhan - 1;     for (int i = 1; i <= n; i++) {       aa[i].t = lower_bound(zhan + 1, zhan + o + 1, aa[i].t) - zhan;     }     sort(aa + 1, aa + n + 1);     memset(ans, -1, sizeof(ans));     for (int i = 1; i <= n; i++) {       if (aa[i].x != aa[i - 1].x)         while (now != i) {           if (aa[now].r == 1) add(aa[now].t, -1);           if (aa[now].r == 2) add(aa[now].t, 1);           now++;         }       if (aa[i].r == 1) add(aa[i].t, 1);       if (aa[i].r == 2) add(aa[i].t, -1);       if (aa[i].r == 3) ans[aa[i].id] = get(aa[i].t);     }     for (int i = 1; i <= n; i++)       if (ans[i] != -1) printf( %d n , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   int n, m, cnt, num[100010], w[100010];   int x[100010], y[100010];   struct edge {     int w, f, id;   } e[100010];   inline bool operator<(edge a, edge b) { return a.w < b.w; }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &e[i].w, &e[i].f);       e[i].id = i;     }     sort(e + 1, e + m + 1);     for (int i = 1; i <= m; i++) {       if (e[i].f) {         cnt++;         num[cnt] = cnt - 1;         w[cnt] = e[i].w;         x[e[i].id] = cnt;         y[e[i].id] = cnt + 1;       }     }     int now = cnt;     for (int i = m; i >= 1; i--) {       if (e[i].f) continue;       while (w[now] > e[i].w && now) now--;       if (now == 0 || now == 1) {         puts( -1 );         return 0;       }       y[e[i].id] = now + 1;       x[e[i].id] = num[now];       num[now]--;       if (num[now] == 0) now--;     }     for (int i = 1; i <= m; i++) {       printf( %d %d n , x[i], y[i]);     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     while (scanf( %d , &n) != EOF) {       int ans = 0;       int sum = 0;       while (n--) {         int x;         scanf( %d , &x);         if (x == -1) {           if (!sum)             ans++;           else             sum--;         } else           sum += x;       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   #pragma gcc optimize( O3, unroll-loops )   using namespace std;   const int mod = 1000000007;   int gcds[4001][4001];   int64_t fpow(int i, int j) {     int64_t ans = 1;     while (j--) ans *= i;     return ans;   }   signed main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     int64_t n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) gcds[i][0] = i;     for (int i = 1; i <= m; i++) gcds[0][i] = i;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         gcds[i][j] = i > j ? gcds[i % j][j] : gcds[i][j % i];     int64_t cnts = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         int g = gcds[i][j];         int64_t targ = min((n - i) / (i / g), (m - j) / (j / g));         (cnts += targ * (targ + 1) * (2 * targ + 1) / 6 * (i / g) * (j / g) +                  (n - i + 1) * (m - j + 1) * targ -                  targ * (targ + 1) / 2 *                      ((n - i + 1) * (j / g) + (m - j + 1) * (i / g))) %= mod;       }     cnts = (cnts * 2 * 6 + (n + 1) * (m + 1) * (m * (m - 1) + n * (n - 1)) +             (n + 1) * (m + 1) * ((n + 1) * (m + 1) - 1) * 3 + (n + 1) * (m + 1)) %            mod;     int64_t ans = 0;     for (int i = 0; i < (1 << 6); i++)       if (~(i >> 2 & i >> 4 ^ i >> 0 & i >> 5 ^ i >> 1 & i >> 3 ^             i >> 2 & i >> 3 ^ i >> 0 & i >> 4 ^ i >> 1 & i >> 5) &           1)         ans += fpow((n + 1) / 2, __builtin_popcount(i & 7)) % mod *                fpow((n + 2) / 2, 3 - __builtin_popcount(i & 7)) % mod *                fpow((m + 1) / 2, __builtin_popcount(i >> 3)) % mod *                fpow((m + 2) / 2, 3 - __builtin_popcount(i >> 3)) % mod;     cout << ((ans - cnts) % mod + mod) % mod << endl;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long int gcd(long long int a, long long int b) {     if (!b)       return a;     else       return gcd(b, a % b);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<long long int> a(n);       vector<bool> vis(n);       deque<long long int> b;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) {         bool x;         cin >> x;         vis[i] = x;         if (!vis[i]) b.push_back(a[i]);       }       sort(b.begin(), b.end(), greater<long long int>());       for (int i = 0; i < n; i++) {         if (!vis[i]) {           cout << b.front() <<    ;           b.pop_front();         } else {           cout << a[i] <<    ;         }       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k, n1, ans, m, per1, per2, add;   const int maxn = 1000007;   long long tree[maxn * 4][4];   void build() {     for (int j = n1 - 1; j < n1 + n - 1; j++) {       tree[j][0] = j - n1 + 2;       tree[j][1] = j - n1 + 2;       tree[j][2] = 0;       tree[j][3] = 0;     }     for (int j = n1 + n - 1; j < 2 * n1 - 1; j++) {       tree[j][0] = j - n1 + 2;       tree[j][1] = j - n1 + 2;       tree[j][2] = 0;       tree[j][3] = 0;     }     for (int j = n1 - 2; j > -1; j -= 1) {       tree[j][0] = tree[j * 2 + 1][0];       tree[j][1] = tree[j * 2 + 2][1];       tree[j][2] = 0;       tree[j][3] = 0;     }   }   void push(int node) {     tree[2 * node + 1][3] += tree[node][3];     tree[2 * node + 2][3] += tree[node][3];     tree[node][3] = 0;   }   void update(int node, int a, int b, int val) {     int l, r;     l = tree[node][0];     r = tree[node][1];     if (l == a and r == b) {       tree[node][3] += val;     } else if (r >= a and b >= l) {       push(node);       update(2 * node + 1, a, min(b, (l + r) / 2), val);       update(2 * node + 2, max(a, (l + r) / 2 + 1), b, val);       tree[node][2] = (tree[node * 2 + 1][2] + tree[node * 2 + 1][3] +                        tree[node * 2 + 2][2] + tree[node * 2 + 2][3]);     }   }   int query(int node, int a, int b) {     int l, r;     l = tree[node][0];     r = tree[node][1];     if (r < a || b < l) {       return 0;     }     if (l == a && r == b) {       return tree[node][2] + tree[node][3];     }     push(node);     ans = (query(node * 2 + 1, a, min(b, (l + r) / 2)) +            query(node * 2 + 2, max(a, (l + r) / 2 + 1), b));     tree[node][2] = (tree[2 * node + 1][2] + tree[2 * node + 1][3] +                      tree[2 * node + 2][2] + tree[2 * node + 2][3]);     return ans;   }   int main() {     cin >> n >> k;     n1 = pow(2, ceil(log2(n)));     ;     build();     long long answer = 1;     int now = 1;     for (int j = 0; j < n; j++) {       update(0, now, now, 1);       per1 = 0;       per2 = 0;       if (now + k > n) {         if (k - 1 <= (n - 2) / 2) {           if (now != n) {             per2 = query(0, now + 1, n);           }           if (now + k - n >= 2) {             per1 = query(0, 1, now + k - 1 - n);           }           answer += (1 + per1 + per2);         } else {           answer += (query(0, now + 1 + k - n, now - 1) + 1);         }         now = now + k - n;       } else {         if (k - 1 <= (n - 2) / 2)           answer += (query(0, now + 1, now + k - 1) + 1);         else {           if (now + k != n) {             per2 = query(0, now + k + 1, n);           }           if (now >= 2) {             per1 = query(0, 1, now - 1);           }           answer += (1 + per1 + per2);         }         now += k;       }       cout << answer <<    ;       update(0, now, now, 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   int dblcmp(double d) {     if (fabs(d) < eps) return 0;     return (d > 0) ? 1 : -1;   }   int n, m, T;   bool win(long long a, long long b) {     if (a * b == 0) return false;     if (a > b) swap(a, b);     if (!win(a, b % a)) return 1;     return ((b / a) % (a + 1)) % 2 == 0;   }   int main() {     cin >> T;     while (T--) {       long long a, b;       cin >> a >> b;       if (win(a, b))         printf( First n );       else         printf( Second n );     }     return 0;   }
#include<bits/stdc++.h>      #define N 5000007   #define M 200007   #define ll long long      const ll Mod=1000000007;   using namespace std;   inline int read()   {    int x=0,f=1;char ch=getchar();    while(!isdigit(ch)){if(ch== - )f=-1;ch=getchar();}    while(isdigit(ch)){x=(x<<1)+(x<<3)+ch- 0 ;ch=getchar();}    return x*f;   }      ll n,m,seed,base,tem;   ll num1,num2,ans;   ll a[N],t[N],hh[N];   ll p[M],k[M],b[M],w[M];   ll T1[N],T2[N],c1,c2;      ll rnd()   {    int ret=seed;    seed=1ll*(1ll*seed*base+233)%1000000007;    return ret;   }   int main()   {    n=read(),m=read();    num1=num2=0;    for (int i=1;i<=m;i++)     p[i]=read(),k[i]=read(),b[i]=read(),w[i]=read();    for (int i=1;i<=m;i++)    {     seed=b[i],base=w[i];     for (int j=p[i-1]+1;j<=p[i];j++)     {      t[j]=(rnd()%2)+1;      a[j]=(rnd()%k[i])+1;      hh[j]=a[j];      if (t[j]==1) num1+=a[j];      else num2+=a[j];     }    }   // cout<<num1<<   <<num2<<endl;     //for (int i=1;i<=n;i++)    // cout<<a[i]<<   <<t[i]<<endl;   /* for (int i=1;i<=n;i++)     a[i]=hh[i]=read();    for (int i=1;i<=n;i++)     t[i]=read();    for (int i=1;i<=n;i++)     if (t[i]==1) num1+=a[i];     else num2+=a[i];*/    if (num1==0||num2==0)    {     ans=1;     if (num1!=0)     {      ans=1ll*ans*(((1)^(1ll*1*1))%Mod+1)%Mod;      for (int i=2;i<=n;i++)       ans=1ll*ans*(((0)^(1ll*i*i))%Mod+1)%Mod;      printf( %lld n ,ans);     }     else     {      for (int i=1;i<=n;i++)       ans=1ll*ans*(((0)^(1ll*i*i))%Mod+1)%Mod;      printf( %lld n ,ans);     }    }    else    {     if (num1>num2) tem=2;     else tem=1;        // cout<<tem<<endl;         /*if (t[1]!=tem)     {      if (tem==1&&hh[1]>=num1)      {       hh[1]-=num1;       for (int i=1;i<=n;i++)        if (t[i]==tem) hh[i]=0;      }      else if (tem==2&&hh[1]>=num2)      {       hh[1]-=num2;       for (int i=1;i<=n;i++)        if (t[i]==tem) hh[i]=0;      }      else      {       int z=2;       while(hh[1])       {        if (t[z]!=t[1])        {         if (hh[1]>hh[z]) hh[1]-=hh[z],hh[z]=0;         else hh[z]-=hh[1],hh[1]=0;        }        z++;        }      }     }*/     //cout<<tem<<   <<num1<<   <<num2<<endl;     int z=1;ll num=0;     if (t[1]!=tem)     {      hh[1]--;      while(t[z]!=tem)z++;      }    // for (int i=1;i<=z;i++)    //  cout<<z<<   <<t[i]<<   <<hh[i]<<endl;     for (int i=z;i<=n<<1;i++)     {      int p=(i>n)?i%n:i;      if (t[p]==tem) num+=hh[p],hh[p]=0;      else      {       if (hh[p]>num) hh[p]-=num,num=0;       else num-=hh[p],hh[p]=0;      }     // cout<<num<<   <<hh[p]<<endl;     }          ans=1;     for (int i=1;i<=n;i++)      ans=1ll*ans*(((a[i]-hh[i])^(1ll*i*i))%Mod+1)%Mod;     printf( %lld n ,ans);    }   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<  :   << arg1 << endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<  :   << arg1 <<   | ;     __f(comma + 1, args...);   }   const long long maxn = (long long)2e3 + 10;   const long long maxm = (long long)20;   const int LOGN = 20;   const long long INF = 1e15 + 10;   const long long MOD = 1e9 + 7;   const double PI = acos(-1.0);   const double EPS = 1e-12;   long long Power(long long x, long long n) {     if (n == 0) return 1;     long long r = Power(x, n / 2);     r = r * r % MOD;     if (n & 1) r = r * x % MOD;     return r;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s1, s2;     cin >> s1 >> s2;     set<char> d1(s1.begin(), s1.end());     set<char> d2(s2.begin(), s2.end());     for (auto c : d2)       if (!d1.count(c)) {         cout << -1 << endl;         return 0;       }     vector<vector<int>> a(128);     for (int i = 0; i < s1.size(); ++i) {       a[s1[i]].push_back(i);     }     int ans = 1;     int p = -1;     for (int i = 0; i < s2.size(); ++i) {       auto c = s2[i];       auto it = upper_bound(a[c].begin(), a[c].end(), p);       if (it == a[c].end()) {         ++ans;         p = *upper_bound(a[c].begin(), a[c].end(), -1);       } else {         p = *it;       }     }     cout << ans << endl;     return 0;   }
#include<bits/stdc++.h>   using namespace std;   #define lop(i,n) for(ll i=0;i<n;i++)   #define lop1(i,n) for(ll i=1;i<=n;i++)   #define lopr(i,n) for(ll i=n-1;i>=0;i--)   #define ll long long int   #define pb push_back   #define all(v) v.begin(),v.end()   #define IOS  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)   #define endl   n    #define F first   #define S second    #define mem(arr,val) memset(arr,val,sizeof(arr))   #define pii pair<int,int>   #define pll pair<ll,ll>   #define LCM(a,b) (a*b)/__gcd(a,b)   #define mii map<int,int>   #define mll map<ll,ll>   #define ub upper_bound   #define lb lower_bound   #define sz(x) (ll)x.size()   #define ld long double   #define pcnt(x) __builtin_popcountll(x)   const long long I1=1e9;   const long long I2=1e18;   const int32_t M1=1e9+7;   const int32_t M2=998244353;   template<typename T,typename T1>T maxn(T &a,T1 b){if(b>a)a=b;return a;}   template<typename T,typename T1>T minn(T &a,T1 b){if(b<a)a=b;return a;}      void solve()   {     //code begins from here//       int n,q,k;       cin>>n>>q>>k;       ll a[n+2];       lop1(i,n){           cin>>a[i];       }       a[0] = 0;       a[n+1] = k+1;       ll pre[n+2];       lop1(i,n){           pre[i] = (a[i]-a[i-1]-1)+(a[i+1]-a[i]-1);           pre[i]+=pre[i-1];       }       while(q--){           int l,r;           cin>>l>>r;           if (l==r){               cout << k-1<<endl;               continue;           }           ll cnt = 0;           cnt += a[l+1]-2;           cnt += k - a[r-1] -1;           l++; r--;           if (l<=r){               cnt += pre[r]-pre[l-1];           }           cout << cnt<<endl;       }   }      signed main()   {       IOS;       #ifdef MODULO           initialize();       #endif       #ifdef SIEVE           sieve();       #endif       int testcase=1;      // cin>>testcase;       while(testcase--) solve();       return 0;   }
#include <bits/stdc++.h>   template <typename _Tp>   void read(_Tp &x) {     char ch(getchar());     bool f(false);     while (!isdigit(ch)) f |= ch == 45, ch = getchar();     x = ch & 15, ch = getchar();     while (isdigit(ch)) x = x * 10 + (ch & 15), ch = getchar();     if (f) x = -x;   }   template <typename _Tp, typename... Args>   void read(_Tp &t, Args &...args) {     read(t);     read(args...);   }   const int N = 10000005, mod = 998244353;   template <typename _Tp1, typename _Tp2>   inline void add(_Tp1 &a, _Tp2 b) {     a = a + b >= mod ? a + b - mod : a + b;   }   template <typename _Tp1, typename _Tp2>   inline void sub(_Tp1 &a, _Tp2 b) {     a = a - b < 0 ? a - b + mod : a - b;   }   long long ksm(long long a, long long b = mod - 2) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % mod;       a = a * a % mod, b >>= 1;     }     return res;   }   int pw[N], a[N];   void init() {     pw[0] = 1;     for (int i = 1; i < N; ++i) pw[i] = pw[i - 1], add(pw[i], pw[i - 1]);     int mul = 1;     for (int i = 1; i < N; ++i) mul = 1ULL * mul * (pw[i] - 1) % mod;     a[N - 1] = ksm(mul);     for (int i = N - 2; i >= 1; --i)       a[i] = 1ULL * a[i + 1] * (pw[i + 1] - 1) % mod;   }   void MAIN() {     int n, k, x;     read(n, k, x);     if (!x) {       if (n > k) return puts( 0 ), void();       int ans = 1;       for (int i = 0; i < n; ++i) ans = 1LL * ans * (pw[k] - pw[i] + mod) % mod;       printf( %d n , ans);       return;     }     int ans = pw[k] - 1, cur = 1, qwq = ksm(2, n), iq = ksm(2);     for (int i = 1, coef = pw[k] - 1; i < k; ++i) {       cur = 1ULL * cur * (qwq - 1) % mod, qwq = 1ULL * qwq * iq % mod,       coef = 1ULL * coef * (pw[k] - pw[i] + mod) % mod;       add(ans, 1ULL * coef * cur % mod * a[i] % mod);     }     printf( %lld n , ksm(pw[k] - 1) * ans % mod);   }   int main() {     init();     int _;     read(_);     while (_--) MAIN();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       string s;       cin >> s;       long long a[26] = {0};       long long cnt = 0;       for (long long i = 0; i < s.size(); i++) {         a[s[i] - 97]++;       }       for (long long i = 0; i < 26; i++) {         if (a[i] <= 2)           cnt += a[i];         else           cnt += 2;       }       cout << cnt / 2 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, i, sum;     int a[100010];     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     sum = a[n - 1];     int f = 1;     for (i = 0; i < n - 1; i++) {       sum -= a[i];       if (sum < 0) {         f = 0;         break;       }     }     if (f)       printf( %d , sum + 1);     else       printf( 1 );     return 0;   }
#include <bits/stdc++.h>   const int N = 1e6 + 10;   const int mod = 1e9 + 7;   const int INF = 0x3f3f3f3f;   using namespace std;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   inline int read() {     int X = 0;     bool flag = 1;     char ch = getchar();     while (ch< 0  | ch>  9 ) {       if (ch ==  - ) flag = 0;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       X = (X << 1) + (X << 3) + ch -  0 ;       ch = getchar();     }     if (flag) return X;     return ~(X - 1);   }   int t;   string s;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> s;       sort(s.begin(), s.end());       bool flag = true;       for (int i = 0; i <= (int)s.size() - 2; ++i) {         if (s[i] + 1 != s[i + 1]) {           flag = false;           break;         }       }       if (flag)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     int i, j, K;     int num[101];     memset(num, 0, sizeof(num));     cin >> n >> k;     for (i = 0; i < n; i++) {       scanf( %d , &K);       num[K]++;     }     int cut = 0;     int Max = 0;     for (i = 1; i <= 100; i++) {       if (num[i]) {         cut++;         Max = max(Max, num[i]);       }     }     Max % k ? (j = Max / k + 1) : (j = Max / k);     long long ans = 0;     ans = cut * j * k - n;     printf( %lld n , ans);   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long double eps = 1e-7;   const int inf = 1000000010;   const long long INF = 10000000000000010LL;   const int mod = 1000000007;   const int MAXN = 1010, K = 51;   int n, m, k, u, v, x, y, t, a, b, ans;   short dp[2][MAXN][K][K];   bool good[2][MAXN];   inline void upd(short &a, short b) { a = max(a, b); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     for (int i = 0; i < 2; i++) {       cin >> t;       while (t--) cin >> x, good[i][x] = 1;     }     m = min(m, 2 * n / k + 2);     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= m; j++) {         for (int x = 0; x <= k; x++)           for (int y = 0; y <= k; y++) {             int tmp = (x && good[0][i]) || (y && good[1][i]);             upd(dp[1][j][x][y], dp[0][j][max(x - 1, 0)][max(y - 1, 0)] + tmp);             if (j) {               upd(dp[1][j][x][y], dp[1][j - 1][k][y]);               upd(dp[1][j][x][y], dp[1][j - 1][x][k]);             }           }       }       for (int j = 0; j <= m; j++)         for (int x = 0; x <= k; x++)           for (int y = 0; y <= k; y++) {             dp[0][j][x][y] = dp[1][j][x][y];             dp[1][j][x][y] = 0;           }     }     cout << dp[0][m][0][0] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 200200, M = 110, K = 30030, Inf = 1e17;   void Max(long long &x, long long y) { x = max(x, y); }   long long dp[4 * K];   long long a[M], b[M];   vector<pair<long long, long long>> p, neg;   bool cmp(pair<long long, long long> p1, pair<long long, long long> p2) {     return p1.first - p1.second < p2.first - p2.second;   }   int main() {     long long n, r, c = 0;     cin >> n >> r;     for (int i = 1; i <= n; i++) {       cin >> a[i] >> b[i];       if (b[i] >= 0)         p.push_back({a[i], b[i]});       else         neg.push_back({a[i], -b[i]});     }     sort(p.begin(), p.end());     for (int i = 0; i < p.size(); i++) {       if (p[i].first <= r) r += p[i].second, c++;     }     sort(neg.begin(), neg.end(), cmp);     for (int i = 0; i < neg.size(); i++) {       for (int j = 2 * K - 1; j >= neg[i].first; j--) {         if (j - neg[i].second >= 0) Max(dp[j], dp[j - neg[i].second] + 1);       }     }     long long Ans = 0;     for (int i = 0; i <= r; i++) {       Max(Ans, dp[i]);     }     Ans += c;     cout << Ans <<   n ;     return 0;   }